From 2c75cd99ce73e60eb911043dfe1df0ab7987d352 Mon Sep 17 00:00:00 2001 From: Anastasios Ioannidis Date: Thu, 10 Aug 2023 14:55:38 +0300 Subject: [PATCH 001/193] JAVA-13321 Added new gateway module to existing microservices e-book --- .../gateway-2/README-OAuth.md | 40 + .../gateway-2/README.md | 13 + .../gateway-2/baeldung-realm.json | 2186 +++++++++++++++++ .../spring-cloud-bootstrap/gateway-2/pom.xml | 194 ++ .../CustomFiltersGatewayApplication.java | 15 + .../gatewayapp/config/WebClientConfig.java | 16 + .../ChainRequestGatewayFilterFactory.java | 89 + .../LoggingGatewayFilterFactory.java | 85 + .../ModifyRequestGatewayFilterFactory.java | 92 + .../ModifyResponseGatewayFilterFactory.java | 48 + .../ScrubResponseGatewayFilterFactory.java | 110 + .../global/FirstPreLastPostGlobalFilter.java | 31 + .../global/LoggingGlobalFilterProperties.java | 47 + .../LoggingGlobalFiltersConfigurations.java | 25 + .../global/LoggingGlobalPreFilter.java | 22 + .../routes/ServiceRouteConfiguration.java | 28 + .../SecondServiceApplication.java | 15 + .../web/SecondServiceRestController.java | 18 + .../service/ServiceApplication.java | 15 + .../service/web/ServiceRestController.java | 22 + .../CustomPredicatesApplication.java | 15 + .../config/CustomPredicatesConfig.java | 43 + .../GoldenCustomerRoutePredicateFactory.java | 102 + .../service/GoldenCustomerService.java | 26 + .../IntroductionGatewayApplication.java | 15 + .../oauth/backend/QuotesApplication.java | 44 + .../oauth/backend/domain/Quote.java | 35 + .../oauth/backend/web/QuoteApi.java | 34 + .../ResourceServerGatewayApplication.java | 13 + .../KeycloakReactiveTokenInstrospector.java | 65 + .../rewrite/URLRewriteGatewayApplication.java | 25 + .../rewrite/routes/DynamicRewriteRoute.java | 43 + .../WebFilterGatewayApplication.java | 15 + .../config/ModifyBodyRouteConfig.java | 49 + .../RequestRateLimiterResolverConfig.java | 16 + .../resources/application-customroutes.yml | 26 + .../main/resources/application-nosecurity.yml | 8 + .../resources/application-oauth-client.yml | 26 + .../resources/application-resource-server.yml | 19 + .../src/main/resources/application-scrub.yml | 12 + .../resources/application-url-rewrite.yml | 11 + .../main/resources/application-webfilters.yml | 102 + .../src/main/resources/application.yml | 4 + ...ustomfilters-global-application.properties | 19 + .../introduction-application.properties | 7 + .../gateway-2/src/main/resources/logback.xml | 13 + .../resources/quotes-application.properties | 12 + .../secondservice-application.properties | 1 + .../resources/service-application.properties | 1 + .../gatewayapp/CustomFiltersLiveTest.java | 112 + ...bResponseGatewayFilterFactoryUnitTest.java | 61 + .../ScrubResponseGatewayFilterLiveTest.java | 135 + .../gatewayapp/utils/LoggerListAppender.java | 25 + .../SecondServiceIntegrationTest.java | 28 + .../secondservice/SpringContextTest.java | 12 + .../service/ServiceIntegrationTest.java | 31 + .../service/SpringContextTest.java | 12 + .../CustomPredicatesApplicationLiveTest.java | 67 + .../introduction/SpringContextTest.java | 15 + .../URLRewriteGatewayApplicationLiveTest.java | 109 + .../RedisWebFilterFactoriesLiveTest.java | 64 + .../WebFilterFactoriesLiveTest.java | 136 + .../OAuth_Gateway.postman_collection.json | 203 ++ .../src/test/resources/logback-test.xml | 17 + .../spring-cloud-bootstrap/pom.xml | 1 + 65 files changed, 4940 insertions(+) create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README-OAuth.md create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README.md create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/baeldung-realm.json create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersGatewayApplication.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/config/WebClientConfig.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ChainRequestGatewayFilterFactory.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/LoggingGatewayFilterFactory.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyRequestGatewayFilterFactory.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyResponseGatewayFilterFactory.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactory.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/FirstPreLastPostGlobalFilter.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFilterProperties.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFiltersConfigurations.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalPreFilter.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/routes/ServiceRouteConfiguration.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceApplication.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/web/SecondServiceRestController.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/ServiceApplication.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/web/ServiceRestController.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/CustomPredicatesApplication.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/config/CustomPredicatesConfig.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/factories/GoldenCustomerRoutePredicateFactory.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/service/GoldenCustomerService.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/introduction/IntroductionGatewayApplication.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/QuotesApplication.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/domain/Quote.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/web/QuoteApi.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/server/ResourceServerGatewayApplication.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/shared/KeycloakReactiveTokenInstrospector.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplication.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/routes/DynamicRewriteRoute.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/WebFilterGatewayApplication.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/ModifyBodyRouteConfig.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/RequestRateLimiterResolverConfig.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-customroutes.yml create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-nosecurity.yml create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-oauth-client.yml create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-resource-server.yml create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-scrub.yml create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-url-rewrite.yml create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-webfilters.yml create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application.yml create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/customfilters-global-application.properties create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/introduction-application.properties create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/logback.xml create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/quotes-application.properties create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/secondservice-application.properties create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/service-application.properties create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersLiveTest.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactoryUnitTest.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterLiveTest.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/utils/LoggerListAppender.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceIntegrationTest.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SpringContextTest.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/ServiceIntegrationTest.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/SpringContextTest.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/custompredicates/CustomPredicatesApplicationLiveTest.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/introduction/SpringContextTest.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplicationLiveTest.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/RedisWebFilterFactoriesLiveTest.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/WebFilterFactoriesLiveTest.java create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/postman/OAuth_Gateway.postman_collection.json create mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/resources/logback-test.xml diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README-OAuth.md b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README-OAuth.md new file mode 100644 index 0000000000..c186114589 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README-OAuth.md @@ -0,0 +1,40 @@ +# OAuth Test Setup + +In order to test the OAuth-secured gateway configurations, please follow the steps below + +## Keycloak setup + +1. Clone or download the https://github.com/Baeldung/spring-security-oauth project +2. Replace the file `oauth-rest/oauth-authorization-server/src/main/resources/baeldung-realm.json` + with the one provider here +3. Go to the oauth-rest/oauth-authorization-server folder and use maven to build the project +4. Run the Keycloack service with `mvn spring-boot:run` +5. Once Keycloak is up and running, go to `http://localhost:8083/auth/admin/master/console/#/realms/baeldung` and + log in with using `bael-admin/pass` as credentials +6. Create two test users, so that one belongs to the *Golden Customers* group and the other doesn't. + +## Quotes backend + +Use the provided maven profile: + +``` +$ mvn spring-boot:run -Pquotes-application +``` + +## Gateway as Resource Server + +Use the provided maven profile: + +``` +$ mvn spring-boot:run -Pgateway-as-resource-server +``` + +## Gateway as OAuth 2.0 Client + +Use the provided maven profile: + +``` +$ mvn spring-boot:run -Pgateway-as-oauth-client +``` + + diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README.md b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README.md new file mode 100644 index 0000000000..80315040c9 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README.md @@ -0,0 +1,13 @@ +## Spring Cloud Gateway + +This module contains articles about Spring Cloud Gateway + +### Relevant Articles: + +- [Exploring the New Spring Cloud Gateway](http://www.baeldung.com/spring-cloud-gateway) +- [Writing Custom Spring Cloud Gateway Filters](https://www.baeldung.com/spring-cloud-custom-gateway-filters) +- [Spring Cloud Gateway Routing Predicate Factories](https://www.baeldung.com/spring-cloud-gateway-routing-predicate-factories) +- [Spring Cloud Gateway WebFilter Factories](https://www.baeldung.com/spring-cloud-gateway-webfilter-factories) +- [Using Spring Cloud Gateway with OAuth 2.0 Patterns](https://www.baeldung.com/spring-cloud-gateway-oauth2) +- [URL Rewriting With Spring Cloud Gateway](https://www.baeldung.com/spring-cloud-gateway-url-rewriting) +- [Processing the Response Body in Spring Cloud Gateway](https://www.baeldung.com/spring-cloud-gateway-response-body) diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/baeldung-realm.json b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/baeldung-realm.json new file mode 100644 index 0000000000..4dad262568 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/baeldung-realm.json @@ -0,0 +1,2186 @@ +{ + "id": "baeldung", + "realm": "baeldung", + "notBefore": 0, + "revokeRefreshToken": false, + "refreshTokenMaxReuse": 0, + "accessTokenLifespan": 300, + "accessTokenLifespanForImplicitFlow": 900, + "ssoSessionIdleTimeout": 1800, + "ssoSessionMaxLifespan": 36000, + "ssoSessionIdleTimeoutRememberMe": 0, + "ssoSessionMaxLifespanRememberMe": 0, + "offlineSessionIdleTimeout": 2592000, + "offlineSessionMaxLifespanEnabled": false, + "offlineSessionMaxLifespan": 5184000, + "clientSessionIdleTimeout": 0, + "clientSessionMaxLifespan": 0, + "clientOfflineSessionIdleTimeout": 0, + "clientOfflineSessionMaxLifespan": 0, + "accessCodeLifespan": 60, + "accessCodeLifespanUserAction": 300, + "accessCodeLifespanLogin": 1800, + "actionTokenGeneratedByAdminLifespan": 43200, + "actionTokenGeneratedByUserLifespan": 300, + "enabled": true, + "sslRequired": "external", + "registrationAllowed": false, + "registrationEmailAsUsername": false, + "rememberMe": false, + "verifyEmail": false, + "loginWithEmailAllowed": true, + "duplicateEmailsAllowed": false, + "resetPasswordAllowed": false, + "editUsernameAllowed": false, + "bruteForceProtected": false, + "permanentLockout": false, + "maxFailureWaitSeconds": 900, + "minimumQuickLoginWaitSeconds": 60, + "waitIncrementSeconds": 60, + "quickLoginCheckMilliSeconds": 1000, + "maxDeltaTimeSeconds": 43200, + "failureFactor": 30, + "roles": { + "realm": [ + { + "id": "2f721e46-398b-43ff-845f-3c747f1f69f5", + "name": "standard", + "description": "Standard customer", + "composite": false, + "clientRole": false, + "containerId": "baeldung", + "attributes": {} + }, + { + "id": "b8b1cb49-c953-4cb0-acea-62b24c4b6d30", + "name": "silver", + "description": "Silver customer", + "composite": false, + "clientRole": false, + "containerId": "baeldung", + "attributes": {} + }, + { + "id": "f44f5ba9-2393-4d2a-b581-81cf8dd7f245", + "name": "gold", + "description": "Gold customers", + "composite": false, + "clientRole": false, + "containerId": "baeldung", + "attributes": {} + }, + { + "id": "3b6109f5-6e5a-4578-83c3-791ec3e2bf9e", + "name": "offline_access", + "description": "${role_offline-access}", + "composite": false, + "clientRole": false, + "containerId": "baeldung", + "attributes": {} + }, + { + "id": "0dd6a8c7-d669-4941-9ea1-521980e9c53f", + "name": "uma_authorization", + "description": "${role_uma_authorization}", + "composite": false, + "clientRole": false, + "containerId": "baeldung", + "attributes": {} + }, + { + "id": "ca962095-7f9b-49e2-a190-e391a0d4b704", + "name": "user", + "composite": false, + "clientRole": false, + "containerId": "baeldung", + "attributes": {} + } + ], + "client": { + "newClient": [], + "realm-management": [ + { + "id": "5d00243f-ceec-4b0c-995e-d86d5b8a0ae6", + "name": "view-clients", + "description": "${role_view-clients}", + "composite": true, + "composites": { + "client": { + "realm-management": [ + "query-clients" + ] + } + }, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "941612de-bd85-47a5-8dfa-37c270dde28c", + "name": "view-authorization", + "description": "${role_view-authorization}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "5ea9810d-63cc-4277-9b32-ba8a3d3c6091", + "name": "manage-realm", + "description": "${role_manage-realm}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "8b7b0dd8-350b-473e-b8cd-8acad34f1358", + "name": "query-clients", + "description": "${role_query-clients}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "0f8e5ee8-b014-4b7c-9b69-50f46abcba5f", + "name": "query-groups", + "description": "${role_query-groups}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "911b1489-9383-4734-b134-bf49bf992ce9", + "name": "manage-clients", + "description": "${role_manage-clients}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "5d48274c-bd6b-4c26-ad54-f1a2254beac0", + "name": "view-realm", + "description": "${role_view-realm}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "3ea43b64-316f-4693-8346-9ee78b24adaf", + "name": "manage-identity-providers", + "description": "${role_manage-identity-providers}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "49735614-96ec-49b2-98fe-3af9bcd1a33a", + "name": "create-client", + "description": "${role_create-client}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "e8f8c3cc-0ff1-4f72-a271-db6821a3cdb6", + "name": "manage-users", + "description": "${role_manage-users}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "387418b1-4f80-4b00-b9dd-805ca041f805", + "name": "view-identity-providers", + "description": "${role_view-identity-providers}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "427c27d4-521a-464b-a0df-16d7f537e8d5", + "name": "realm-admin", + "description": "${role_realm-admin}", + "composite": true, + "composites": { + "client": { + "realm-management": [ + "view-clients", + "view-authorization", + "query-groups", + "manage-realm", + "query-clients", + "manage-clients", + "view-realm", + "manage-identity-providers", + "create-client", + "manage-users", + "view-identity-providers", + "query-users", + "query-realms", + "view-users", + "impersonation", + "manage-authorization", + "manage-events", + "view-events" + ] + } + }, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "a574cf01-03e4-4573-ab9e-276d13a1ce8d", + "name": "query-users", + "description": "${role_query-users}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "c3a253a8-a1b6-4d38-9677-f728f32482ad", + "name": "query-realms", + "description": "${role_query-realms}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "f3cb93da-273e-419a-b2f4-93f09896abcf", + "name": "view-users", + "description": "${role_view-users}", + "composite": true, + "composites": { + "client": { + "realm-management": [ + "query-users", + "query-groups" + ] + } + }, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "6eedf2b7-50ef-4495-a89b-54aef751b7fa", + "name": "manage-authorization", + "description": "${role_manage-authorization}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "0332e99b-3dfc-4193-9e13-5728f8f3e6d6", + "name": "impersonation", + "description": "${role_impersonation}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "b690cb9c-0f4a-4be5-ade0-b40443d8149d", + "name": "view-events", + "description": "${role_view-events}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, + { + "id": "aac3def5-f193-4a6c-9065-1667a0746a8a", + "name": "manage-events", + "description": "${role_manage-events}", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + } + ], + "security-admin-console": [], + "quotes-client": [], + "admin-cli": [], + "account-console": [], + "broker": [ + { + "id": "397b5703-4c81-48fd-a24c-a7e8177ef657", + "name": "read-token", + "description": "${role_read-token}", + "composite": false, + "clientRole": true, + "containerId": "4b9609f0-48d1-4e71-9381-2ecec08616f9", + "attributes": {} + } + ], + "account": [ + { + "id": "8daa8096-d14e-4d1c-ad1f-83f822016aa1", + "name": "manage-account", + "description": "${role_manage-account}", + "composite": true, + "composites": { + "client": { + "account": [ + "manage-account-links" + ] + } + }, + "clientRole": true, + "containerId": "12eebf0b-a3eb-49f8-9ecf-173cf8a00145", + "attributes": {} + }, + { + "id": "15f0d8be-932b-4565-8ad0-e8aa170093dd", + "name": "view-consent", + "description": "${role_view-consent}", + "composite": false, + "clientRole": true, + "containerId": "12eebf0b-a3eb-49f8-9ecf-173cf8a00145", + "attributes": {} + }, + { + "id": "c5aa697c-bf87-47c6-bd94-9121b72420b9", + "name": "view-applications", + "description": "${role_view-applications}", + "composite": false, + "clientRole": true, + "containerId": "12eebf0b-a3eb-49f8-9ecf-173cf8a00145", + "attributes": {} + }, + { + "id": "f0b3bbe4-aec1-4227-b9d3-2c314d612a04", + "name": "manage-consent", + "description": "${role_manage-consent}", + "composite": true, + "composites": { + "client": { + "account": [ + "view-consent" + ] + } + }, + "clientRole": true, + "containerId": "12eebf0b-a3eb-49f8-9ecf-173cf8a00145", + "attributes": {} + }, + { + "id": "948269c7-a69c-4c82-a7f3-88868713dfd9", + "name": "manage-account-links", + "description": "${role_manage-account-links}", + "composite": false, + "clientRole": true, + "containerId": "12eebf0b-a3eb-49f8-9ecf-173cf8a00145", + "attributes": {} + }, + { + "id": "aed18201-2433-4998-8fa3-0979b0b31c10", + "name": "view-profile", + "description": "${role_view-profile}", + "composite": false, + "clientRole": true, + "containerId": "12eebf0b-a3eb-49f8-9ecf-173cf8a00145", + "attributes": {} + } + ] + } + }, + "groups": [ + { + "id": "635c3314-f15f-4c02-bcb7-8739fd4c21b7", + "name": "golden_customers", + "path": "/golden_customers", + "attributes": {}, + "realmRoles": [ + "gold" + ], + "clientRoles": {}, + "subGroups": [] + }, + { + "id": "279c5ec4-0588-4884-91c1-2697ed5c9826", + "name": "silver_customers", + "path": "/silver_customers", + "attributes": {}, + "realmRoles": [ + "silver" + ], + "clientRoles": {}, + "subGroups": [] + } + ], + "defaultRoles": [ + "uma_authorization", + "offline_access" + ], + "requiredCredentials": [ + "password" + ], + "otpPolicyType": "totp", + "otpPolicyAlgorithm": "HmacSHA1", + "otpPolicyInitialCounter": 0, + "otpPolicyDigits": 6, + "otpPolicyLookAheadWindow": 1, + "otpPolicyPeriod": 30, + "otpSupportedApplications": [ + "FreeOTP", + "Google Authenticator" + ], + "webAuthnPolicyRpEntityName": "keycloak", + "webAuthnPolicySignatureAlgorithms": [ + "ES256" + ], + "webAuthnPolicyRpId": "", + "webAuthnPolicyAttestationConveyancePreference": "not specified", + "webAuthnPolicyAuthenticatorAttachment": "not specified", + "webAuthnPolicyRequireResidentKey": "not specified", + "webAuthnPolicyUserVerificationRequirement": "not specified", + "webAuthnPolicyCreateTimeout": 0, + "webAuthnPolicyAvoidSameAuthenticatorRegister": false, + "webAuthnPolicyAcceptableAaguids": [], + "webAuthnPolicyPasswordlessRpEntityName": "keycloak", + "webAuthnPolicyPasswordlessSignatureAlgorithms": [ + "ES256" + ], + "webAuthnPolicyPasswordlessRpId": "", + "webAuthnPolicyPasswordlessAttestationConveyancePreference": "not specified", + "webAuthnPolicyPasswordlessAuthenticatorAttachment": "not specified", + "webAuthnPolicyPasswordlessRequireResidentKey": "not specified", + "webAuthnPolicyPasswordlessUserVerificationRequirement": "not specified", + "webAuthnPolicyPasswordlessCreateTimeout": 0, + "webAuthnPolicyPasswordlessAvoidSameAuthenticatorRegister": false, + "webAuthnPolicyPasswordlessAcceptableAaguids": [], + "scopeMappings": [ + { + "clientScope": "offline_access", + "roles": [ + "offline_access" + ] + } + ], + "clientScopeMappings": { + "account": [ + { + "client": "account-console", + "roles": [ + "manage-account" + ] + } + ] + }, + "clients": [ + { + "id": "12eebf0b-a3eb-49f8-9ecf-173cf8a00145", + "clientId": "account", + "name": "${client_account}", + "rootUrl": "${authBaseUrl}", + "baseUrl": "/realms/baeldung/account/", + "surrogateAuthRequired": false, + "enabled": true, + "alwaysDisplayInConsole": false, + "clientAuthenticatorType": "client-secret", + "secret": "**********", + "defaultRoles": [ + "manage-account", + "view-profile" + ], + "redirectUris": [ + "/realms/baeldung/account/*" + ], + "webOrigins": [], + "notBefore": 0, + "bearerOnly": false, + "consentRequired": false, + "standardFlowEnabled": true, + "implicitFlowEnabled": false, + "directAccessGrantsEnabled": false, + "serviceAccountsEnabled": false, + "publicClient": false, + "frontchannelLogout": false, + "protocol": "openid-connect", + "attributes": {}, + "authenticationFlowBindingOverrides": {}, + "fullScopeAllowed": false, + "nodeReRegistrationTimeout": 0, + "defaultClientScopes": [ + "web-origins", + "role_list", + "roles", + "profile", + "email" + ], + "optionalClientScopes": [ + "address", + "phone", + "offline_access", + "microprofile-jwt" + ] + }, + { + "id": "8209784b-8540-43c2-aece-241acf12ea5a", + "clientId": "account-console", + "name": "${client_account-console}", + "rootUrl": "${authBaseUrl}", + "baseUrl": "/realms/baeldung/account/", + "surrogateAuthRequired": false, + "enabled": true, + "alwaysDisplayInConsole": false, + "clientAuthenticatorType": "client-secret", + "secret": "**********", + "redirectUris": [ + "/realms/baeldung/account/*" + ], + "webOrigins": [], + "notBefore": 0, + "bearerOnly": false, + "consentRequired": false, + "standardFlowEnabled": true, + "implicitFlowEnabled": false, + "directAccessGrantsEnabled": false, + "serviceAccountsEnabled": false, + "publicClient": true, + "frontchannelLogout": false, + "protocol": "openid-connect", + "attributes": { + "pkce.code.challenge.method": "S256" + }, + "authenticationFlowBindingOverrides": {}, + "fullScopeAllowed": false, + "nodeReRegistrationTimeout": 0, + "protocolMappers": [ + { + "id": "58395b96-1718-4787-8f92-74577e2bfc30", + "name": "audience resolve", + "protocol": "openid-connect", + "protocolMapper": "oidc-audience-resolve-mapper", + "consentRequired": false, + "config": {} + } + ], + "defaultClientScopes": [ + "web-origins", + "role_list", + "roles", + "profile", + "email" + ], + "optionalClientScopes": [ + "address", + "phone", + "offline_access", + "microprofile-jwt" + ] + }, + { + "id": "13d76feb-d762-4409-bb84-7a75bc395a61", + "clientId": "admin-cli", + "name": "${client_admin-cli}", + "surrogateAuthRequired": false, + "enabled": true, + "alwaysDisplayInConsole": false, + "clientAuthenticatorType": "client-secret", + "secret": "**********", + "redirectUris": [], + "webOrigins": [], + "notBefore": 0, + "bearerOnly": false, + "consentRequired": false, + "standardFlowEnabled": false, + "implicitFlowEnabled": false, + "directAccessGrantsEnabled": true, + "serviceAccountsEnabled": false, + "publicClient": true, + "frontchannelLogout": false, + "protocol": "openid-connect", + "attributes": {}, + "authenticationFlowBindingOverrides": {}, + "fullScopeAllowed": false, + "nodeReRegistrationTimeout": 0, + "defaultClientScopes": [ + "web-origins", + "role_list", + "roles", + "profile", + "email" + ], + "optionalClientScopes": [ + "address", + "phone", + "offline_access", + "microprofile-jwt" + ] + }, + { + "id": "4b9609f0-48d1-4e71-9381-2ecec08616f9", + "clientId": "broker", + "name": "${client_broker}", + "surrogateAuthRequired": false, + "enabled": true, + "alwaysDisplayInConsole": false, + "clientAuthenticatorType": "client-secret", + "secret": "**********", + "redirectUris": [], + "webOrigins": [], + "notBefore": 0, + "bearerOnly": false, + "consentRequired": false, + "standardFlowEnabled": true, + "implicitFlowEnabled": false, + "directAccessGrantsEnabled": false, + "serviceAccountsEnabled": false, + "publicClient": false, + "frontchannelLogout": false, + "protocol": "openid-connect", + "attributes": {}, + "authenticationFlowBindingOverrides": {}, + "fullScopeAllowed": false, + "nodeReRegistrationTimeout": 0, + "defaultClientScopes": [ + "web-origins", + "role_list", + "roles", + "profile", + "email" + ], + "optionalClientScopes": [ + "address", + "phone", + "offline_access", + "microprofile-jwt" + ] + }, + { + "id": "b88ce206-63d6-43b6-87c9-ea09d8c02f32", + "clientId": "newClient", + "surrogateAuthRequired": false, + "enabled": true, + "alwaysDisplayInConsole": false, + "clientAuthenticatorType": "client-secret", + "secret": "**********", + "redirectUris": [ + "http://localhost:8082/new-client/login/oauth2/code/custom", + "http://localhost:8089/", + "http://localhost:8089/auth/redirect/" + ], + "webOrigins": [ + "+" + ], + "notBefore": 0, + "bearerOnly": false, + "consentRequired": false, + "standardFlowEnabled": true, + "implicitFlowEnabled": true, + "directAccessGrantsEnabled": true, + "serviceAccountsEnabled": false, + "publicClient": false, + "frontchannelLogout": false, + "protocol": "openid-connect", + "attributes": { + "saml.assertion.signature": "false", + "saml.force.post.binding": "false", + "saml.multivalued.roles": "false", + "saml.encrypt": "false", + "saml.server.signature": "false", + "saml.server.signature.keyinfo.ext": "false", + "exclude.session.state.from.auth.response": "false", + "saml_force_name_id_format": "false", + "saml.client.signature": "false", + "tls.client.certificate.bound.access.tokens": "false", + "saml.authnstatement": "false", + "display.on.consent.screen": "false", + "saml.onetimeuse.condition": "false" + }, + "authenticationFlowBindingOverrides": {}, + "fullScopeAllowed": true, + "nodeReRegistrationTimeout": -1, + "defaultClientScopes": [ + "role_list", + "profile" + ], + "optionalClientScopes": [ + "web-origins", + "address", + "read", + "phone", + "roles", + "offline_access", + "microprofile-jwt", + "write", + "email" + ] + }, + { + "id": "5898f71f-b91e-4c3f-9c86-48de0e8665c4", + "clientId": "quotes-client", + "name": "Quotes Client", + "surrogateAuthRequired": false, + "enabled": true, + "alwaysDisplayInConsole": false, + "clientAuthenticatorType": "client-secret", + "secret": "0e082231-a70d-48e8-b8a5-fbfb743041b6", + "redirectUris": [ + "http://localhost:8082/*", + "http://localhost:8087/*" + ], + "webOrigins": [], + "notBefore": 0, + "bearerOnly": false, + "consentRequired": false, + "standardFlowEnabled": true, + "implicitFlowEnabled": false, + "directAccessGrantsEnabled": true, + "serviceAccountsEnabled": false, + "publicClient": false, + "frontchannelLogout": false, + "protocol": "openid-connect", + "attributes": { + "saml.assertion.signature": "false", + "saml.multivalued.roles": "false", + "saml.force.post.binding": "false", + "saml.encrypt": "false", + "saml.server.signature": "false", + "saml.server.signature.keyinfo.ext": "false", + "exclude.session.state.from.auth.response": "false", + "saml_force_name_id_format": "false", + "saml.client.signature": "false", + "tls.client.certificate.bound.access.tokens": "false", + "saml.authnstatement": "false", + "display.on.consent.screen": "false", + "saml.onetimeuse.condition": "false" + }, + "authenticationFlowBindingOverrides": {}, + "fullScopeAllowed": true, + "nodeReRegistrationTimeout": -1, + "protocolMappers": [ + { + "id": "008d32b5-ea7b-4739-89af-e90fe137bda9", + "name": "realm roles", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-realm-role-mapper", + "consentRequired": false, + "config": { + "user.attribute": "foo", + "access.token.claim": "true", + "claim.name": "realm_access.roles", + "jsonType.label": "String", + "multivalued": "true" + } + } + ], + "defaultClientScopes": [ + "web-origins", + "role_list", + "roles", + "profile", + "email" + ], + "optionalClientScopes": [ + "address", + "phone", + "offline_access", + "microprofile-jwt" + ] + }, + { + "id": "6a4bfbd0-576d-4778-af56-56f876647355", + "clientId": "realm-management", + "name": "${client_realm-management}", + "surrogateAuthRequired": false, + "enabled": true, + "alwaysDisplayInConsole": false, + "clientAuthenticatorType": "client-secret", + "secret": "**********", + "redirectUris": [], + "webOrigins": [], + "notBefore": 0, + "bearerOnly": true, + "consentRequired": false, + "standardFlowEnabled": true, + "implicitFlowEnabled": false, + "directAccessGrantsEnabled": false, + "serviceAccountsEnabled": false, + "publicClient": false, + "frontchannelLogout": false, + "protocol": "openid-connect", + "attributes": {}, + "authenticationFlowBindingOverrides": {}, + "fullScopeAllowed": false, + "nodeReRegistrationTimeout": 0, + "defaultClientScopes": [ + "web-origins", + "role_list", + "roles", + "profile", + "email" + ], + "optionalClientScopes": [ + "address", + "phone", + "offline_access", + "microprofile-jwt" + ] + }, + { + "id": "8e358d2f-b085-4243-8e6e-c175431e5eeb", + "clientId": "security-admin-console", + "name": "${client_security-admin-console}", + "rootUrl": "${authAdminUrl}", + "baseUrl": "/admin/baeldung/console/", + "surrogateAuthRequired": false, + "enabled": true, + "alwaysDisplayInConsole": false, + "clientAuthenticatorType": "client-secret", + "secret": "**********", + "redirectUris": [ + "/admin/baeldung/console/*" + ], + "webOrigins": [ + "+" + ], + "notBefore": 0, + "bearerOnly": false, + "consentRequired": false, + "standardFlowEnabled": true, + "implicitFlowEnabled": false, + "directAccessGrantsEnabled": false, + "serviceAccountsEnabled": false, + "publicClient": true, + "frontchannelLogout": false, + "protocol": "openid-connect", + "attributes": { + "pkce.code.challenge.method": "S256" + }, + "authenticationFlowBindingOverrides": {}, + "fullScopeAllowed": false, + "nodeReRegistrationTimeout": 0, + "protocolMappers": [ + { + "id": "9cfca9ee-493d-4b5e-8170-2d364149de59", + "name": "locale", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "locale", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "locale", + "jsonType.label": "String" + } + } + ], + "defaultClientScopes": [ + "web-origins", + "role_list", + "roles", + "profile", + "email" + ], + "optionalClientScopes": [ + "address", + "phone", + "offline_access", + "microprofile-jwt" + ] + } + ], + "clientScopes": [ + { + "id": "77c7e29d-1a22-4419-bbfb-4a62bb033449", + "name": "address", + "description": "OpenID Connect built-in scope: address", + "protocol": "openid-connect", + "attributes": { + "include.in.token.scope": "true", + "display.on.consent.screen": "true", + "consent.screen.text": "${addressScopeConsentText}" + }, + "protocolMappers": [ + { + "id": "94e1879d-b49e-4178-96e0-bf8d7f32c160", + "name": "address", + "protocol": "openid-connect", + "protocolMapper": "oidc-address-mapper", + "consentRequired": false, + "config": { + "user.attribute.formatted": "formatted", + "user.attribute.country": "country", + "user.attribute.postal_code": "postal_code", + "userinfo.token.claim": "true", + "user.attribute.street": "street", + "id.token.claim": "true", + "user.attribute.region": "region", + "access.token.claim": "true", + "user.attribute.locality": "locality" + } + } + ] + }, + { + "id": "b3526ac1-10e2-4344-8621-9c5a0853e97a", + "name": "email", + "description": "OpenID Connect built-in scope: email", + "protocol": "openid-connect", + "attributes": { + "include.in.token.scope": "true", + "display.on.consent.screen": "true", + "consent.screen.text": "${emailScopeConsentText}" + }, + "protocolMappers": [ + { + "id": "d30270dc-baa6-455a-8ff6-ddccf8a78d86", + "name": "email verified", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-property-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "emailVerified", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "email_verified", + "jsonType.label": "boolean" + } + }, + { + "id": "f5b1684d-e479-4134-8578-457fa64717da", + "name": "email", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-property-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "email", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "email", + "jsonType.label": "String" + } + } + ] + }, + { + "id": "c658ae14-e96a-4745-b21b-2ed5c4c63f5f", + "name": "microprofile-jwt", + "description": "Microprofile - JWT built-in scope", + "protocol": "openid-connect", + "attributes": { + "include.in.token.scope": "true", + "display.on.consent.screen": "false" + }, + "protocolMappers": [ + { + "id": "959521bc-5ffd-465b-95f2-5b0c20d1909c", + "name": "upn", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-property-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "username", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "upn", + "jsonType.label": "String" + } + }, + { + "id": "07b8550c-b298-4cce-9ffb-900182575b76", + "name": "groups", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-realm-role-mapper", + "consentRequired": false, + "config": { + "multivalued": "true", + "userinfo.token.claim": "true", + "user.attribute": "foo", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "groups", + "jsonType.label": "String" + } + } + ] + }, + { + "id": "569b3d44-4ecd-4768-a58c-70ff38f4b4fe", + "name": "offline_access", + "description": "OpenID Connect built-in scope: offline_access", + "protocol": "openid-connect", + "attributes": { + "consent.screen.text": "${offlineAccessScopeConsentText}", + "display.on.consent.screen": "true" + } + }, + { + "id": "a3e7b19d-df6c-437e-9eea-06fec1becb2f", + "name": "phone", + "description": "OpenID Connect built-in scope: phone", + "protocol": "openid-connect", + "attributes": { + "include.in.token.scope": "true", + "display.on.consent.screen": "true", + "consent.screen.text": "${phoneScopeConsentText}" + }, + "protocolMappers": [ + { + "id": "72a070f7-4363-4c88-8153-6fd2d12b9b04", + "name": "phone number verified", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "phoneNumberVerified", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "phone_number_verified", + "jsonType.label": "boolean" + } + }, + { + "id": "24b42c6d-a93c-4aa1-9a03-2a2b55954c13", + "name": "phone number", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "phoneNumber", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "phone_number", + "jsonType.label": "String" + } + } + ] + }, + { + "id": "ba8c9950-fd0b-4434-8be6-b58456d7b6d4", + "name": "profile", + "description": "OpenID Connect built-in scope: profile", + "protocol": "openid-connect", + "attributes": { + "include.in.token.scope": "true", + "display.on.consent.screen": "true", + "consent.screen.text": "${profileScopeConsentText}" + }, + "protocolMappers": [ + { + "id": "0a9ddd71-309c-40f0-8ea6-a0791070c6ed", + "name": "profile", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "profile", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "profile", + "jsonType.label": "String" + } + }, + { + "id": "fbf53bbd-1ad0-4bf8-8030-50f81696d8ee", + "name": "nickname", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "nickname", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "nickname", + "jsonType.label": "String" + } + }, + { + "id": "423be2cd-42c0-462e-9030-18f9b28ff2d3", + "name": "gender", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "gender", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "gender", + "jsonType.label": "String" + } + }, + { + "id": "53eb9006-4b81-474a-8b60-80f775d54b63", + "name": "picture", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "picture", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "picture", + "jsonType.label": "String" + } + }, + { + "id": "4d8bc82a-eaeb-499e-8eb2-0f1dcbe91699", + "name": "locale", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "locale", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "locale", + "jsonType.label": "String" + } + }, + { + "id": "d3b25485-4042-419d-afff-cfd63a76e229", + "name": "full name", + "protocol": "openid-connect", + "protocolMapper": "oidc-full-name-mapper", + "consentRequired": false, + "config": { + "id.token.claim": "true", + "access.token.claim": "true", + "userinfo.token.claim": "true" + } + }, + { + "id": "422cfa5a-f2f4-4f36-82df-91b47ae1ea50", + "name": "given name", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-property-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "firstName", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "given_name", + "jsonType.label": "String" + } + }, + { + "id": "3f2863c1-d98d-45b5-b08f-af9c4d9c10f8", + "name": "website", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "website", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "website", + "jsonType.label": "String" + } + }, + { + "id": "c98c063d-eee4-41a0-9130-595afd709d1f", + "name": "middle name", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "middleName", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "middle_name", + "jsonType.label": "String" + } + }, + { + "id": "8dbed80a-d672-4185-8dda-4bba2a56ec83", + "name": "family name", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-property-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "lastName", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "family_name", + "jsonType.label": "String" + } + }, + { + "id": "5e5c690c-93cf-489d-a054-b109eab8911b", + "name": "updated at", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "updatedAt", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "updated_at", + "jsonType.label": "String" + } + }, + { + "id": "3b985202-af8a-42f1-ac5f-0966a404f5d7", + "name": "birthdate", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "birthdate", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "birthdate", + "jsonType.label": "String" + } + }, + { + "id": "6eafd1b3-7121-4919-ad1e-039fa58acc32", + "name": "username", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-property-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "username", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "preferred_username", + "jsonType.label": "String" + } + }, + { + "id": "73cba925-8c31-443f-9601-b1514e6396c1", + "name": "zoneinfo", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "zoneinfo", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "zoneinfo", + "jsonType.label": "String" + } + } + ] + }, + { + "id": "c1a2eb23-25c6-4be7-a791-bbdca99c83f7", + "name": "read", + "protocol": "openid-connect", + "attributes": { + "include.in.token.scope": "true", + "display.on.consent.screen": "true" + } + }, + { + "id": "18e141bf-dabe-4858-879c-dbc439cdead4", + "name": "role_list", + "description": "SAML role list", + "protocol": "saml", + "attributes": { + "consent.screen.text": "${samlRoleListScopeConsentText}", + "display.on.consent.screen": "true" + }, + "protocolMappers": [ + { + "id": "10cbe37f-0198-4d65-bc8a-bfe5ad8145d1", + "name": "role list", + "protocol": "saml", + "protocolMapper": "saml-role-list-mapper", + "consentRequired": false, + "config": { + "single": "false", + "attribute.nameformat": "Basic", + "attribute.name": "Role" + } + } + ] + }, + { + "id": "111ed87a-5fd3-4cee-96df-8dbfb88cfdc0", + "name": "roles", + "description": "OpenID Connect scope for add user roles to the access token", + "protocol": "openid-connect", + "attributes": { + "include.in.token.scope": "false", + "display.on.consent.screen": "true", + "consent.screen.text": "${rolesScopeConsentText}" + }, + "protocolMappers": [ + { + "id": "24924d8d-6071-4a93-b40f-326176cb335e", + "name": "realm roles", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-realm-role-mapper", + "consentRequired": false, + "config": { + "user.attribute": "foo", + "access.token.claim": "true", + "claim.name": "realm_access.roles", + "jsonType.label": "String", + "multivalued": "true" + } + }, + { + "id": "2f6a9bdf-3758-484c-996d-e4f93555559f", + "name": "audience resolve", + "protocol": "openid-connect", + "protocolMapper": "oidc-audience-resolve-mapper", + "consentRequired": false, + "config": {} + }, + { + "id": "804d4798-d9a3-4fd3-8b28-d12142e8cb3d", + "name": "client roles", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-client-role-mapper", + "consentRequired": false, + "config": { + "user.attribute": "foo", + "access.token.claim": "true", + "claim.name": "resource_access.${client_id}.roles", + "jsonType.label": "String", + "multivalued": "true" + } + } + ] + }, + { + "id": "51d49314-b511-43e0-9258-bfb873758a78", + "name": "web-origins", + "description": "OpenID Connect scope for add allowed web origins to the access token", + "protocol": "openid-connect", + "attributes": { + "include.in.token.scope": "false", + "display.on.consent.screen": "false", + "consent.screen.text": "" + }, + "protocolMappers": [ + { + "id": "2b384cd0-9e85-4a87-8eeb-2b480b0587b7", + "name": "allowed web origins", + "protocol": "openid-connect", + "protocolMapper": "oidc-allowed-origins-mapper", + "consentRequired": false, + "config": {} + } + ] + }, + { + "id": "c3e253fb-7361-47cf-9d4a-86245686fdf1", + "name": "write", + "protocol": "openid-connect", + "attributes": { + "include.in.token.scope": "true", + "display.on.consent.screen": "true" + } + } + ], + "defaultDefaultClientScopes": [ + "roles", + "role_list", + "web-origins", + "email", + "profile" + ], + "defaultOptionalClientScopes": [ + "offline_access", + "address", + "phone", + "microprofile-jwt" + ], + "browserSecurityHeaders": { + "contentSecurityPolicyReportOnly": "", + "xContentTypeOptions": "nosniff", + "xRobotsTag": "none", + "xFrameOptions": "SAMEORIGIN", + "contentSecurityPolicy": "frame-src 'self'; frame-ancestors 'self'; object-src 'none';", + "xXSSProtection": "1; mode=block", + "strictTransportSecurity": "max-age=31536000; includeSubDomains" + }, + "smtpServer": {}, + "eventsEnabled": false, + "eventsListeners": [ + "jboss-logging" + ], + "enabledEventTypes": [], + "adminEventsEnabled": false, + "adminEventsDetailsEnabled": false, + "components": { + "org.keycloak.services.clientregistration.policy.ClientRegistrationPolicy": [ + { + "id": "84305f42-4b6d-4b0a-ac7c-53e406e3ac63", + "name": "Allowed Client Scopes", + "providerId": "allowed-client-templates", + "subType": "authenticated", + "subComponents": {}, + "config": { + "allow-default-scopes": [ + "true" + ] + } + }, + { + "id": "c7c38a95-744f-4558-a403-9cf692fe1944", + "name": "Allowed Client Scopes", + "providerId": "allowed-client-templates", + "subType": "anonymous", + "subComponents": {}, + "config": { + "allow-default-scopes": [ + "true" + ] + } + }, + { + "id": "365b2899-befe-4417-b89b-562650ec4446", + "name": "Full Scope Disabled", + "providerId": "scope", + "subType": "anonymous", + "subComponents": {}, + "config": {} + }, + { + "id": "81c32244-7921-43e9-9356-a3469259b78c", + "name": "Trusted Hosts", + "providerId": "trusted-hosts", + "subType": "anonymous", + "subComponents": {}, + "config": { + "host-sending-registration-request-must-match": [ + "true" + ], + "client-uris-must-match": [ + "true" + ] + } + }, + { + "id": "d09b2147-afea-4f7f-a49c-0aec7eee10de", + "name": "Max Clients Limit", + "providerId": "max-clients", + "subType": "anonymous", + "subComponents": {}, + "config": { + "max-clients": [ + "200" + ] + } + }, + { + "id": "41ffde1b-72a2-416f-87a7-94989e940dc0", + "name": "Allowed Protocol Mapper Types", + "providerId": "allowed-protocol-mappers", + "subType": "authenticated", + "subComponents": {}, + "config": { + "allowed-protocol-mapper-types": [ + "saml-user-property-mapper", + "oidc-address-mapper", + "oidc-usermodel-property-mapper", + "oidc-full-name-mapper", + "oidc-sha256-pairwise-sub-mapper", + "saml-role-list-mapper", + "oidc-usermodel-attribute-mapper", + "saml-user-attribute-mapper" + ] + } + }, + { + "id": "76075388-2782-4656-a986-313493239a9f", + "name": "Consent Required", + "providerId": "consent-required", + "subType": "anonymous", + "subComponents": {}, + "config": {} + }, + { + "id": "3caaf57a-9cd7-48c1-b709-b40b887414f7", + "name": "Allowed Protocol Mapper Types", + "providerId": "allowed-protocol-mappers", + "subType": "anonymous", + "subComponents": {}, + "config": { + "allowed-protocol-mapper-types": [ + "oidc-usermodel-attribute-mapper", + "saml-user-property-mapper", + "oidc-usermodel-property-mapper", + "oidc-full-name-mapper", + "saml-user-attribute-mapper", + "oidc-address-mapper", + "saml-role-list-mapper", + "oidc-sha256-pairwise-sub-mapper" + ] + } + } + ], + "org.keycloak.keys.KeyProvider": [ + { + "id": "d67a940a-52e4-44a5-9f69-6ffdd67a188f", + "name": "rsa-generated", + "providerId": "rsa-generated", + "subComponents": {}, + "config": { + "priority": [ + "100" + ] + } + }, + { + "id": "48d40de3-6234-42e8-9449-f68f56abb54b", + "name": "aes-generated", + "providerId": "aes-generated", + "subComponents": {}, + "config": { + "priority": [ + "100" + ] + } + }, + { + "id": "52ea1c5d-2a30-459f-b66a-249f298b32f8", + "name": "hmac-generated", + "providerId": "hmac-generated", + "subComponents": {}, + "config": { + "priority": [ + "100" + ], + "algorithm": [ + "HS256" + ] + } + } + ] + }, + "internationalizationEnabled": false, + "supportedLocales": [], + "authenticationFlows": [ + { + "id": "b35b726e-c1cc-4a31-8670-8c858c088498", + "alias": "Handle Existing Account", + "description": "Handle what to do if there is existing account with same email/username like authenticated identity provider", + "providerId": "basic-flow", + "topLevel": false, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "idp-confirm-link", + "requirement": "REQUIRED", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "requirement": "REQUIRED", + "priority": 20, + "flowAlias": "Handle Existing Account - Alternatives - 0", + "userSetupAllowed": false, + "autheticatorFlow": true + } + ] + }, + { + "id": "b7cb4b8c-0064-4c6b-95ee-d7f50011bae7", + "alias": "Handle Existing Account - Alternatives - 0", + "description": "Subflow of Handle Existing Account with alternative executions", + "providerId": "basic-flow", + "topLevel": false, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "idp-email-verification", + "requirement": "ALTERNATIVE", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "requirement": "ALTERNATIVE", + "priority": 20, + "flowAlias": "Verify Existing Account by Re-authentication", + "userSetupAllowed": false, + "autheticatorFlow": true + } + ] + }, + { + "id": "2576bf21-a516-4e22-8ed8-8a1a3d35c06a", + "alias": "Verify Existing Account by Re-authentication", + "description": "Reauthentication of existing account", + "providerId": "basic-flow", + "topLevel": false, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "idp-username-password-form", + "requirement": "REQUIRED", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "requirement": "CONDITIONAL", + "priority": 20, + "flowAlias": "Verify Existing Account by Re-authentication - auth-otp-form - Conditional", + "userSetupAllowed": false, + "autheticatorFlow": true + } + ] + }, + { + "id": "867b0355-c2b0-4f4e-b535-09406e2bc086", + "alias": "Verify Existing Account by Re-authentication - auth-otp-form - Conditional", + "description": "Flow to determine if the auth-otp-form authenticator should be used or not.", + "providerId": "basic-flow", + "topLevel": false, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "conditional-user-configured", + "requirement": "REQUIRED", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "auth-otp-form", + "requirement": "REQUIRED", + "priority": 20, + "userSetupAllowed": false, + "autheticatorFlow": false + } + ] + }, + { + "id": "52e45a6a-292f-4a34-9c02-7f97d9997a9c", + "alias": "browser", + "description": "browser based authentication", + "providerId": "basic-flow", + "topLevel": true, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "auth-cookie", + "requirement": "ALTERNATIVE", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "auth-spnego", + "requirement": "DISABLED", + "priority": 20, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "identity-provider-redirector", + "requirement": "ALTERNATIVE", + "priority": 25, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "requirement": "ALTERNATIVE", + "priority": 30, + "flowAlias": "forms", + "userSetupAllowed": false, + "autheticatorFlow": true + } + ] + }, + { + "id": "ef818d24-fb06-418a-a093-16239068cb58", + "alias": "clients", + "description": "Base authentication for clients", + "providerId": "client-flow", + "topLevel": true, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "client-secret", + "requirement": "ALTERNATIVE", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "client-jwt", + "requirement": "ALTERNATIVE", + "priority": 20, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "client-secret-jwt", + "requirement": "ALTERNATIVE", + "priority": 30, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "client-x509", + "requirement": "ALTERNATIVE", + "priority": 40, + "userSetupAllowed": false, + "autheticatorFlow": false + } + ] + }, + { + "id": "f7864004-be4b-40f2-8534-454981f09f98", + "alias": "direct grant", + "description": "OpenID Connect Resource Owner Grant", + "providerId": "basic-flow", + "topLevel": true, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "direct-grant-validate-username", + "requirement": "REQUIRED", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "direct-grant-validate-password", + "requirement": "REQUIRED", + "priority": 20, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "requirement": "CONDITIONAL", + "priority": 30, + "flowAlias": "direct grant - direct-grant-validate-otp - Conditional", + "userSetupAllowed": false, + "autheticatorFlow": true + } + ] + }, + { + "id": "233225f2-78b0-4756-9568-a775ea7cc975", + "alias": "direct grant - direct-grant-validate-otp - Conditional", + "description": "Flow to determine if the direct-grant-validate-otp authenticator should be used or not.", + "providerId": "basic-flow", + "topLevel": false, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "conditional-user-configured", + "requirement": "REQUIRED", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "direct-grant-validate-otp", + "requirement": "REQUIRED", + "priority": 20, + "userSetupAllowed": false, + "autheticatorFlow": false + } + ] + }, + { + "id": "2787939c-3312-4d56-9d61-22a71947e154", + "alias": "docker auth", + "description": "Used by Docker clients to authenticate against the IDP", + "providerId": "basic-flow", + "topLevel": true, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "docker-http-basic-authenticator", + "requirement": "REQUIRED", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + } + ] + }, + { + "id": "c80ca473-6e65-4140-a9d1-035414546bfb", + "alias": "first broker login", + "description": "Actions taken after first broker login with identity provider account, which is not yet linked to any Keycloak account", + "providerId": "basic-flow", + "topLevel": true, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticatorConfig": "review profile config", + "authenticator": "idp-review-profile", + "requirement": "REQUIRED", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "requirement": "REQUIRED", + "priority": 20, + "flowAlias": "first broker login - Alternatives - 0", + "userSetupAllowed": false, + "autheticatorFlow": true + } + ] + }, + { + "id": "700a71e1-f176-432e-9e70-ccb06d539730", + "alias": "first broker login - Alternatives - 0", + "description": "Subflow of first broker login with alternative executions", + "providerId": "basic-flow", + "topLevel": false, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticatorConfig": "create unique user config", + "authenticator": "idp-create-user-if-unique", + "requirement": "ALTERNATIVE", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "requirement": "ALTERNATIVE", + "priority": 20, + "flowAlias": "Handle Existing Account", + "userSetupAllowed": false, + "autheticatorFlow": true + } + ] + }, + { + "id": "13cd2ee9-8ebb-4651-8a9d-535d4020d889", + "alias": "forms", + "description": "Username, password, otp and other auth forms.", + "providerId": "basic-flow", + "topLevel": false, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "auth-username-password-form", + "requirement": "REQUIRED", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "requirement": "CONDITIONAL", + "priority": 20, + "flowAlias": "forms - auth-otp-form - Conditional", + "userSetupAllowed": false, + "autheticatorFlow": true + } + ] + }, + { + "id": "80067ebf-72b9-4ba5-abc3-161dfdd53938", + "alias": "forms - auth-otp-form - Conditional", + "description": "Flow to determine if the auth-otp-form authenticator should be used or not.", + "providerId": "basic-flow", + "topLevel": false, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "conditional-user-configured", + "requirement": "REQUIRED", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "auth-otp-form", + "requirement": "REQUIRED", + "priority": 20, + "userSetupAllowed": false, + "autheticatorFlow": false + } + ] + }, + { + "id": "269354b1-7dd7-46ff-8a69-084cd2c7be80", + "alias": "http challenge", + "description": "An authentication flow based on challenge-response HTTP Authentication Schemes", + "providerId": "basic-flow", + "topLevel": true, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "no-cookie-redirect", + "requirement": "REQUIRED", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "basic-auth", + "requirement": "REQUIRED", + "priority": 20, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "basic-auth-otp", + "requirement": "DISABLED", + "priority": 30, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "auth-spnego", + "requirement": "DISABLED", + "priority": 40, + "userSetupAllowed": false, + "autheticatorFlow": false + } + ] + }, + { + "id": "c5fa64a0-e784-490f-8879-0e8a209e3636", + "alias": "registration", + "description": "registration flow", + "providerId": "basic-flow", + "topLevel": true, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "registration-page-form", + "requirement": "REQUIRED", + "priority": 10, + "flowAlias": "registration form", + "userSetupAllowed": false, + "autheticatorFlow": true + } + ] + }, + { + "id": "bc48f897-4d16-49a8-be70-183c7867e20a", + "alias": "registration form", + "description": "registration form", + "providerId": "form-flow", + "topLevel": false, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "registration-user-creation", + "requirement": "REQUIRED", + "priority": 20, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "registration-profile-action", + "requirement": "REQUIRED", + "priority": 40, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "registration-password-action", + "requirement": "REQUIRED", + "priority": 50, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "registration-recaptcha-action", + "requirement": "DISABLED", + "priority": 60, + "userSetupAllowed": false, + "autheticatorFlow": false + } + ] + }, + { + "id": "fddaba41-87b1-40d1-b147-f062c38e39ad", + "alias": "reset credentials", + "description": "Reset credentials for a user if they forgot their password or something", + "providerId": "basic-flow", + "topLevel": true, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "reset-credentials-choose-user", + "requirement": "REQUIRED", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "reset-credential-email", + "requirement": "REQUIRED", + "priority": 20, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "reset-password", + "requirement": "REQUIRED", + "priority": 30, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "requirement": "CONDITIONAL", + "priority": 40, + "flowAlias": "reset credentials - reset-otp - Conditional", + "userSetupAllowed": false, + "autheticatorFlow": true + } + ] + }, + { + "id": "6b9fa295-1eb4-48b0-a286-b17ebd6be7e1", + "alias": "reset credentials - reset-otp - Conditional", + "description": "Flow to determine if the reset-otp authenticator should be used or not.", + "providerId": "basic-flow", + "topLevel": false, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "conditional-user-configured", + "requirement": "REQUIRED", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + }, + { + "authenticator": "reset-otp", + "requirement": "REQUIRED", + "priority": 20, + "userSetupAllowed": false, + "autheticatorFlow": false + } + ] + }, + { + "id": "c890d4c4-e4e2-4618-b69d-8d30f8278965", + "alias": "saml ecp", + "description": "SAML ECP Profile Authentication Flow", + "providerId": "basic-flow", + "topLevel": true, + "builtIn": true, + "authenticationExecutions": [ + { + "authenticator": "http-basic-authenticator", + "requirement": "REQUIRED", + "priority": 10, + "userSetupAllowed": false, + "autheticatorFlow": false + } + ] + } + ], + "authenticatorConfig": [ + { + "id": "2b02fbe4-e05e-4238-bb0e-04da7d4efd4e", + "alias": "create unique user config", + "config": { + "require.password.update.after.registration": "false" + } + }, + { + "id": "07dd933b-ce95-4a7c-bd81-3efa24f9558c", + "alias": "review profile config", + "config": { + "update.profile.on.first.login": "missing" + } + } + ], + "requiredActions": [ + { + "alias": "CONFIGURE_TOTP", + "name": "Configure OTP", + "providerId": "CONFIGURE_TOTP", + "enabled": true, + "defaultAction": false, + "priority": 10, + "config": {} + }, + { + "alias": "terms_and_conditions", + "name": "Terms and Conditions", + "providerId": "terms_and_conditions", + "enabled": false, + "defaultAction": false, + "priority": 20, + "config": {} + }, + { + "alias": "UPDATE_PASSWORD", + "name": "Update Password", + "providerId": "UPDATE_PASSWORD", + "enabled": true, + "defaultAction": false, + "priority": 30, + "config": {} + }, + { + "alias": "UPDATE_PROFILE", + "name": "Update Profile", + "providerId": "UPDATE_PROFILE", + "enabled": true, + "defaultAction": false, + "priority": 40, + "config": {} + }, + { + "alias": "VERIFY_EMAIL", + "name": "Verify Email", + "providerId": "VERIFY_EMAIL", + "enabled": true, + "defaultAction": false, + "priority": 50, + "config": {} + }, + { + "alias": "update_user_locale", + "name": "Update User Locale", + "providerId": "update_user_locale", + "enabled": true, + "defaultAction": false, + "priority": 1000, + "config": {} + } + ], + "browserFlow": "browser", + "registrationFlow": "registration", + "directGrantFlow": "direct grant", + "resetCredentialsFlow": "reset credentials", + "clientAuthenticationFlow": "clients", + "dockerAuthenticationFlow": "docker auth", + "attributes": { + "clientOfflineSessionMaxLifespan": "0", + "clientSessionIdleTimeout": "0", + "clientSessionMaxLifespan": "0", + "clientOfflineSessionIdleTimeout": "0" + }, + "keycloakVersion": "11.0.2", + "userManagedAccessAllowed": false +} \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml new file mode 100644 index 0000000000..dc42483dc5 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml @@ -0,0 +1,194 @@ + + + 4.0.0 + gateway-2 + spring-cloud-gateway + jar + + + com.baeldung.spring.cloud + spring-cloud-modules + 1.0.0-SNAPSHOT + + + + + + org.junit + junit-bom + ${junit-jupiter.version} + pom + import + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud-dependencies.version} + pom + import + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + org.springframework.cloud + spring-cloud-starter-gateway + + + + org.springframework.cloud + spring-cloud-starter-circuitbreaker-reactor-resilience4j + + + + org.springframework.boot + spring-boot-starter-data-redis-reactive + + + + it.ozimov + embedded-redis + ${redis.version} + test + + + org.hibernate + hibernate-validator-cdi + ${hibernate-validator.version} + + + javax.validation + validation-api + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-devtools + + + + org.springframework.boot + spring-boot-starter-oauth2-resource-server + + + org.springframework.boot + spring-boot-starter-oauth2-client + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + + + quotes-application + + + + org.springframework.boot + spring-boot-maven-plugin + + com.baeldung.springcloudgateway.oauth.backend.QuotesApplication + + + + + + + gateway-as-resource-server + + + + org.springframework.boot + spring-boot-maven-plugin + + com.baeldung.springcloudgateway.oauth.server.ResourceServerGatewayApplication + -Dspring.profiles.active=resource-server + + + + + + + gateway-as-oauth-client + + + + org.springframework.boot + spring-boot-maven-plugin + + com.baeldung.springcloudgateway.oauth.server.ResourceServerGatewayApplication + -Dspring.profiles.active=oauth-client + + + + + + + gateway-url-rewrite + + + + org.springframework.boot + spring-boot-maven-plugin + + com.baeldung.springcloudgateway.rewrite.URLRewriteGatewayApplication + -Dspring.profiles.active=url-rewrite + + + + + + + + + + + 6.0.2.Final + 0.7.2 + 9.19 + + + + \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersGatewayApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersGatewayApplication.java new file mode 100644 index 0000000000..fae25bb7cc --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersGatewayApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.PropertySource; + +@SpringBootApplication +@PropertySource("classpath:customfilters-global-application.properties") +public class CustomFiltersGatewayApplication { + + public static void main(String[] args) { + SpringApplication.run(CustomFiltersGatewayApplication.class, args); + } + +} \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/config/WebClientConfig.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/config/WebClientConfig.java new file mode 100644 index 0000000000..0589d8c321 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/config/WebClientConfig.java @@ -0,0 +1,16 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.reactive.function.client.WebClient; + +@Configuration +public class WebClientConfig { + + @Bean + WebClient client() { + return WebClient.builder() + .build(); + } + +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ChainRequestGatewayFilterFactory.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ChainRequestGatewayFilterFactory.java new file mode 100644 index 0000000000..f53b0a3c93 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ChainRequestGatewayFilterFactory.java @@ -0,0 +1,89 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories; + +import java.util.Arrays; +import java.util.List; +import java.util.Locale.LanguageRange; +import java.util.stream.Collectors; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; + +import reactor.core.publisher.Mono; + +@Component +public class ChainRequestGatewayFilterFactory extends AbstractGatewayFilterFactory { + + final Logger logger = LoggerFactory.getLogger(ChainRequestGatewayFilterFactory.class); + + private final WebClient client; + + public ChainRequestGatewayFilterFactory(WebClient client) { + super(Config.class); + this.client = client; + } + + @Override + public List shortcutFieldOrder() { + return Arrays.asList("languageServiceEndpoint", "defaultLanguage"); + } + + @Override + public GatewayFilter apply(Config config) { + return (exchange, chain) -> { + return client.get() + .uri(config.getLanguageServiceEndpoint()) + .exchange() + .flatMap(response -> { + return (response.statusCode() + .is2xxSuccessful()) ? response.bodyToMono(String.class) : Mono.just(config.getDefaultLanguage()); + }) + .map(LanguageRange::parse) + .map(range -> { + exchange.getRequest() + .mutate() + .headers(h -> h.setAcceptLanguage(range)); + + String allOutgoingRequestLanguages = exchange.getRequest() + .getHeaders() + .getAcceptLanguage() + .stream() + .map(r -> r.getRange()) + .collect(Collectors.joining(",")); + + logger.info("Chain Request output - Request contains Accept-Language header: " + allOutgoingRequestLanguages); + + return exchange; + }) + .flatMap(chain::filter); + + }; + } + + public static class Config { + private String languageServiceEndpoint; + private String defaultLanguage; + + public Config() { + } + + public String getLanguageServiceEndpoint() { + return languageServiceEndpoint; + } + + public void setLanguageServiceEndpoint(String languageServiceEndpoint) { + this.languageServiceEndpoint = languageServiceEndpoint; + } + + public String getDefaultLanguage() { + return defaultLanguage; + } + + public void setDefaultLanguage(String defaultLanguage) { + this.defaultLanguage = defaultLanguage; + } + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/LoggingGatewayFilterFactory.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/LoggingGatewayFilterFactory.java new file mode 100644 index 0000000000..900d36cc02 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/LoggingGatewayFilterFactory.java @@ -0,0 +1,85 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories; + +import java.util.Arrays; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.filter.OrderedGatewayFilter; +import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; +import org.springframework.stereotype.Component; + +import reactor.core.publisher.Mono; + +@Component +public class LoggingGatewayFilterFactory extends AbstractGatewayFilterFactory { + + final Logger logger = LoggerFactory.getLogger(LoggingGatewayFilterFactory.class); + + public static final String BASE_MSG = "baseMessage"; + public static final String PRE_LOGGER = "preLogger"; + public static final String POST_LOGGER = "postLogger"; + + public LoggingGatewayFilterFactory() { + super(Config.class); + } + + @Override + public List shortcutFieldOrder() { + return Arrays.asList(BASE_MSG, PRE_LOGGER, POST_LOGGER); + } + + @Override + public GatewayFilter apply(Config config) { + return new OrderedGatewayFilter((exchange, chain) -> { + if (config.isPreLogger()) + logger.info("Pre GatewayFilter logging: " + config.getBaseMessage()); + return chain.filter(exchange) + .then(Mono.fromRunnable(() -> { + if (config.isPostLogger()) + logger.info("Post GatewayFilter logging: " + config.getBaseMessage()); + })); + }, 1); + } + + public static class Config { + private String baseMessage; + private boolean preLogger; + private boolean postLogger; + + public Config() { + }; + + public Config(String baseMessage, boolean preLogger, boolean postLogger) { + super(); + this.baseMessage = baseMessage; + this.preLogger = preLogger; + this.postLogger = postLogger; + } + + public String getBaseMessage() { + return this.baseMessage; + } + + public boolean isPreLogger() { + return preLogger; + } + + public boolean isPostLogger() { + return postLogger; + } + + public void setBaseMessage(String baseMessage) { + this.baseMessage = baseMessage; + } + + public void setPreLogger(boolean preLogger) { + this.preLogger = preLogger; + } + + public void setPostLogger(boolean postLogger) { + this.postLogger = postLogger; + } + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyRequestGatewayFilterFactory.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyRequestGatewayFilterFactory.java new file mode 100644 index 0000000000..5828f35a36 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyRequestGatewayFilterFactory.java @@ -0,0 +1,92 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.Optional; +import java.util.stream.Collectors; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; +import org.springframework.stereotype.Component; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.util.UriComponentsBuilder; + +@Component +public class ModifyRequestGatewayFilterFactory extends AbstractGatewayFilterFactory { + + final Logger logger = LoggerFactory.getLogger(ModifyRequestGatewayFilterFactory.class); + + public ModifyRequestGatewayFilterFactory() { + super(Config.class); + } + + @Override + public List shortcutFieldOrder() { + return Arrays.asList("defaultLocale"); + } + + @Override + public GatewayFilter apply(Config config) { + return (exchange, chain) -> { + if (exchange.getRequest() + .getHeaders() + .getAcceptLanguage() + .isEmpty()) { + + String queryParamLocale = exchange.getRequest() + .getQueryParams() + .getFirst("locale"); + + Locale requestLocale = Optional.ofNullable(queryParamLocale) + .map(l -> Locale.forLanguageTag(l)) + .orElse(config.getDefaultLocale()); + + exchange.getRequest() + .mutate() + .headers(h -> h.setAcceptLanguageAsLocales(Collections.singletonList(requestLocale))); + } + + String allOutgoingRequestLanguages = exchange.getRequest() + .getHeaders() + .getAcceptLanguage() + .stream() + .map(range -> range.getRange()) + .collect(Collectors.joining(",")); + + logger.info("Modify request output - Request contains Accept-Language header: {}", allOutgoingRequestLanguages); + + ServerWebExchange modifiedExchange = exchange.mutate() + .request(originalRequest -> originalRequest.uri(UriComponentsBuilder.fromUri(exchange.getRequest() + .getURI()) + .replaceQueryParams(new LinkedMultiValueMap()) + .build() + .toUri())) + .build(); + + logger.info("Removed all query params: {}", modifiedExchange.getRequest() + .getURI()); + + return chain.filter(modifiedExchange); + }; + } + + public static class Config { + private Locale defaultLocale; + + public Config() { + } + + public Locale getDefaultLocale() { + return defaultLocale; + } + + public void setDefaultLocale(String defaultLocale) { + this.defaultLocale = Locale.forLanguageTag(defaultLocale); + }; + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyResponseGatewayFilterFactory.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyResponseGatewayFilterFactory.java new file mode 100644 index 0000000000..f5efa69402 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyResponseGatewayFilterFactory.java @@ -0,0 +1,48 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories; + +import java.util.Optional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; +import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.stereotype.Component; + +import reactor.core.publisher.Mono; + +@Component +public class ModifyResponseGatewayFilterFactory extends AbstractGatewayFilterFactory { + + final Logger logger = LoggerFactory.getLogger(ModifyResponseGatewayFilterFactory.class); + + public ModifyResponseGatewayFilterFactory() { + super(Config.class); + } + + @Override + public GatewayFilter apply(Config config) { + return (exchange, chain) -> { + return chain.filter(exchange) + .then(Mono.fromRunnable(() -> { + ServerHttpResponse response = exchange.getResponse(); + + Optional.ofNullable(exchange.getRequest() + .getQueryParams() + .getFirst("locale")) + .ifPresent(qp -> { + String responseContentLanguage = response.getHeaders() + .getContentLanguage() + .getLanguage(); + + response.getHeaders() + .add("Bael-Custom-Language-Header", responseContentLanguage); + logger.info("Added custom header to Response"); + }); + })); + }; + } + + public static class Config { + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactory.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactory.java new file mode 100644 index 0000000000..dbe9a9fb4f --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactory.java @@ -0,0 +1,110 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories; + +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +import org.reactivestreams.Publisher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; +import org.springframework.cloud.gateway.filter.factory.rewrite.ModifyResponseBodyGatewayFilterFactory; +import org.springframework.cloud.gateway.filter.factory.rewrite.RewriteFunction; +import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; + +import com.fasterxml.jackson.core.TreeNode; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.node.TextNode; + +import reactor.core.publisher.Mono; + +@Component +public class ScrubResponseGatewayFilterFactory extends AbstractGatewayFilterFactory { + + final Logger logger = LoggerFactory.getLogger(ScrubResponseGatewayFilterFactory.class); + private ModifyResponseBodyGatewayFilterFactory modifyResponseBodyFilterFactory; + + public ScrubResponseGatewayFilterFactory(ModifyResponseBodyGatewayFilterFactory modifyResponseBodyFilterFactory) { + super(Config.class); + this.modifyResponseBodyFilterFactory = modifyResponseBodyFilterFactory; + } + + @Override + public List shortcutFieldOrder() { + return Arrays.asList("fields", "replacement"); + } + + + @Override + public GatewayFilter apply(Config config) { + + return modifyResponseBodyFilterFactory + .apply(c -> c.setRewriteFunction(JsonNode.class, JsonNode.class, new Scrubber(config))); + } + + public static class Config { + + private String fields; + private String replacement; + + + public String getFields() { + return fields; + } + public void setFields(String fields) { + this.fields = fields; + } + public String getReplacement() { + return replacement; + } + public void setReplacement(String replacement) { + this.replacement = replacement; + } + } + + + public static class Scrubber implements RewriteFunction { + private final Pattern fields; + private final String replacement; + + public Scrubber(Config config) { + this.fields = Pattern.compile(config.getFields()); + this.replacement = config.getReplacement(); + } + + @Override + public Publisher apply(ServerWebExchange t, JsonNode u) { + return Mono.just(scrubRecursively(u)); + } + + private JsonNode scrubRecursively(JsonNode u) { + if ( !u.isContainerNode()) { + return u; + } + + if ( u.isObject()) { + ObjectNode node = (ObjectNode)u; + node.fields().forEachRemaining((f) -> { + if ( fields.matcher(f.getKey()).matches() && f.getValue().isTextual()) { + f.setValue(TextNode.valueOf(replacement)); + } + else { + f.setValue(scrubRecursively(f.getValue())); + } + }); + } + else if ( u.isArray()) { + ArrayNode array = (ArrayNode)u; + for ( int i = 0 ; i < array.size() ; i++ ) { + array.set(i, scrubRecursively(array.get(i))); + } + } + + return u; + } + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/FirstPreLastPostGlobalFilter.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/FirstPreLastPostGlobalFilter.java new file mode 100644 index 0000000000..687f3fe685 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/FirstPreLastPostGlobalFilter.java @@ -0,0 +1,31 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.global; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.core.Ordered; +import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; + +import reactor.core.publisher.Mono; + +@Component +public class FirstPreLastPostGlobalFilter implements GlobalFilter, Ordered { + + final Logger logger = LoggerFactory.getLogger(FirstPreLastPostGlobalFilter.class); + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + logger.info("First Pre Global Filter"); + return chain.filter(exchange) + .then(Mono.fromRunnable(() -> { + logger.info("Last Post Global Filter"); + })); + } + + @Override + public int getOrder() { + return -1; + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFilterProperties.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFilterProperties.java new file mode 100644 index 0000000000..4bf6453355 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFilterProperties.java @@ -0,0 +1,47 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.global; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("logging.global") +public class LoggingGlobalFilterProperties { + + private boolean enabled; + private boolean requestHeaders; + private boolean requestBody; + private boolean responseHeaders; + private boolean responseBody; + + public boolean isEnabled() { + return enabled; + } + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + public boolean isRequestHeaders() { + return requestHeaders; + } + public void setRequestHeaders(boolean requestHeaders) { + this.requestHeaders = requestHeaders; + } + public boolean isRequestBody() { + return requestBody; + } + public void setRequestBody(boolean requestBody) { + this.requestBody = requestBody; + } + public boolean isResponseHeaders() { + return responseHeaders; + } + public void setResponseHeaders(boolean responseHeaders) { + this.responseHeaders = responseHeaders; + } + public boolean isResponseBody() { + return responseBody; + } + public void setResponseBody(boolean responseBody) { + this.responseBody = responseBody; + } + + + +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFiltersConfigurations.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFiltersConfigurations.java new file mode 100644 index 0000000000..2dead8da3b --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFiltersConfigurations.java @@ -0,0 +1,25 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.global; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import reactor.core.publisher.Mono; + +@Configuration +public class LoggingGlobalFiltersConfigurations { + + final Logger logger = LoggerFactory.getLogger(LoggingGlobalFiltersConfigurations.class); + + @Bean + public GlobalFilter postGlobalFilter() { + return (exchange, chain) -> { + return chain.filter(exchange) + .then(Mono.fromRunnable(() -> { + logger.info("Global Post Filter executed"); + })); + }; + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalPreFilter.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalPreFilter.java new file mode 100644 index 0000000000..2bacf033db --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalPreFilter.java @@ -0,0 +1,22 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.global; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; + +import reactor.core.publisher.Mono; + +@Component +public class LoggingGlobalPreFilter implements GlobalFilter { + + final Logger logger = LoggerFactory.getLogger(LoggingGlobalPreFilter.class); + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + logger.info("Global Pre Filter executed"); + return chain.filter(exchange); + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/routes/ServiceRouteConfiguration.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/routes/ServiceRouteConfiguration.java new file mode 100644 index 0000000000..17d4827d93 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/routes/ServiceRouteConfiguration.java @@ -0,0 +1,28 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp.routes; + +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; +import org.springframework.context.annotation.Bean; + +import com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories.LoggingGatewayFilterFactory; +import com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories.LoggingGatewayFilterFactory.Config; + +/** + * Note: We want to keep this as an example of configuring a Route with a custom filter + * + * This corresponds with the properties configuration we have + */ +// @Configuration +public class ServiceRouteConfiguration { + + @Bean + public RouteLocator routes(RouteLocatorBuilder builder, LoggingGatewayFilterFactory loggingFactory) { + + return builder.routes() + .route("service_route_java_config", r -> r.path("/service/**") + .filters(f -> f.rewritePath("/service(?/?.*)", "$\\{segment}") + .filter(loggingFactory.apply(new Config("My Custom Message", true, true)))) + .uri("http://localhost:8081")) + .build(); + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceApplication.java new file mode 100644 index 0000000000..b65d0efbd6 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.springcloudgateway.customfilters.secondservice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.PropertySource; + +@SpringBootApplication +@PropertySource("classpath:secondservice-application.properties") +public class SecondServiceApplication { + + public static void main(String[] args) { + SpringApplication.run(SecondServiceApplication.class, args); + } + +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/web/SecondServiceRestController.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/web/SecondServiceRestController.java new file mode 100644 index 0000000000..1ac44ba6b1 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/web/SecondServiceRestController.java @@ -0,0 +1,18 @@ +package com.baeldung.springcloudgateway.customfilters.secondservice.web; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import reactor.core.publisher.Mono; + +@RestController +public class SecondServiceRestController { + + @GetMapping("/resource/language") + public Mono> getResource() { + return Mono.just(ResponseEntity.ok() + .body("es")); + + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/ServiceApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/ServiceApplication.java new file mode 100644 index 0000000000..1e2ffb63c2 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/ServiceApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.springcloudgateway.customfilters.service; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.PropertySource; + +@SpringBootApplication +@PropertySource("classpath:service-application.properties") +public class ServiceApplication { + + public static void main(String[] args) { + SpringApplication.run(ServiceApplication.class, args); + } + +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/web/ServiceRestController.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/web/ServiceRestController.java new file mode 100644 index 0000000000..3ca09f6853 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/web/ServiceRestController.java @@ -0,0 +1,22 @@ +package com.baeldung.springcloudgateway.customfilters.service.web; + +import java.util.Locale; + +import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import reactor.core.publisher.Mono; + +@RestController +public class ServiceRestController { + + @GetMapping("/resource") + public Mono> getResource() { + return Mono.just(ResponseEntity.ok() + .header(HttpHeaders.CONTENT_LANGUAGE, Locale.ENGLISH.getLanguage()) + .body("Service Resource")); + + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/CustomPredicatesApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/CustomPredicatesApplication.java new file mode 100644 index 0000000000..e209b6cdf0 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/CustomPredicatesApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.springcloudgateway.custompredicates; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; + +@SpringBootApplication +public class CustomPredicatesApplication { + + public static void main(String[] args) { + new SpringApplicationBuilder(CustomPredicatesApplication.class) + .profiles("customroutes") + .run(args); + } + +} \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/config/CustomPredicatesConfig.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/config/CustomPredicatesConfig.java new file mode 100644 index 0000000000..ea58eb7e46 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/config/CustomPredicatesConfig.java @@ -0,0 +1,43 @@ +package com.baeldung.springcloudgateway.custompredicates.config; + +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.baeldung.springcloudgateway.custompredicates.factories.GoldenCustomerRoutePredicateFactory; +import com.baeldung.springcloudgateway.custompredicates.factories.GoldenCustomerRoutePredicateFactory.Config; +import com.baeldung.springcloudgateway.custompredicates.service.GoldenCustomerService; + +@Configuration +public class CustomPredicatesConfig { + + + @Bean + public GoldenCustomerRoutePredicateFactory goldenCustomer(GoldenCustomerService goldenCustomerService) { + return new GoldenCustomerRoutePredicateFactory(goldenCustomerService); + } + + + //@Bean + public RouteLocator routes(RouteLocatorBuilder builder, GoldenCustomerRoutePredicateFactory gf ) { + + return builder.routes() + .route("dsl_golden_route", r -> + r.predicate(gf.apply(new Config(true, "customerId"))) + .and() + .path("/dsl_api/**") + .filters(f -> f.stripPrefix(1)) + .uri("https://httpbin.org") + ) + .route("dsl_common_route", r -> + r.predicate(gf.apply(new Config(false, "customerId"))) + .and() + .path("/dsl_api/**") + .filters(f -> f.stripPrefix(1)) + .uri("https://httpbin.org") + ) + .build(); + } + +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/factories/GoldenCustomerRoutePredicateFactory.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/factories/GoldenCustomerRoutePredicateFactory.java new file mode 100644 index 0000000000..cb5c3a0b50 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/factories/GoldenCustomerRoutePredicateFactory.java @@ -0,0 +1,102 @@ +/** + * + */ +package com.baeldung.springcloudgateway.custompredicates.factories; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; + +import javax.validation.constraints.NotEmpty; + +import org.springframework.cloud.gateway.handler.predicate.AbstractRoutePredicateFactory; +import org.springframework.http.HttpCookie; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.server.ServerWebExchange; + +import com.baeldung.springcloudgateway.custompredicates.service.GoldenCustomerService; + +/** + * @author Philippe + * + */ +public class GoldenCustomerRoutePredicateFactory extends AbstractRoutePredicateFactory { + + private final GoldenCustomerService goldenCustomerService; + + public GoldenCustomerRoutePredicateFactory(GoldenCustomerService goldenCustomerService ) { + super(Config.class); + this.goldenCustomerService = goldenCustomerService; + } + + + @Override + public List shortcutFieldOrder() { + return Arrays.asList("isGolden","customerIdCookie"); + } + + + @Override + public Predicate apply(Config config) { + + return (ServerWebExchange t) -> { + List cookies = t.getRequest() + .getCookies() + .get(config.getCustomerIdCookie()); + + boolean isGolden; + if ( cookies == null || cookies.isEmpty()) { + isGolden = false; + } + else { + String customerId = cookies.get(0).getValue(); + isGolden = goldenCustomerService.isGoldenCustomer(customerId); + } + + return config.isGolden()?isGolden:!isGolden; + }; + } + + + @Validated + public static class Config { + boolean isGolden = true; + + @NotEmpty + String customerIdCookie = "customerId"; + + + public Config() {} + + public Config( boolean isGolden, String customerIdCookie) { + this.isGolden = isGolden; + this.customerIdCookie = customerIdCookie; + } + + public boolean isGolden() { + return isGolden; + } + + public void setGolden(boolean value) { + this.isGolden = value; + } + + /** + * @return the customerIdCookie + */ + public String getCustomerIdCookie() { + return customerIdCookie; + } + + /** + * @param customerIdCookie the customerIdCookie to set + */ + public void setCustomerIdCookie(String customerIdCookie) { + this.customerIdCookie = customerIdCookie; + } + + + + } + +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/service/GoldenCustomerService.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/service/GoldenCustomerService.java new file mode 100644 index 0000000000..82bf2e6ae9 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/custompredicates/service/GoldenCustomerService.java @@ -0,0 +1,26 @@ +/** + * + */ +package com.baeldung.springcloudgateway.custompredicates.service; + +import org.springframework.stereotype.Component; + +/** + * @author Philippe + * + */ +@Component +public class GoldenCustomerService { + + public boolean isGoldenCustomer(String customerId) { + + // TODO: Add some AI logic to check is this customer deserves a "golden" status ;^) + if ( "baeldung".equalsIgnoreCase(customerId)) { + return true; + } + else { + return false; + } + } + +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/introduction/IntroductionGatewayApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/introduction/IntroductionGatewayApplication.java new file mode 100644 index 0000000000..d276597a6b --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/introduction/IntroductionGatewayApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.springcloudgateway.introduction; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.PropertySource; + +@SpringBootApplication +@PropertySource("classpath:introduction-application.properties") +public class IntroductionGatewayApplication { + + public static void main(String[] args) { + SpringApplication.run(IntroductionGatewayApplication.class, args); + } + +} \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/QuotesApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/QuotesApplication.java new file mode 100644 index 0000000000..96daf8a73d --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/QuotesApplication.java @@ -0,0 +1,44 @@ +/** + * + */ +package com.baeldung.springcloudgateway.oauth.backend; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.PropertySource; +import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; +import org.springframework.security.oauth2.server.resource.introspection.NimbusReactiveOpaqueTokenIntrospector; +import org.springframework.security.oauth2.server.resource.introspection.ReactiveOpaqueTokenIntrospector; + +import com.baeldung.springcloudgateway.oauth.shared.KeycloakReactiveTokenInstrospector; + +/** + * @author Philippe + * + */ +@SpringBootApplication +@PropertySource("classpath:quotes-application.properties") +@EnableWebFluxSecurity +public class QuotesApplication { + + public static void main(String[] args) { + SpringApplication.run(QuotesApplication.class); + } + + + @Bean + public ReactiveOpaqueTokenIntrospector keycloakIntrospector(OAuth2ResourceServerProperties props) { + + NimbusReactiveOpaqueTokenIntrospector delegate = new NimbusReactiveOpaqueTokenIntrospector( + props.getOpaquetoken().getIntrospectionUri(), + props.getOpaquetoken().getClientId(), + props.getOpaquetoken().getClientSecret()); + + return new KeycloakReactiveTokenInstrospector(delegate); + } + + +} + diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/domain/Quote.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/domain/Quote.java new file mode 100644 index 0000000000..042cfa63fa --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/domain/Quote.java @@ -0,0 +1,35 @@ +package com.baeldung.springcloudgateway.oauth.backend.domain; + + +public class Quote { + + private String symbol; + private double price; + + /** + * @return the symbol + */ + public String getSymbol() { + return symbol; + } + /** + * @param symbol the symbol to set + */ + public void setSymbol(String symbol) { + this.symbol = symbol; + } + /** + * @return the price + */ + public double getPrice() { + return price; + } + /** + * @param price the price to set + */ + public void setPrice(double price) { + this.price = price; + } + + +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/web/QuoteApi.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/web/QuoteApi.java new file mode 100644 index 0000000000..6d3721166c --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/web/QuoteApi.java @@ -0,0 +1,34 @@ +package com.baeldung.springcloudgateway.oauth.backend.web; + +import javax.annotation.PostConstruct; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.springcloudgateway.oauth.backend.domain.Quote; + +import reactor.core.publisher.Mono; + +@RestController +public class QuoteApi { + private static final GrantedAuthority GOLD_CUSTOMER = new SimpleGrantedAuthority("gold"); + + @GetMapping("/quotes/{symbol}") + public Mono getQuote(@PathVariable("symbol") String symbol, BearerTokenAuthentication auth ) { + + Quote q = new Quote(); + q.setSymbol(symbol); + + if ( auth.getAuthorities().contains(GOLD_CUSTOMER)) { + q.setPrice(10.0); + } + else { + q.setPrice(12.0); + } + return Mono.just(q); + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/server/ResourceServerGatewayApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/server/ResourceServerGatewayApplication.java new file mode 100644 index 0000000000..1b85867f3b --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/server/ResourceServerGatewayApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.springcloudgateway.oauth.server; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; + +@SpringBootApplication +@EnableWebFluxSecurity +public class ResourceServerGatewayApplication { + public static void main(String[] args) { + SpringApplication.run(ResourceServerGatewayApplication.class,args); + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/shared/KeycloakReactiveTokenInstrospector.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/shared/KeycloakReactiveTokenInstrospector.java new file mode 100644 index 0000000000..e834e6934d --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/shared/KeycloakReactiveTokenInstrospector.java @@ -0,0 +1,65 @@ +/** + * + */ +package com.baeldung.springcloudgateway.oauth.shared; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal; +import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal; +import org.springframework.security.oauth2.server.resource.introspection.ReactiveOpaqueTokenIntrospector; + +import reactor.core.publisher.Mono; + +/** + * Custom ReactiveTokenIntrospector to map realm roles into Spring GrantedAuthorities + * + */ +public class KeycloakReactiveTokenInstrospector implements ReactiveOpaqueTokenIntrospector { + + private final ReactiveOpaqueTokenIntrospector delegate; + + public KeycloakReactiveTokenInstrospector(ReactiveOpaqueTokenIntrospector delegate) { + this.delegate = delegate; + } + + @Override + public Mono introspect(String token) { + + return delegate.introspect(token) + .map( this::mapPrincipal); + } + + protected OAuth2AuthenticatedPrincipal mapPrincipal(OAuth2AuthenticatedPrincipal principal) { + + return new DefaultOAuth2AuthenticatedPrincipal( + principal.getName(), + principal.getAttributes(), + extractAuthorities(principal)); + } + + protected Collection extractAuthorities(OAuth2AuthenticatedPrincipal principal) { + + // + Map> realm_access = principal.getAttribute("realm_access"); + List roles = realm_access.getOrDefault("roles", Collections.emptyList()); + List rolesAuthorities = roles.stream() + .map(SimpleGrantedAuthority::new) + .collect(Collectors.toList()); + + Set allAuthorities = new HashSet<>(); + allAuthorities.addAll(principal.getAuthorities()); + allAuthorities.addAll(rolesAuthorities); + + return allAuthorities; + } + +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplication.java new file mode 100644 index 0000000000..46541b4826 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplication.java @@ -0,0 +1,25 @@ +/** + * + */ +package com.baeldung.springcloudgateway.rewrite; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.cloud.gateway.filter.GatewayFilter; + +import reactor.core.publisher.Mono; + +/** + * @author Baeldung + * + */ +@SpringBootApplication +public class URLRewriteGatewayApplication { + + public static void main(String[] args) { + new SpringApplicationBuilder(URLRewriteGatewayApplication.class) + .profiles("url-rewrite") + .run(args); + } + +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/routes/DynamicRewriteRoute.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/routes/DynamicRewriteRoute.java new file mode 100644 index 0000000000..29d40d7021 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/routes/DynamicRewriteRoute.java @@ -0,0 +1,43 @@ +package com.baeldung.springcloudgateway.rewrite.routes; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.http.server.reactive.ServerHttpRequest; + +import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR; +import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.addOriginalRequestUrl; + +import java.util.Random; + +@Configuration +@Profile("url-rewrite") +public class DynamicRewriteRoute { + + @Value("${rewrite.backend.uri}") + private String backendUri; + private static Random rnd = new Random(); + + @Bean + public RouteLocator dynamicZipCodeRoute(RouteLocatorBuilder builder) { + return builder.routes() + .route("dynamicRewrite", r -> + r.path("/v2/zip/**") + .filters(f -> f.filter((exchange, chain) -> { + ServerHttpRequest req = exchange.getRequest(); + addOriginalRequestUrl(exchange, req.getURI()); + String path = req.getURI().getRawPath(); + String newPath = path.replaceAll( + "/v2/zip/(?.*)", + "/api/zip/${zipcode}-" + String.format("%03d", rnd.nextInt(1000))); + ServerHttpRequest request = req.mutate().path(newPath).build(); + exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, request.getURI()); + return chain.filter(exchange.mutate().request(request).build()); + })) + .uri(backendUri)) + .build(); + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/WebFilterGatewayApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/WebFilterGatewayApplication.java new file mode 100644 index 0000000000..9e212cc4bf --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/WebFilterGatewayApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.springcloudgateway.webfilters; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; + +@SpringBootApplication +public class WebFilterGatewayApplication { + + public static void main(String[] args) { + new SpringApplicationBuilder(WebFilterGatewayApplication.class) + .profiles("url-rewrite") + .run(args); + } + +} \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/ModifyBodyRouteConfig.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/ModifyBodyRouteConfig.java new file mode 100644 index 0000000000..7b6188b66a --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/ModifyBodyRouteConfig.java @@ -0,0 +1,49 @@ +package com.baeldung.springcloudgateway.webfilters.config; + +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; + +import reactor.core.publisher.Mono; + +@Configuration +public class ModifyBodyRouteConfig { + + @Bean + public RouteLocator routes(RouteLocatorBuilder builder) { + return builder.routes() + .route("modify_request_body", r -> r.path("/post") + .filters(f -> f.modifyRequestBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE, + (exchange, s) -> Mono.just(new Hello(s.toUpperCase())))).uri("https://httpbin.org")) + .build(); + } + + @Bean + public RouteLocator responseRoutes(RouteLocatorBuilder builder) { + return builder.routes() + .route("modify_response_body", r -> r.path("/put/**") + .filters(f -> f.modifyResponseBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE, + (exchange, s) -> Mono.just(new Hello("New Body")))).uri("https://httpbin.org")) + .build(); + } + + static class Hello { + String message; + + public Hello() { } + + public Hello(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/RequestRateLimiterResolverConfig.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/RequestRateLimiterResolverConfig.java new file mode 100644 index 0000000000..f80a742fa6 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/RequestRateLimiterResolverConfig.java @@ -0,0 +1,16 @@ +package com.baeldung.springcloudgateway.webfilters.config; + +import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import reactor.core.publisher.Mono; + +@Configuration +public class RequestRateLimiterResolverConfig { + + @Bean + KeyResolver userKeyResolver() { + return exchange -> Mono.just("1"); + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-customroutes.yml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-customroutes.yml new file mode 100644 index 0000000000..859aa60bda --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-customroutes.yml @@ -0,0 +1,26 @@ +spring: + cloud: + gateway: + routes: + - id: golden_route + uri: https://httpbin.org + predicates: + - Path=/api/** + - GoldenCustomer=true + filters: + - StripPrefix=1 + - AddRequestHeader=GoldenCustomer,true + - id: common_route + uri: https://httpbin.org + predicates: + - Path=/api/** + - name: GoldenCustomer + args: + golden: false + customerIdCookie: customerId + filters: + - StripPrefix=1 + - AddRequestHeader=GoldenCustomer,false + + + \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-nosecurity.yml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-nosecurity.yml new file mode 100644 index 0000000000..40a52ded0f --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-nosecurity.yml @@ -0,0 +1,8 @@ +# Enable this profile to disable security +spring: + autoconfigure: + exclude: + - org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration + - org.springframework.boot.actuate.autoconfigure.ManagementSecurityAutoConfiguration + - org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration + - org.springframework.boot.actuate.autoconfigure.security.reactive.ReactiveManagementWebSecurityAutoConfiguration \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-oauth-client.yml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-oauth-client.yml new file mode 100644 index 0000000000..b097c54eb1 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-oauth-client.yml @@ -0,0 +1,26 @@ +server: + port: 8087 +spring: + cloud: + gateway: + redis: + enabled: false + routes: + - id: quotes + uri: http://localhost:8085 + predicates: + - Path=/quotes/** + filters: - TokenRelay= + security: + oauth2: + client: provider: keycloak: + issuer-uri: http://localhost:8083/auth/realms/baeldung + registration: quotes-client: + provider: keycloak + client-id: quotes-client + client-secret: 0e082231-a70d-48e8-b8a5-fbfb743041b6 + scope: - email + - profile + - roles + + \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-resource-server.yml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-resource-server.yml new file mode 100644 index 0000000000..14f713a04a --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-resource-server.yml @@ -0,0 +1,19 @@ +server: + port: 8086 +spring: + security: + oauth2: + resourceserver: + opaquetoken: + introspection-uri: http://localhost:8083/auth/realms/baeldung/protocol/openid-connect/token/introspect + client-id: quotes-client + client-secret: 0e082231-a70d-48e8-b8a5-fbfb743041b6 + cloud: + gateway: + redis: + enabled: false + routes: + - id: quotes + uri: http://localhost:8085 + predicates: + - Path=/quotes/** diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-scrub.yml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-scrub.yml new file mode 100644 index 0000000000..da7dfea0a7 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-scrub.yml @@ -0,0 +1,12 @@ +spring: + cloud: + gateway: + routes: + - id: rewrite_with_scrub + uri: ${rewrite.backend.uri:http://example.com} + predicates: + - Path=/v1/customer/** + filters: + - RewritePath=/v1/customer/(?.*),/api/$\{segment} + - ScrubResponse=ssn,*** + \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-url-rewrite.yml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-url-rewrite.yml new file mode 100644 index 0000000000..b2656151db --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-url-rewrite.yml @@ -0,0 +1,11 @@ +spring: + cloud: + gateway: + routes: + - id: rewrite_v1 + uri: ${rewrite.backend.uri:http://example.com} + predicates: + - Path=/v1/customer/** + filters: + - RewritePath=/v1/customer/(?.*),/api/$\{segment} + \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-webfilters.yml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-webfilters.yml new file mode 100644 index 0000000000..3348cbbba0 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-webfilters.yml @@ -0,0 +1,102 @@ +logging: + level: + org.springframework.cloud.gateway: INFO + reactor.netty.http.client: INFO + +spring: + redis: + host: localhost + port: 6379 + cloud: + gateway: + routes: + - id: request_header_route + uri: https://httpbin.org + predicates: + - Path=/get/** + filters: + - AddRequestHeader=My-Header-Good,Good + - AddRequestHeader=My-Header-Remove,Remove + - AddRequestParameter=var, good + - AddRequestParameter=var2, remove + - MapRequestHeader=My-Header-Good, My-Header-Bad + - MapRequestHeader=My-Header-Set, My-Header-Bad + - SetRequestHeader=My-Header-Set, Set + - RemoveRequestHeader=My-Header-Remove + - RemoveRequestParameter=var2 + - PreserveHostHeader + + - id: response_header_route + uri: https://httpbin.org + predicates: + - Path=/header/post/** + filters: + - AddResponseHeader=My-Header-Good,Good + - AddResponseHeader=My-Header-Set,Good + - AddResponseHeader=My-Header-Rewrite, password=12345678 + - DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin + - AddResponseHeader=My-Header-Remove,Remove + - SetResponseHeader=My-Header-Set, Set + - RemoveResponseHeader=My-Header-Remove + - RewriteResponseHeader=My-Header-Rewrite, password=[^&]+, password=*** + - RewriteLocationResponseHeader=AS_IN_REQUEST, Location, , + - StripPrefix=1 + + - id: path_route + uri: https://httpbin.org + predicates: + - Path=/new/post/** + filters: + - RewritePath=/new(?/?.*), $\{segment} + - SetPath=/post + + - id: redirect_route + uri: https://httpbin.org + predicates: + - Path=/fake/post/** + filters: + - RedirectTo=302, https://httpbin.org + + - id: status_route + uri: https://httpbin.org + predicates: + - Path=/delete/** + filters: + - SetStatus=401 + + - id: size_route + uri: https://httpbin.org + predicates: + - Path=/anything + filters: + - name: RequestSize + args: + maxSize: 5000000 + + - id: retry_test + uri: https://httpbin.org + predicates: + - Path=/status/502 + filters: + - name: Retry + args: + retries: 3 + statuses: BAD_GATEWAY + methods: GET,POST + backoff: + firstBackoff: 10ms + maxBackoff: 50ms + factor: 2 + basedOnPreviousValue: false + + - id: request_rate_limiter + uri: https://httpbin.org + predicates: + - Path=/redis/get/** + filters: + - StripPrefix=1 + - name: RequestRateLimiter + args: + redis-rate-limiter.replenishRate: 10 + redis-rate-limiter.burstCapacity: 5 + key-resolver: "#{@userKeyResolver}" \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application.yml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application.yml new file mode 100644 index 0000000000..a33bca2055 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application.yml @@ -0,0 +1,4 @@ +logging: + level: + org.springframework.cloud.gateway: DEBUG + reactor.netty.http.client: DEBUG diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/customfilters-global-application.properties b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/customfilters-global-application.properties new file mode 100644 index 0000000000..08421a0653 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/customfilters-global-application.properties @@ -0,0 +1,19 @@ +spring.cloud.gateway.routes[0].id=service_route +spring.cloud.gateway.routes[0].uri=http://localhost:8081 +spring.cloud.gateway.routes[0].predicates[0]=Path=/service/** +spring.cloud.gateway.routes[0].filters[0]=RewritePath=/service(?/?.*), $\{segment} +spring.cloud.gateway.routes[0].filters[1]=Logging=My Custom Message, true, true +# Or, as an alternative: +#spring.cloud.gateway.routes[0].filters[1].name=Logging +#spring.cloud.gateway.routes[0].filters[1].args[baseMessage]=My Custom Message +#spring.cloud.gateway.routes[0].filters[1].args[preLogger]=true +#spring.cloud.gateway.routes[0].filters[1].args[postLogger]=true + +spring.cloud.gateway.routes[0].filters[2]=ModifyResponse +spring.cloud.gateway.routes[0].filters[3]=ModifyRequest=en +spring.cloud.gateway.routes[0].filters[4]=ChainRequest=http://localhost:8082/resource/language, fr + +management.endpoints.web.exposure.include=* + +server.port=80 + diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/introduction-application.properties b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/introduction-application.properties new file mode 100644 index 0000000000..d7a6c4e072 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/introduction-application.properties @@ -0,0 +1,7 @@ +spring.cloud.gateway.routes[0].id=baeldung_route +spring.cloud.gateway.routes[0].uri=http://www.baeldung.com +spring.cloud.gateway.routes[0].predicates[0]=Path=/baeldung + +management.endpoints.web.exposure.include=* + +server.port=80 diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/logback.xml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/quotes-application.properties b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/quotes-application.properties new file mode 100644 index 0000000000..48e8999b1b --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/quotes-application.properties @@ -0,0 +1,12 @@ +server.port=8085 +# Disable gateway & redis as we don't need them in this application +spring.cloud.gateway.enabled=false +spring.cloud.gateway.redis.enabled=false + +# Resource server settings +spring.security.oauth2.resourceserver.opaquetoken.introspection-uri=http://localhost:8083/auth/realms/baeldung/protocol/openid-connect/token/introspect +spring.security.oauth2.resourceserver.opaquetoken.client-id=quotes-client +spring.security.oauth2.resourceserver.opaquetoken.client-secret=0e082231-a70d-48e8-b8a5-fbfb743041b6 + + + diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/secondservice-application.properties b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/secondservice-application.properties new file mode 100644 index 0000000000..3cf12afeb9 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/secondservice-application.properties @@ -0,0 +1 @@ +server.port=8082 diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/service-application.properties b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/service-application.properties new file mode 100644 index 0000000000..4d360de145 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/service-application.properties @@ -0,0 +1 @@ +server.port=8081 diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersLiveTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersLiveTest.java new file mode 100644 index 0000000000..f49f8c68b6 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersLiveTest.java @@ -0,0 +1,112 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.assertj.core.api.Condition; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.test.web.reactive.server.WebTestClient; +import org.springframework.test.web.reactive.server.WebTestClient.ResponseSpec; + +import com.baeldung.springcloudgateway.customfilters.gatewayapp.utils.LoggerListAppender; + +import ch.qos.logback.classic.spi.ILoggingEvent; + +/** + * This test requires: + * * the service in com.baeldung.service running + * * the 'second service' in com.baeldung.secondservice running + * + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +public class CustomFiltersLiveTest { + + @LocalServerPort + String port; + + @Autowired + private WebTestClient client; + + @BeforeEach + public void clearLogList() { + LoggerListAppender.clearEventList(); + client = WebTestClient.bindToServer() + .baseUrl("http://localhost:" + port) + .build(); + } + + @Test + public void whenCallServiceThroughGateway_thenAllConfiguredFiltersGetExecuted() { + ResponseSpec response = client.get() + .uri("/service/resource") + .exchange(); + + response.expectStatus() + .isOk() + .expectHeader() + .doesNotExist("Bael-Custom-Language-Header") + .expectBody(String.class) + .isEqualTo("Service Resource"); + + assertThat(LoggerListAppender.getEvents()) + // Global Pre Filter + .haveAtLeastOne(eventContains("Global Pre Filter executed")) + // Global Post Filter + .haveAtLeastOne(eventContains("Global Post Filter executed")) + // Global Pre and Post Filter + .haveAtLeastOne(eventContains("First Pre Global Filter")) + .haveAtLeastOne(eventContains("Last Post Global Filter")) + // Logging Filter Factory + .haveAtLeastOne(eventContains("Pre GatewayFilter logging: My Custom Message")) + .haveAtLeastOne(eventContains("Post GatewayFilter logging: My Custom Message")) + // Modify Request + .haveAtLeastOne(eventContains("Modify request output - Request contains Accept-Language header:")) + .haveAtLeastOne(eventContainsExcept("Removed all query params: ", "locale")) + // Modify Response + .areNot(eventContains("Added custom header to Response")) + // Chain Request + .haveAtLeastOne(eventContains("Chain Request output - Request contains Accept-Language header:")); + } + + @Test + public void givenRequestWithLocaleQueryParam_whenCallServiceThroughGateway_thenAllConfiguredFiltersGetExecuted() { + ResponseSpec response = client.get() + .uri("/service/resource?locale=en") + .exchange(); + + response.expectStatus() + .isOk() + .expectHeader() + .exists("Bael-Custom-Language-Header") + .expectBody(String.class) + .isEqualTo("Service Resource"); + + assertThat(LoggerListAppender.getEvents()) + // Modify Response + .haveAtLeastOne(eventContains("Added custom header to Response")) + .haveAtLeastOne(eventContainsExcept("Removed all query params: ", "locale")); + } + + /** + * This condition will be successful if the event contains a substring + */ + private Condition eventContains(String substring) { + return new Condition(entry -> (substring == null || (entry.getFormattedMessage() != null && entry.getFormattedMessage() + .contains(substring))), String.format("entry with message '%s'", substring)); + } + + /** + * This condition will be successful if the event contains a substring, but not another one + */ + private Condition eventContainsExcept(String substring, String except) { + return new Condition(entry -> (substring == null || (entry.getFormattedMessage() != null && entry.getFormattedMessage() + .contains(substring) + && !entry.getFormattedMessage() + .contains(except))), + String.format("entry with message '%s'", substring)); + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactoryUnitTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactoryUnitTest.java new file mode 100644 index 0000000000..667aabaddc --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactoryUnitTest.java @@ -0,0 +1,61 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +import com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories.ScrubResponseGatewayFilterFactory.Config; +import com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories.ScrubResponseGatewayFilterFactory.Scrubber; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.core.TreeNode; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import reactor.core.publisher.Mono; + +class ScrubResponseGatewayFilterFactoryUnitTest { + + private static final String JSON_WITH_FIELDS_TO_SCRUB = "{\r\n" + + " \"name\" : \"John Doe\",\r\n" + + " \"ssn\" : \"123-45-9999\",\r\n" + + " \"account\" : \"9999888877770000\"\r\n" + + "}"; + + + @Test + void givenJsonWithFieldsToScrub_whenApply_thenScrubFields() throws Exception{ + + JsonFactory jf = new JsonFactory(new ObjectMapper()); + JsonParser parser = jf.createParser(JSON_WITH_FIELDS_TO_SCRUB); + JsonNode root = parser.readValueAsTree(); + + Config config = new Config(); + config.setFields("ssn|account"); + config.setReplacement("*"); + Scrubber scrubber = new ScrubResponseGatewayFilterFactory.Scrubber(config); + + JsonNode scrubbed = Mono.from(scrubber.apply(null, root)).block(); + assertNotNull(scrubbed); + assertEquals("*", scrubbed.get("ssn").asText()); + } + + @Test + void givenJsonWithoutFieldsToScrub_whenApply_theBodUnchanged() throws Exception{ + + JsonFactory jf = new JsonFactory(new ObjectMapper()); + JsonParser parser = jf.createParser(JSON_WITH_FIELDS_TO_SCRUB); + JsonNode root = parser.readValueAsTree(); + + Config config = new Config(); + config.setFields("xxxx"); + config.setReplacement("*"); + Scrubber scrubber = new ScrubResponseGatewayFilterFactory.Scrubber(config); + + JsonNode scrubbed = Mono.from(scrubber.apply(null, root)).block(); + assertNotNull(scrubbed); + assertNotEquals("*", scrubbed.get("ssn").asText()); + } + +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterLiveTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterLiveTest.java new file mode 100644 index 0000000000..8906af774e --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterLiveTest.java @@ -0,0 +1,135 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.Collections; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.cloud.gateway.filter.factory.SetPathGatewayFilterFactory; +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Primary; +import org.springframework.http.MediaType; +import org.springframework.http.client.reactive.ReactorClientHttpConnector; +import org.springframework.security.config.web.server.ServerHttpSecurity; +import org.springframework.security.web.server.SecurityWebFilterChain; +import org.springframework.test.web.reactive.server.WebTestClient; + +import com.sun.net.httpserver.HttpServer; + +import reactor.netty.http.client.HttpClient; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +public class ScrubResponseGatewayFilterLiveTest { + + private static Logger log = LoggerFactory.getLogger(ScrubResponseGatewayFilterLiveTest.class); + + private static final String JSON_WITH_FIELDS_TO_SCRUB = "{\r\n" + + " \"name\" : \"John Doe\",\r\n" + + " \"ssn\" : \"123-45-9999\",\r\n" + + " \"account\" : \"9999888877770000\"\r\n" + + "}"; + + private static final String JSON_WITH_SCRUBBED_FIELDS = "{\r\n" + + " \"name\" : \"John Doe\",\r\n" + + " \"ssn\" : \"*\",\r\n" + + " \"account\" : \"9999888877770000\"\r\n" + + "}"; + + @LocalServerPort + String port; + + @Autowired + private WebTestClient client; + + @Autowired HttpServer server; + + @Test + public void givenRequestToScrubRoute_thenResponseScrubbed() { + + client.get() + .uri("/scrub") + .accept(MediaType.APPLICATION_JSON) + .exchange() + .expectStatus() + .is2xxSuccessful() + .expectHeader() + .contentType(MediaType.APPLICATION_JSON) + .expectBody() + .json(JSON_WITH_SCRUBBED_FIELDS); + } + + + @TestConfiguration + public static class TestRoutesConfiguration { + + + @Bean + public RouteLocator scrubSsnRoute(RouteLocatorBuilder builder, ScrubResponseGatewayFilterFactory scrubFilterFactory, SetPathGatewayFilterFactory pathFilterFactory, HttpServer server ) { + + log.info("[I92] Creating scrubSsnRoute..."); + + int mockServerPort = server.getAddress().getPort(); + ScrubResponseGatewayFilterFactory.Config config = new ScrubResponseGatewayFilterFactory.Config(); + config.setFields("ssn"); + config.setReplacement("*"); + + SetPathGatewayFilterFactory.Config pathConfig = new SetPathGatewayFilterFactory.Config(); + pathConfig.setTemplate("/customer"); + + return builder.routes() + .route("scrub_ssn", + r -> r.path("/scrub") + .filters( + f -> f + .filter(scrubFilterFactory.apply(config)) + .filter(pathFilterFactory.apply(pathConfig))) + .uri("http://localhost:" + mockServerPort )) + .build(); + } + + @Bean + public SecurityWebFilterChain testFilterChain(ServerHttpSecurity http ) { + + // @formatter:off + return http.authorizeExchange() + .anyExchange() + .permitAll() + .and() + .build(); + // @formatter:on + } + + @Bean + public HttpServer mockServer() throws IOException { + + log.info("[I48] Starting mock server..."); + + HttpServer server = HttpServer.create(new InetSocketAddress(0),0); + server.createContext("/customer", (exchange) -> { + exchange.getResponseHeaders().set("Content-Type", "application/json"); + + byte[] response = JSON_WITH_FIELDS_TO_SCRUB.getBytes("UTF-8"); + exchange.sendResponseHeaders(200,response.length); + exchange.getResponseBody().write(response); + }); + + server.setExecutor(null); + server.start(); + + log.info("[I65] Mock server started. port={}", server.getAddress().getPort()); + return server; + } + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/utils/LoggerListAppender.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/utils/LoggerListAppender.java new file mode 100644 index 0000000000..8e113b417b --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/utils/LoggerListAppender.java @@ -0,0 +1,25 @@ +package com.baeldung.springcloudgateway.customfilters.gatewayapp.utils; + +import java.util.ArrayList; +import java.util.List; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.AppenderBase; + +public class LoggerListAppender extends AppenderBase { + + static private List events = new ArrayList<>(); + + @Override + protected void append(ILoggingEvent eventObject) { + events.add(eventObject); + } + + public static List getEvents() { + return events; + } + + public static void clearEventList() { + events.clear(); + } +} \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceIntegrationTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceIntegrationTest.java new file mode 100644 index 0000000000..f4b3d0f00d --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceIntegrationTest.java @@ -0,0 +1,28 @@ +package com.baeldung.springcloudgateway.customfilters.secondservice; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration; +import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; +import org.springframework.test.web.reactive.server.WebTestClient; + +import com.baeldung.springcloudgateway.customfilters.secondservice.web.SecondServiceRestController; + +@WebFluxTest(controllers = SecondServiceRestController.class, + excludeAutoConfiguration = ReactiveSecurityAutoConfiguration.class) +public class SecondServiceIntegrationTest { + + @Autowired + private WebTestClient webClient; + + @Test + public void whenResourceLanguageEndpointCalled_thenRetrievesSpanishLanguageString() throws Exception { + this.webClient.get() + .uri("/resource/language") + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("es"); + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SpringContextTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SpringContextTest.java new file mode 100644 index 0000000000..eaf94c0a42 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SpringContextTest.java @@ -0,0 +1,12 @@ +package com.baeldung.springcloudgateway.customfilters.secondservice; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = SecondServiceApplication.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/ServiceIntegrationTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/ServiceIntegrationTest.java new file mode 100644 index 0000000000..9990cd003c --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/ServiceIntegrationTest.java @@ -0,0 +1,31 @@ +package com.baeldung.springcloudgateway.customfilters.service; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration; +import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; +import org.springframework.http.HttpHeaders; +import org.springframework.test.web.reactive.server.WebTestClient; + +import com.baeldung.springcloudgateway.customfilters.service.web.ServiceRestController; + +@WebFluxTest(controllers = ServiceRestController.class, + excludeAutoConfiguration = ReactiveSecurityAutoConfiguration.class) +public class ServiceIntegrationTest { + + @Autowired + private WebTestClient webClient; + + @Test + public void whenResourceEndpointCalled_thenRetrievesResourceStringWithContentLanguageHeader() throws Exception { + this.webClient.get() + .uri("/resource") + .exchange() + .expectStatus() + .isOk() + .expectHeader() + .valueEquals(HttpHeaders.CONTENT_LANGUAGE, "en") + .expectBody(String.class) + .isEqualTo("Service Resource"); + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/SpringContextTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/SpringContextTest.java new file mode 100644 index 0000000000..2a9b322d5e --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/SpringContextTest.java @@ -0,0 +1,12 @@ +package com.baeldung.springcloudgateway.customfilters.service; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = ServiceApplication.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/custompredicates/CustomPredicatesApplicationLiveTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/custompredicates/CustomPredicatesApplicationLiveTest.java new file mode 100644 index 0000000000..d9988ceb5e --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/custompredicates/CustomPredicatesApplicationLiveTest.java @@ -0,0 +1,67 @@ +package com.baeldung.springcloudgateway.custompredicates; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +import java.net.URI; + +import org.json.JSONException; +import org.json.JSONObject; +import org.json.JSONTokener; +import org.junit.Before; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.RequestEntity; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; + +/** + * This test requires + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ActiveProfiles("customroutes") +public class CustomPredicatesApplicationLiveTest { + + @LocalServerPort + String serverPort; + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void givenNormalCustomer_whenCallHeadersApi_thenResponseForNormalCustomer() throws JSONException { + + String url = "http://localhost:" + serverPort + "/api/headers"; + ResponseEntity response = restTemplate.getForEntity(url, String.class); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + + JSONObject json = new JSONObject(response.getBody()); + JSONObject headers = json.getJSONObject("headers"); + assertThat(headers.getString("Goldencustomer")).isEqualTo("false"); + + } + + @Test + void givenGoldenCustomer_whenCallHeadersApi_thenResponseForGoldenCustomer() throws JSONException { + + String url = "http://localhost:" + serverPort + "/api/headers"; + RequestEntity request = RequestEntity + .get(URI.create(url)) + .header("Cookie", "customerId=baeldung") + .build(); + + ResponseEntity response = restTemplate.exchange(request, String.class); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + + JSONObject json = new JSONObject(response.getBody()); + JSONObject headers = json.getJSONObject("headers"); + assertThat(headers.getString("Goldencustomer")).isEqualTo("true"); + + } + +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/introduction/SpringContextTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/introduction/SpringContextTest.java new file mode 100644 index 0000000000..1550265f22 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/introduction/SpringContextTest.java @@ -0,0 +1,15 @@ +package com.baeldung.springcloudgateway.introduction; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import com.baeldung.springcloudgateway.introduction.IntroductionGatewayApplication; + + +@SpringBootTest(classes = IntroductionGatewayApplication.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplicationLiveTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplicationLiveTest.java new file mode 100644 index 0000000000..41fe37045c --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplicationLiveTest.java @@ -0,0 +1,109 @@ +package com.baeldung.springcloudgateway.rewrite; + +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.OutputStream; +import java.net.InetSocketAddress; + +import org.junit.AfterClass; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.springframework.test.web.reactive.server.WebTestClient; + +import com.sun.net.httpserver.HttpServer; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ActiveProfiles({ "nosecurity", "url-rewrite" }) +class URLRewriteGatewayApplicationLiveTest { + + // NOTE for Eclipse users: By default, Eclipse will complain about com.sun.** classes. + // To solve this issue, follow instructions available at the : + // https://stackoverflow.com/questions/13155734/eclipse-cant-recognize-com-sun-net-httpserver-httpserver-package + private static HttpServer mockServer; + private static Logger log = LoggerFactory.getLogger(URLRewriteGatewayApplicationLiveTest.class); + + // Create a running HttpServer that echoes back the request URL. + private static HttpServer startTestServer() { + + try { + log.info("[I26] Starting mock server"); + mockServer = HttpServer.create(); + mockServer.bind(new InetSocketAddress(0), 0); + mockServer.createContext("/api", (xchg) -> { + String uri = xchg.getRequestURI() + .toString(); + log.info("[I23] Backend called: uri={}", uri); + xchg.getResponseHeaders() + .add("Content-Type", "text/plain"); + xchg.sendResponseHeaders(200, 0); + OutputStream os = xchg.getResponseBody(); + os.write(uri.getBytes()); + os.flush(); + os.close(); + }); + + mockServer.start(); + InetSocketAddress localAddr = mockServer.getAddress(); + log.info("[I36] mock server started: local address={}", localAddr); + + return mockServer; + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + // TIP: https://www.baeldung.com/spring-dynamicpropertysource + @DynamicPropertySource + static void registerBackendServer(DynamicPropertyRegistry registry) { + registry.add("rewrite.backend.uri", () -> { + HttpServer s = startTestServer(); + return "http://localhost:" + s.getAddress().getPort(); + }); + } + + @AfterClass + public static void stopMockBackend() throws Exception { + log.info("[I40] Shutdown mock http server"); + mockServer.stop(5); + } + + @LocalServerPort + private int localPort; + + @Test + void testWhenApiCall_thenRewriteSuccess(@Autowired WebTestClient webClient) { + webClient.get() + .uri("http://localhost:" + localPort + "/v1/customer/customer1") + .exchange() + .expectBody() + .consumeWith((result) -> { + String body = new String(result.getResponseBody()); + log.info("[I99] body={}", body); + assertEquals("/api/customer1", body); + }); + } + + @Test + void testWhenDslCall_thenRewriteSuccess(@Autowired WebTestClient webClient) { + webClient.get() + .uri("http://localhost:" + localPort + "/v2/zip/123456") + .exchange() + .expectBody() + .consumeWith((result) -> { + String body = new String(result.getResponseBody()); + log.info("[I99] body={}", body); + assertTrue(body.matches("/api/zip/123456-\\d{3}")); + }); + } + +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/RedisWebFilterFactoriesLiveTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/RedisWebFilterFactoriesLiveTest.java new file mode 100644 index 0000000000..a28eb68775 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/RedisWebFilterFactoriesLiveTest.java @@ -0,0 +1,64 @@ +package com.baeldung.springcloudgateway.webfilters; + +import org.junit.After; +import org.junit.Before; +import org.junit.jupiter.api.RepeatedTest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; + +import redis.embedded.RedisServer; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ActiveProfiles("webfilters") +@TestConfiguration +public class RedisWebFilterFactoriesLiveTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(RedisWebFilterFactoriesLiveTest.class); + + private RedisServer redisServer; + + public RedisWebFilterFactoriesLiveTest() { + } + + @Before + public void postConstruct() { + this.redisServer = new RedisServer(6379); + redisServer.start(); + } + + @LocalServerPort + String port; + + @Autowired + private TestRestTemplate restTemplate; + + @Autowired + TestRestTemplate template; + + @RepeatedTest(25) + public void whenCallRedisGetThroughGateway_thenOKStatusOrIsReceived() { + String url = "http://localhost:" + port + "/redis/get"; + + ResponseEntity r = restTemplate.getForEntity(url, String.class); + // assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + + LOGGER.info("Received: status->{}, reason->{}, remaining->{}", + r.getStatusCodeValue(), r.getStatusCode().getReasonPhrase(), + r.getHeaders().get("X-RateLimit-Remaining")); + } + + @After + public void preDestroy() { + redisServer.stop(); + } + +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/WebFilterFactoriesLiveTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/WebFilterFactoriesLiveTest.java new file mode 100644 index 0000000000..67e00a42fc --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/WebFilterFactoriesLiveTest.java @@ -0,0 +1,136 @@ +package com.baeldung.springcloudgateway.webfilters; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.assertj.core.api.Condition; +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.reactive.server.WebTestClient; +import org.springframework.test.web.reactive.server.WebTestClient.ResponseSpec; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ActiveProfiles("webfilters") +public class WebFilterFactoriesLiveTest { + + @LocalServerPort + String port; + + @Autowired + private WebTestClient client; + + @Autowired + private TestRestTemplate restTemplate; + + @BeforeEach + public void configureClient() { + client = WebTestClient.bindToServer() + .baseUrl("http://localhost:" + port) + .build(); + } + + @Test + public void whenCallGetThroughGateway_thenAllHTTPRequestHeadersParametersAreSet() throws JSONException { + String url = "http://localhost:" + port + "/get"; + ResponseEntity response = restTemplate.getForEntity(url, String.class); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + + JSONObject json = new JSONObject(response.getBody()); + JSONObject headers = json.getJSONObject("headers"); + assertThat(headers.getString("My-Header-Good")).isEqualTo("Good"); + assertThat(headers.getString("My-Header-Bad")).isEqualTo("Good"); + assertThat(headers.getString("My-Header-Set")).isEqualTo("Set"); + assertTrue(headers.isNull("My-Header-Remove")); + JSONObject vars = json.getJSONObject("args"); + assertThat(vars.getString("var")).isEqualTo("good"); + } + + @Test + public void whenCallHeaderPostThroughGateway_thenAllHTTPResponseHeadersAreSet() { + ResponseSpec response = client.post() + .uri("/header/post") + .exchange(); + + response.expectStatus() + .isOk() + .expectHeader() + .valueEquals("My-Header-Rewrite", "password=***") + .expectHeader() + .valueEquals("My-Header-Set", "Set") + .expectHeader() + .valueEquals("My-Header-Good", "Good") + .expectHeader() + .doesNotExist("My-Header-Remove"); + } + + @Test + public void whenCallPostThroughGateway_thenBodyIsRetrieved() throws JSONException { + String url = "http://localhost:" + port + "/post"; + + HttpEntity entity = new HttpEntity<>("content", new HttpHeaders()); + + ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + + JSONObject json = new JSONObject(response.getBody()); + JSONObject data = json.getJSONObject("json"); + assertThat(data.getString("message")).isEqualTo("CONTENT"); + } + + @Test + public void whenCallPutThroughGateway_thenBodyIsRetrieved() throws JSONException { + String url = "http://localhost:" + port + "/put"; + + HttpEntity entity = new HttpEntity<>("CONTENT", new HttpHeaders()); + + ResponseEntity response = restTemplate.exchange(url, HttpMethod.PUT, entity, String.class); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + + JSONObject json = new JSONObject(response.getBody()); + assertThat(json.getString("message")).isEqualTo("New Body"); + } + + @Test + public void whenCallDeleteThroughGateway_thenIsUnauthorizedCodeIsSet() { + ResponseSpec response = client.delete() + .uri("/delete") + .exchange(); + + response.expectStatus() + .isUnauthorized(); + } + + @Test + public void whenCallFakePostThroughGateway_thenIsUnauthorizedCodeIsSet() { + ResponseSpec response = client.post() + .uri("/fake/post") + .exchange(); + + response.expectStatus() + .is3xxRedirection(); + } + + @Test + public void whenCallStatus504ThroughGateway_thenCircuitBreakerIsExecuted() throws JSONException { + String url = "http://localhost:" + port + "/status/504"; + ResponseEntity response = restTemplate.getForEntity(url, String.class); + + JSONObject json = new JSONObject(response.getBody()); + assertThat(json.getString("url")).contains("anything"); + } +} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/postman/OAuth_Gateway.postman_collection.json b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/postman/OAuth_Gateway.postman_collection.json new file mode 100644 index 0000000000..ac920a271b --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/postman/OAuth_Gateway.postman_collection.json @@ -0,0 +1,203 @@ +{ + "info": { + "_postman_id": "b3d00e23-c2cd-40ce-a90b-673efb25e5c0", + "name": "Baeldung - OAuth", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Token", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = pm.response.json();\r", + "pm.environment.set(\"access_token\", jsonData.access_token);\r", + "pm.environment.set(\"refresh_token\", jsonData.refresh_token);\r", + "pm.environment.set(\"backend_token\", \"Bearer \" + jsonData.access_token);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "client_id", + "value": "{{client_id}}", + "type": "text" + }, + { + "key": "client_secret", + "value": "{{client_secret}}", + "type": "text" + }, + { + "key": "grant_type", + "value": "password", + "type": "text" + }, + { + "key": "scope", + "value": "email roles profile", + "type": "text" + }, + { + "key": "username", + "value": "maxwell.smart", + "type": "text" + }, + { + "key": "password", + "value": "1234", + "type": "text" + } + ] + }, + "url": { + "raw": "{{keycloack_base}}/token", + "host": [ + "{{keycloack_base}}" + ], + "path": [ + "token" + ] + } + }, + "response": [] + }, + { + "name": "Quote", + "protocolProfileBehavior": { + "disabledSystemHeaders": { + "accept": true + } + }, + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{access_token}}", + "type": "string" + } + ] + }, + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "application/json", + "type": "text" + } + ], + "url": { + "raw": "http://localhost:8085/quotes/:symbol", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8085", + "path": [ + "quotes", + ":symbol" + ], + "variable": [ + { + "key": "symbol", + "value": "IBM" + } + ] + } + }, + "response": [] + }, + { + "name": "Quote via Gateway", + "protocolProfileBehavior": { + "disabledSystemHeaders": { + "accept": true + } + }, + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{access_token}}", + "type": "string" + } + ] + }, + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "application/json", + "type": "text" + } + ], + "url": { + "raw": "http://localhost:8086/quotes/:symbol", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8086", + "path": [ + "quotes", + ":symbol" + ], + "variable": [ + { + "key": "symbol", + "value": "IBM" + } + ] + } + }, + "response": [] + } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "variable": [ + { + "key": "keycloack_base", + "value": "http://localhost:8083/auth/realms/baeldung/protocol/openid-connect" + }, + { + "key": "client_id", + "value": "quotes-client" + }, + { + "key": "client_secret", + "value": "56be94c8-b20a-4374-899c-e39cb022d3f8" + } + ] +} \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/resources/logback-test.xml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..6980d119b1 --- /dev/null +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/resources/logback-test.xml @@ -0,0 +1,17 @@ + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/pom.xml b/spring-cloud-modules/spring-cloud-bootstrap/pom.xml index e7fe7e7485..f4d4073ef1 100644 --- a/spring-cloud-modules/spring-cloud-bootstrap/pom.xml +++ b/spring-cloud-modules/spring-cloud-bootstrap/pom.xml @@ -18,6 +18,7 @@ config discovery gateway + gateway-2 svc-book svc-rating customer-service From f1b3f233dc537d707dd491280648e5b57fb13178 Mon Sep 17 00:00:00 2001 From: Anastasios Ioannidis Date: Fri, 18 Aug 2023 11:30:56 +0300 Subject: [PATCH 002/193] JAVA-13321 Removed code unrelated to spring-cloud-gateway article topics --- .../gateway-2/README-OAuth.md | 40 ------------ .../spring-cloud-bootstrap/gateway-2/pom.xml | 44 ------------- .../oauth/backend/QuotesApplication.java | 44 ------------- .../oauth/backend/domain/Quote.java | 35 ---------- .../oauth/backend/web/QuoteApi.java | 34 ---------- .../ResourceServerGatewayApplication.java | 13 ---- .../KeycloakReactiveTokenInstrospector.java | 65 ------------------- .../resources/application-oauth-client.yml | 26 -------- .../resources/application-resource-server.yml | 19 ------ .../resources/quotes-application.properties | 12 ---- 10 files changed, 332 deletions(-) delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README-OAuth.md delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/QuotesApplication.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/domain/Quote.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/web/QuoteApi.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/server/ResourceServerGatewayApplication.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/shared/KeycloakReactiveTokenInstrospector.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-oauth-client.yml delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-resource-server.yml delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/quotes-application.properties diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README-OAuth.md b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README-OAuth.md deleted file mode 100644 index c186114589..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README-OAuth.md +++ /dev/null @@ -1,40 +0,0 @@ -# OAuth Test Setup - -In order to test the OAuth-secured gateway configurations, please follow the steps below - -## Keycloak setup - -1. Clone or download the https://github.com/Baeldung/spring-security-oauth project -2. Replace the file `oauth-rest/oauth-authorization-server/src/main/resources/baeldung-realm.json` - with the one provider here -3. Go to the oauth-rest/oauth-authorization-server folder and use maven to build the project -4. Run the Keycloack service with `mvn spring-boot:run` -5. Once Keycloak is up and running, go to `http://localhost:8083/auth/admin/master/console/#/realms/baeldung` and - log in with using `bael-admin/pass` as credentials -6. Create two test users, so that one belongs to the *Golden Customers* group and the other doesn't. - -## Quotes backend - -Use the provided maven profile: - -``` -$ mvn spring-boot:run -Pquotes-application -``` - -## Gateway as Resource Server - -Use the provided maven profile: - -``` -$ mvn spring-boot:run -Pgateway-as-resource-server -``` - -## Gateway as OAuth 2.0 Client - -Use the provided maven profile: - -``` -$ mvn spring-boot:run -Pgateway-as-oauth-client -``` - - diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml index dc42483dc5..520646cc7d 100644 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml @@ -121,50 +121,6 @@ - - quotes-application - - - - org.springframework.boot - spring-boot-maven-plugin - - com.baeldung.springcloudgateway.oauth.backend.QuotesApplication - - - - - - - gateway-as-resource-server - - - - org.springframework.boot - spring-boot-maven-plugin - - com.baeldung.springcloudgateway.oauth.server.ResourceServerGatewayApplication - -Dspring.profiles.active=resource-server - - - - - - - gateway-as-oauth-client - - - - org.springframework.boot - spring-boot-maven-plugin - - com.baeldung.springcloudgateway.oauth.server.ResourceServerGatewayApplication - -Dspring.profiles.active=oauth-client - - - - - gateway-url-rewrite diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/QuotesApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/QuotesApplication.java deleted file mode 100644 index 96daf8a73d..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/QuotesApplication.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * - */ -package com.baeldung.springcloudgateway.oauth.backend; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.PropertySource; -import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; -import org.springframework.security.oauth2.server.resource.introspection.NimbusReactiveOpaqueTokenIntrospector; -import org.springframework.security.oauth2.server.resource.introspection.ReactiveOpaqueTokenIntrospector; - -import com.baeldung.springcloudgateway.oauth.shared.KeycloakReactiveTokenInstrospector; - -/** - * @author Philippe - * - */ -@SpringBootApplication -@PropertySource("classpath:quotes-application.properties") -@EnableWebFluxSecurity -public class QuotesApplication { - - public static void main(String[] args) { - SpringApplication.run(QuotesApplication.class); - } - - - @Bean - public ReactiveOpaqueTokenIntrospector keycloakIntrospector(OAuth2ResourceServerProperties props) { - - NimbusReactiveOpaqueTokenIntrospector delegate = new NimbusReactiveOpaqueTokenIntrospector( - props.getOpaquetoken().getIntrospectionUri(), - props.getOpaquetoken().getClientId(), - props.getOpaquetoken().getClientSecret()); - - return new KeycloakReactiveTokenInstrospector(delegate); - } - - -} - diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/domain/Quote.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/domain/Quote.java deleted file mode 100644 index 042cfa63fa..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/domain/Quote.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.springcloudgateway.oauth.backend.domain; - - -public class Quote { - - private String symbol; - private double price; - - /** - * @return the symbol - */ - public String getSymbol() { - return symbol; - } - /** - * @param symbol the symbol to set - */ - public void setSymbol(String symbol) { - this.symbol = symbol; - } - /** - * @return the price - */ - public double getPrice() { - return price; - } - /** - * @param price the price to set - */ - public void setPrice(double price) { - this.price = price; - } - - -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/web/QuoteApi.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/web/QuoteApi.java deleted file mode 100644 index 6d3721166c..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/backend/web/QuoteApi.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.springcloudgateway.oauth.backend.web; - -import javax.annotation.PostConstruct; - -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.springcloudgateway.oauth.backend.domain.Quote; - -import reactor.core.publisher.Mono; - -@RestController -public class QuoteApi { - private static final GrantedAuthority GOLD_CUSTOMER = new SimpleGrantedAuthority("gold"); - - @GetMapping("/quotes/{symbol}") - public Mono getQuote(@PathVariable("symbol") String symbol, BearerTokenAuthentication auth ) { - - Quote q = new Quote(); - q.setSymbol(symbol); - - if ( auth.getAuthorities().contains(GOLD_CUSTOMER)) { - q.setPrice(10.0); - } - else { - q.setPrice(12.0); - } - return Mono.just(q); - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/server/ResourceServerGatewayApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/server/ResourceServerGatewayApplication.java deleted file mode 100644 index 1b85867f3b..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/server/ResourceServerGatewayApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.springcloudgateway.oauth.server; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; - -@SpringBootApplication -@EnableWebFluxSecurity -public class ResourceServerGatewayApplication { - public static void main(String[] args) { - SpringApplication.run(ResourceServerGatewayApplication.class,args); - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/shared/KeycloakReactiveTokenInstrospector.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/shared/KeycloakReactiveTokenInstrospector.java deleted file mode 100644 index e834e6934d..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/oauth/shared/KeycloakReactiveTokenInstrospector.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * - */ -package com.baeldung.springcloudgateway.oauth.shared; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal; -import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal; -import org.springframework.security.oauth2.server.resource.introspection.ReactiveOpaqueTokenIntrospector; - -import reactor.core.publisher.Mono; - -/** - * Custom ReactiveTokenIntrospector to map realm roles into Spring GrantedAuthorities - * - */ -public class KeycloakReactiveTokenInstrospector implements ReactiveOpaqueTokenIntrospector { - - private final ReactiveOpaqueTokenIntrospector delegate; - - public KeycloakReactiveTokenInstrospector(ReactiveOpaqueTokenIntrospector delegate) { - this.delegate = delegate; - } - - @Override - public Mono introspect(String token) { - - return delegate.introspect(token) - .map( this::mapPrincipal); - } - - protected OAuth2AuthenticatedPrincipal mapPrincipal(OAuth2AuthenticatedPrincipal principal) { - - return new DefaultOAuth2AuthenticatedPrincipal( - principal.getName(), - principal.getAttributes(), - extractAuthorities(principal)); - } - - protected Collection extractAuthorities(OAuth2AuthenticatedPrincipal principal) { - - // - Map> realm_access = principal.getAttribute("realm_access"); - List roles = realm_access.getOrDefault("roles", Collections.emptyList()); - List rolesAuthorities = roles.stream() - .map(SimpleGrantedAuthority::new) - .collect(Collectors.toList()); - - Set allAuthorities = new HashSet<>(); - allAuthorities.addAll(principal.getAuthorities()); - allAuthorities.addAll(rolesAuthorities); - - return allAuthorities; - } - -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-oauth-client.yml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-oauth-client.yml deleted file mode 100644 index b097c54eb1..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-oauth-client.yml +++ /dev/null @@ -1,26 +0,0 @@ -server: - port: 8087 -spring: - cloud: - gateway: - redis: - enabled: false - routes: - - id: quotes - uri: http://localhost:8085 - predicates: - - Path=/quotes/** - filters: - TokenRelay= - security: - oauth2: - client: provider: keycloak: - issuer-uri: http://localhost:8083/auth/realms/baeldung - registration: quotes-client: - provider: keycloak - client-id: quotes-client - client-secret: 0e082231-a70d-48e8-b8a5-fbfb743041b6 - scope: - email - - profile - - roles - - \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-resource-server.yml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-resource-server.yml deleted file mode 100644 index 14f713a04a..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-resource-server.yml +++ /dev/null @@ -1,19 +0,0 @@ -server: - port: 8086 -spring: - security: - oauth2: - resourceserver: - opaquetoken: - introspection-uri: http://localhost:8083/auth/realms/baeldung/protocol/openid-connect/token/introspect - client-id: quotes-client - client-secret: 0e082231-a70d-48e8-b8a5-fbfb743041b6 - cloud: - gateway: - redis: - enabled: false - routes: - - id: quotes - uri: http://localhost:8085 - predicates: - - Path=/quotes/** diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/quotes-application.properties b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/quotes-application.properties deleted file mode 100644 index 48e8999b1b..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/quotes-application.properties +++ /dev/null @@ -1,12 +0,0 @@ -server.port=8085 -# Disable gateway & redis as we don't need them in this application -spring.cloud.gateway.enabled=false -spring.cloud.gateway.redis.enabled=false - -# Resource server settings -spring.security.oauth2.resourceserver.opaquetoken.introspection-uri=http://localhost:8083/auth/realms/baeldung/protocol/openid-connect/token/introspect -spring.security.oauth2.resourceserver.opaquetoken.client-id=quotes-client -spring.security.oauth2.resourceserver.opaquetoken.client-secret=0e082231-a70d-48e8-b8a5-fbfb743041b6 - - - From fa34902b702d98b542bd30207e9b11479d5af23e Mon Sep 17 00:00:00 2001 From: mcasari Date: Sat, 19 Aug 2023 23:42:04 +0200 Subject: [PATCH 003/193] shallow vs deep copy first commit --- shallow-deep-copy/README.md | 7 +++++ shallow-deep-copy/pom.xml | 16 ++++++++++ .../baeldung/shallowdeepcopy/Dependency.java | 23 ++++++++++++++ .../com/baeldung/shallowdeepcopy/Main.java | 31 +++++++++++++++++++ .../src/main/resources/logback.xml | 13 ++++++++ .../ShallowDeepCopyUnitTest.java | 27 ++++++++++++++++ 6 files changed, 117 insertions(+) create mode 100644 shallow-deep-copy/README.md create mode 100644 shallow-deep-copy/pom.xml create mode 100644 shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Dependency.java create mode 100644 shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Main.java create mode 100644 shallow-deep-copy/src/main/resources/logback.xml create mode 100644 shallow-deep-copy/src/test/java/com/baeldung/shallowdeepcopy/ShallowDeepCopyUnitTest.java diff --git a/shallow-deep-copy/README.md b/shallow-deep-copy/README.md new file mode 100644 index 0000000000..e1a426a138 --- /dev/null +++ b/shallow-deep-copy/README.md @@ -0,0 +1,7 @@ +## Shallow vs Deep Copy + +This module contains an article about shallow vs deep copy of Java objects + +### Relevant articles: + +- [Creating a deep vs shallow copy of an object in Java](https://drafts.baeldung.com/?p=172294&preview=true) diff --git a/shallow-deep-copy/pom.xml b/shallow-deep-copy/pom.xml new file mode 100644 index 0000000000..01c1430f28 --- /dev/null +++ b/shallow-deep-copy/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + shallow-deep-copy + shallow-deep-copy + jar + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + \ No newline at end of file diff --git a/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Dependency.java b/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Dependency.java new file mode 100644 index 0000000000..a5da5fc163 --- /dev/null +++ b/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Dependency.java @@ -0,0 +1,23 @@ +package com.baeldung.shallowdeepcopy; + +public class Dependency implements Cloneable { + private int value = 13; + + public Dependency(int value) { + super(); + this.value = value; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + @Override + protected Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Main.java b/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Main.java new file mode 100644 index 0000000000..fb24007162 --- /dev/null +++ b/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Main.java @@ -0,0 +1,31 @@ +package com.baeldung.shallowdeepcopy; + +public class Main implements Cloneable { + private Dependency dependency; + + public Main(Dependency dependency) { + super(); + this.dependency = dependency; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public Object deepClone() throws CloneNotSupportedException { + Main dependentClone = (Main) super.clone(); + Dependency dependencyClone = (Dependency) this.dependency.clone(); + dependentClone.setDependency(dependencyClone); + return dependentClone; + } + + public Dependency getDependency() { + return dependency; + } + + public void setDependency(Dependency dependency) { + this.dependency = dependency; + } + +} diff --git a/shallow-deep-copy/src/main/resources/logback.xml b/shallow-deep-copy/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/shallow-deep-copy/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/shallow-deep-copy/src/test/java/com/baeldung/shallowdeepcopy/ShallowDeepCopyUnitTest.java b/shallow-deep-copy/src/test/java/com/baeldung/shallowdeepcopy/ShallowDeepCopyUnitTest.java new file mode 100644 index 0000000000..321c2df327 --- /dev/null +++ b/shallow-deep-copy/src/test/java/com/baeldung/shallowdeepcopy/ShallowDeepCopyUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.shallowdeepcopy; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class ShallowDeepCopyUnitTest { + + @Test + public void givenAnObjectAndADependency_whenShallowClonedAndDepencyChanges_ThenDepencyHasNewValue() throws Exception { + Dependency dependency = new Dependency(13); + Main main = new Main(dependency); + Main shallowClone = (Main) main.clone(); + dependency.setValue(17); + assertEquals(17, shallowClone.getDependency().getValue()); + } + + + @Test + public void givenAnObjectAndADependency_whenDeepClonedAndDepencyChanges_ThenDepencyKeepsOldValue() throws Exception { + Dependency dependency = new Dependency(13); + Main main = new Main(dependency); + Main deepClone = (Main) main.deepClone(); + dependency.setValue(17); + assertEquals(13, deepClone.getDependency().getValue()); + } +} From 8a6e3f233ec0591fe20d82fcf00c80cb8164b577 Mon Sep 17 00:00:00 2001 From: mcasari Date: Tue, 22 Aug 2023 19:49:54 +0200 Subject: [PATCH 004/193] Format content with baeldung formatter --- shallow-deep-copy/pom.xml | 22 ++++----- .../baeldung/shallowdeepcopy/Dependency.java | 32 ++++++------- .../com/baeldung/shallowdeepcopy/Main.java | 48 +++++++++---------- .../src/main/resources/logback.xml | 19 ++++---- .../ShallowDeepCopyUnitTest.java | 37 +++++++------- 5 files changed, 80 insertions(+), 78 deletions(-) diff --git a/shallow-deep-copy/pom.xml b/shallow-deep-copy/pom.xml index 01c1430f28..323f720df3 100644 --- a/shallow-deep-copy/pom.xml +++ b/shallow-deep-copy/pom.xml @@ -1,16 +1,16 @@ - 4.0.0 - shallow-deep-copy - shallow-deep-copy - jar + 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"> + 4.0.0 + shallow-deep-copy + shallow-deep-copy + jar - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + \ No newline at end of file diff --git a/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Dependency.java b/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Dependency.java index a5da5fc163..2550acd268 100644 --- a/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Dependency.java +++ b/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Dependency.java @@ -1,23 +1,23 @@ package com.baeldung.shallowdeepcopy; public class Dependency implements Cloneable { - private int value = 13; - - public Dependency(int value) { - super(); - this.value = value; - } + private int value = 13; - public int getValue() { - return value; - } + public Dependency(int value) { + super(); + this.value = value; + } - public void setValue(int value) { - this.value = value; - } + public int getValue() { + return value; + } - @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); - } + public void setValue(int value) { + this.value = value; + } + + @Override + protected Object clone() throws CloneNotSupportedException { + return super.clone(); + } } diff --git a/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Main.java b/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Main.java index fb24007162..33d565bb10 100644 --- a/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Main.java +++ b/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Main.java @@ -1,31 +1,31 @@ package com.baeldung.shallowdeepcopy; public class Main implements Cloneable { - private Dependency dependency; - - public Main(Dependency dependency) { - super(); - this.dependency = dependency; - } + private Dependency dependency; - @Override - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } + public Main(Dependency dependency) { + super(); + this.dependency = dependency; + } - public Object deepClone() throws CloneNotSupportedException { - Main dependentClone = (Main) super.clone(); - Dependency dependencyClone = (Dependency) this.dependency.clone(); - dependentClone.setDependency(dependencyClone); - return dependentClone; - } - - public Dependency getDependency() { - return dependency; - } + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public Object deepClone() throws CloneNotSupportedException { + Main dependentClone = (Main) super.clone(); + Dependency dependencyClone = (Dependency) this.dependency.clone(); + dependentClone.setDependency(dependencyClone); + return dependentClone; + } + + public Dependency getDependency() { + return dependency; + } + + public void setDependency(Dependency dependency) { + this.dependency = dependency; + } - public void setDependency(Dependency dependency) { - this.dependency = dependency; - } - } diff --git a/shallow-deep-copy/src/main/resources/logback.xml b/shallow-deep-copy/src/main/resources/logback.xml index 7d900d8ea8..830ab22727 100644 --- a/shallow-deep-copy/src/main/resources/logback.xml +++ b/shallow-deep-copy/src/main/resources/logback.xml @@ -1,13 +1,14 @@ - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + - - - + + + \ No newline at end of file diff --git a/shallow-deep-copy/src/test/java/com/baeldung/shallowdeepcopy/ShallowDeepCopyUnitTest.java b/shallow-deep-copy/src/test/java/com/baeldung/shallowdeepcopy/ShallowDeepCopyUnitTest.java index 321c2df327..f75bbc040b 100644 --- a/shallow-deep-copy/src/test/java/com/baeldung/shallowdeepcopy/ShallowDeepCopyUnitTest.java +++ b/shallow-deep-copy/src/test/java/com/baeldung/shallowdeepcopy/ShallowDeepCopyUnitTest.java @@ -5,23 +5,24 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; class ShallowDeepCopyUnitTest { - - @Test - public void givenAnObjectAndADependency_whenShallowClonedAndDepencyChanges_ThenDepencyHasNewValue() throws Exception { - Dependency dependency = new Dependency(13); - Main main = new Main(dependency); - Main shallowClone = (Main) main.clone(); - dependency.setValue(17); - assertEquals(17, shallowClone.getDependency().getValue()); - } - - @Test - public void givenAnObjectAndADependency_whenDeepClonedAndDepencyChanges_ThenDepencyKeepsOldValue() throws Exception { - Dependency dependency = new Dependency(13); - Main main = new Main(dependency); - Main deepClone = (Main) main.deepClone(); - dependency.setValue(17); - assertEquals(13, deepClone.getDependency().getValue()); - } + @Test + public void givenAnObjectAndADependency_whenShallowClonedAndDepencyChanges_ThenDepencyHasNewValue() throws Exception { + Dependency dependency = new Dependency(13); + Main main = new Main(dependency); + Main shallowClone = (Main) main.clone(); + dependency.setValue(17); + assertEquals(17, shallowClone.getDependency() + .getValue()); + } + + @Test + public void givenAnObjectAndADependency_whenDeepClonedAndDepencyChanges_ThenDepencyKeepsOldValue() throws Exception { + Dependency dependency = new Dependency(13); + Main main = new Main(dependency); + Main deepClone = (Main) main.deepClone(); + dependency.setValue(17); + assertEquals(13, deepClone.getDependency() + .getValue()); + } } From 982401a329a86e1a124bfc6d451ac1b31069d458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20M=C3=BCller?= Date: Fri, 28 Jul 2023 19:15:07 +0200 Subject: [PATCH 005/193] [BAEL-6529] Update Springwolf version to 0.13.0 Co-authored-by: Timon Back --- .../src/test/resources/asyncapi.json | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/spring-boot-modules/spring-boot-documentation/src/test/resources/asyncapi.json b/spring-boot-modules/spring-boot-documentation/src/test/resources/asyncapi.json index 0198733c1c..45be27f571 100644 --- a/spring-boot-modules/spring-boot-documentation/src/test/resources/asyncapi.json +++ b/spring-boot-modules/spring-boot-documentation/src/test/resources/asyncapi.json @@ -18,7 +18,9 @@ "operationId": "incoming-topic_publish", "description": "More details for the incoming topic", "bindings": { - "kafka": { } + "kafka": { + "bindingVersion": "0.4.0" + } }, "message": { "schemaFormat": "application/vnd.oai.openapi+json;version=3.0.0", @@ -32,7 +34,9 @@ "$ref": "#/components/schemas/SpringKafkaDefaultHeadersIncomingPayloadDto" }, "bindings": { - "kafka": { } + "kafka": { + "bindingVersion": "0.4.0" + } } } } @@ -42,7 +46,9 @@ "operationId": "outgoing-topic_subscribe", "description": "More details for the outgoing topic", "bindings": { - "kafka": { } + "kafka": { + "bindingVersion": "0.4.0" + } }, "message": { "schemaFormat": "application/vnd.oai.openapi+json;version=3.0.0", @@ -56,7 +62,9 @@ "$ref": "#/components/schemas/SpringKafkaDefaultHeadersOutgoingPayloadDto" }, "bindings": { - "kafka": { } + "kafka": { + "bindingVersion": "0.4.0" + } } } } From c7d0b46531dd52afac7782830ad8262a1a1abd50 Mon Sep 17 00:00:00 2001 From: Timon Back Date: Mon, 4 Sep 2023 22:02:38 +0200 Subject: [PATCH 006/193] [BAEL-6529] Update Springwolf version to 0.14.0 --- spring-boot-modules/spring-boot-documentation/pom.xml | 4 ++-- .../src/test/resources/asyncapi.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-boot-modules/spring-boot-documentation/pom.xml b/spring-boot-modules/spring-boot-documentation/pom.xml index f0806b3c75..3ac2799258 100644 --- a/spring-boot-modules/spring-boot-documentation/pom.xml +++ b/spring-boot-modules/spring-boot-documentation/pom.xml @@ -93,8 +93,8 @@ 2.2.11 - 0.12.1 - 0.8.0 + 0.14.0 + 0.14.0 1.18.3 diff --git a/spring-boot-modules/spring-boot-documentation/src/test/resources/asyncapi.json b/spring-boot-modules/spring-boot-documentation/src/test/resources/asyncapi.json index 45be27f571..260f9382f9 100644 --- a/spring-boot-modules/spring-boot-documentation/src/test/resources/asyncapi.json +++ b/spring-boot-modules/spring-boot-documentation/src/test/resources/asyncapi.json @@ -8,7 +8,7 @@ "defaultContentType": "application/json", "servers": { "kafka": { - "url": "localhost:9092", + "url": "localhost:29092", "protocol": "kafka" } }, From 68b78c845ce06efc2de53239c4bd76e06f7d93a8 Mon Sep 17 00:00:00 2001 From: Timon Back Date: Tue, 5 Sep 2023 08:16:27 +0200 Subject: [PATCH 007/193] Update asyncapi.json --- .../spring-boot-documentation/src/test/resources/asyncapi.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-documentation/src/test/resources/asyncapi.json b/spring-boot-modules/spring-boot-documentation/src/test/resources/asyncapi.json index 260f9382f9..45be27f571 100644 --- a/spring-boot-modules/spring-boot-documentation/src/test/resources/asyncapi.json +++ b/spring-boot-modules/spring-boot-documentation/src/test/resources/asyncapi.json @@ -8,7 +8,7 @@ "defaultContentType": "application/json", "servers": { "kafka": { - "url": "localhost:29092", + "url": "localhost:9092", "protocol": "kafka" } }, From 5116a17b36cb840149cb55c43af55b7093683924 Mon Sep 17 00:00:00 2001 From: lajka Date: Tue, 5 Sep 2023 19:42:03 +0200 Subject: [PATCH 008/193] BAEL-6871: Add code and tests demonstrating how to compare objects using apache commons lang 3. --- core-java-modules/core-java-lang-6/pom.xml | 11 +++- .../com/baeldung/compareobjects/Address.java | 47 +++++++++++++++ .../com/baeldung/compareobjects/Person.java | 58 +++++++++++++++++++ .../compareobjects/PersonDiffBuilder.java | 32 ++++++++++ .../PersonReflectionDiffBuilder.java | 11 ++++ .../baeldung/compareobjects/PhoneNumber.java | 43 ++++++++++++++ .../PersonDiffBuilderUnitTest.java | 38 ++++++++++++ .../PersonReflectionDiffBuilderUnitTest.java | 37 ++++++++++++ 8 files changed, 276 insertions(+), 1 deletion(-) create mode 100644 core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/Address.java create mode 100644 core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/Person.java create mode 100644 core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PersonDiffBuilder.java create mode 100644 core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PersonReflectionDiffBuilder.java create mode 100644 core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PhoneNumber.java create mode 100644 core-java-modules/core-java-lang-6/src/test/java/com/baeldung/compareobjects/PersonDiffBuilderUnitTest.java create mode 100644 core-java-modules/core-java-lang-6/src/test/java/com/baeldung/compareobjects/PersonReflectionDiffBuilderUnitTest.java diff --git a/core-java-modules/core-java-lang-6/pom.xml b/core-java-modules/core-java-lang-6/pom.xml index 53ef36a898..f458456b9f 100644 --- a/core-java-modules/core-java-lang-6/pom.xml +++ b/core-java-modules/core-java-lang-6/pom.xml @@ -18,7 +18,16 @@ mapstruct ${mapstruct.version} - + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + org.junit.jupiter + junit-jupiter-api + ${junit-jupiter.version} + diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/Address.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/Address.java new file mode 100644 index 0000000000..e82a1018ce --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/Address.java @@ -0,0 +1,47 @@ +package com.baeldung.compareobjects; + +import java.util.Objects; + +public class Address { + private String streetAddress; + private String city; + private String postalCode; + + public Address(String streetAddress, String city, String postalCode) { + this.streetAddress = streetAddress; + this.city = city; + this.postalCode = postalCode; + } + + public String getStreetAddress() { + return streetAddress; + } + + public String getCity() { + return city; + } + + public String getPostalCode() { + return postalCode; + } + + @Override + public String toString() { + return "Address{" + "streetAddress='" + streetAddress + '\'' + ", city='" + city + '\'' + ", postalCode='" + postalCode + '\'' + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Address address = (Address) o; + return Objects.equals(streetAddress, address.streetAddress) && Objects.equals(city, address.city) && Objects.equals(postalCode, address.postalCode); + } + + @Override + public int hashCode() { + return Objects.hash(streetAddress, city, postalCode); + } +} diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/Person.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/Person.java new file mode 100644 index 0000000000..6ba244ff17 --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/Person.java @@ -0,0 +1,58 @@ +package com.baeldung.compareobjects; + +import java.util.List; +import java.util.Objects; + +import org.apache.commons.lang3.builder.DiffExclude; + +public class Person { + private String firstName; + private String lastName; + private int age; + private List phoneNumbers; + @DiffExclude + private Address address; + + public Person(String firstName, String lastName, int age, List phoneNumbers, Address address) { + this.firstName = firstName; + this.lastName = lastName; + this.age = age; + this.phoneNumbers = phoneNumbers; + this.address = address; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public int getAge() { + return age; + } + + public List getPhoneNumbers() { + return phoneNumbers; + } + + public Address getAddress() { + return address; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Person person = (Person) o; + return age == person.age && Objects.equals(firstName, person.firstName) && Objects.equals(lastName, person.lastName) && Objects.equals(phoneNumbers, person.phoneNumbers) && Objects.equals(address, person.address); + } + + @Override + public int hashCode() { + return Objects.hash(firstName, lastName, age, phoneNumbers, address); + } +} diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PersonDiffBuilder.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PersonDiffBuilder.java new file mode 100644 index 0000000000..9e21f5d7c3 --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PersonDiffBuilder.java @@ -0,0 +1,32 @@ +package com.baeldung.compareobjects; + +import org.apache.commons.lang3.builder.DiffBuilder; +import org.apache.commons.lang3.builder.DiffResult; +import org.apache.commons.lang3.builder.ToStringStyle; + +public class PersonDiffBuilder { + public static DiffResult compare(Person first, Person second) { + DiffBuilder diffBuilder = new DiffBuilder(first, second, ToStringStyle.DEFAULT_STYLE).append("person", first.getFirstName(), second.getFirstName()) + .append("lastName", first.getLastName(), second.getLastName()) + .append("streetAddress", first.getAddress() + .getStreetAddress(), second.getAddress() + .getStreetAddress()) + .append("city", first.getAddress() + .getCity(), second.getAddress() + .getCity()) + .append("postalCode", first.getAddress() + .getPostalCode(), second.getAddress() + .getPostalCode()) + .append("age", first.getAge(), second.getAge()); + + for (int i = 0; i < first.getPhoneNumbers() + .size(); i++) { + diffBuilder.append("phoneNumbers[" + i + "].number", first.getPhoneNumbers() + .get(i) + .getNumber(), second.getPhoneNumbers() + .get(i) + .getNumber()); + } + return diffBuilder.build(); + } +} diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PersonReflectionDiffBuilder.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PersonReflectionDiffBuilder.java new file mode 100644 index 0000000000..82081e7282 --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PersonReflectionDiffBuilder.java @@ -0,0 +1,11 @@ +package com.baeldung.compareobjects; + +import org.apache.commons.lang3.builder.DiffResult; +import org.apache.commons.lang3.builder.ReflectionDiffBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +public class PersonReflectionDiffBuilder { + public static DiffResult compare(Person first, Person second) { + return new ReflectionDiffBuilder<>(first, second, ToStringStyle.SHORT_PREFIX_STYLE).build(); + } +} diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PhoneNumber.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PhoneNumber.java new file mode 100644 index 0000000000..4ab2b4a4bd --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PhoneNumber.java @@ -0,0 +1,43 @@ +package com.baeldung.compareobjects; + +import java.util.Objects; + +import org.apache.commons.lang3.builder.DiffExclude; + +public class PhoneNumber { + private String type; + private String number; + + public PhoneNumber(String type, String number) { + this.type = type; + this.number = number; + } + + public String getType() { + return type; + } + + public String getNumber() { + return number; + } + + @Override + public String toString() { + return "PhoneNumber{" + "type='" + type + '\'' + ", number='" + number + '\'' + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + PhoneNumber that = (PhoneNumber) o; + return Objects.equals(number, that.number); + } + + @Override + public int hashCode() { + return Objects.hash(number); + } +} diff --git a/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/compareobjects/PersonDiffBuilderUnitTest.java b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/compareobjects/PersonDiffBuilderUnitTest.java new file mode 100644 index 0000000000..417e9da0ea --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/compareobjects/PersonDiffBuilderUnitTest.java @@ -0,0 +1,38 @@ +package com.baeldung.compareobjects; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.builder.Diff; +import org.apache.commons.lang3.builder.DiffResult; +import org.junit.jupiter.api.Test; + +public class PersonDiffBuilderUnitTest { + + @Test + void givenTwoPeopleDifferent_whenComparingWithDiffBuilder_thenDifferencesFound() { + List phoneNumbers1 = new ArrayList<>(); + phoneNumbers1.add(new PhoneNumber("home", "123-456-7890")); + phoneNumbers1.add(new PhoneNumber("work", "987-654-3210")); + + List phoneNumbers2 = new ArrayList<>(); + phoneNumbers2.add(new PhoneNumber("mobile1", "123-456-7890")); + phoneNumbers2.add(new PhoneNumber("mobile2", "987-654-3210")); + + Address address1 = new Address("123 Main St", "London", "12345"); + Address address2 = new Address("123 Main St", "Paris", "54321"); + + Person person1 = new Person("John", "Doe", 30, phoneNumbers1, address1); + Person person2 = new Person("Jane", "Smith", 28, phoneNumbers2, address2); + + DiffResult diff = PersonDiffBuilder.compare(person1, person2); + for (Diff d : diff.getDiffs()) { + System.out.println(d.getFieldName() + ": " + d.getLeft() + " != " + d.getRight()); + } + + assertFalse(diff.getDiffs() + .isEmpty()); + } +} diff --git a/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/compareobjects/PersonReflectionDiffBuilderUnitTest.java b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/compareobjects/PersonReflectionDiffBuilderUnitTest.java new file mode 100644 index 0000000000..fffa56dccc --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/compareobjects/PersonReflectionDiffBuilderUnitTest.java @@ -0,0 +1,37 @@ +package com.baeldung.compareobjects; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.builder.Diff; +import org.apache.commons.lang3.builder.DiffResult; +import org.junit.jupiter.api.Test; + +public class PersonReflectionDiffBuilderUnitTest { + @Test + void givenTwoPeopleDifferent_whenComparingWithReflectionDiffBuilder_thenDifferencesFound() { + List phoneNumbers1 = new ArrayList<>(); + phoneNumbers1.add(new PhoneNumber("home", "123-456-7890")); + phoneNumbers1.add(new PhoneNumber("work", "987-654-3210")); + + List phoneNumbers2 = new ArrayList<>(); + phoneNumbers2.add(new PhoneNumber("mobile1", "123-456-7890")); + phoneNumbers2.add(new PhoneNumber("mobile2", "987-654-3210")); + + Address address1 = new Address("123 Main St", "London", "12345"); + Address address2 = new Address("123 Main St", "Paris", "54321"); + + Person person1 = new Person("John", "Doe", 30, phoneNumbers1, address1); + Person person2 = new Person("Jane", "Smith", 28, phoneNumbers2, address2); + + DiffResult diff = PersonReflectionDiffBuilder.compare(person1, person2); + for (Diff d : diff.getDiffs()) { + System.out.println(d.getFieldName() + ": " + d.getLeft() + " != " + d.getRight()); + } + + assertFalse(diff.getDiffs() + .isEmpty()); + } +} From a0ca4e6438d90a3bc331c4a4c9c9110e11e5f8e5 Mon Sep 17 00:00:00 2001 From: lajka Date: Tue, 5 Sep 2023 19:44:37 +0200 Subject: [PATCH 009/193] BAEL-6871: Remove junit-jupiter-api dependency. --- core-java-modules/core-java-lang-6/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core-java-modules/core-java-lang-6/pom.xml b/core-java-modules/core-java-lang-6/pom.xml index f458456b9f..6561c4fdcc 100644 --- a/core-java-modules/core-java-lang-6/pom.xml +++ b/core-java-modules/core-java-lang-6/pom.xml @@ -23,11 +23,6 @@ commons-lang3 ${commons-lang3.version} - - org.junit.jupiter - junit-jupiter-api - ${junit-jupiter.version} - From 949572f93b940213b616095df74729bfc740cb4f Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Mon, 11 Sep 2023 12:23:34 +0300 Subject: [PATCH 010/193] [JAVA-24600] --- spring-boot-modules/spring-boot-jasypt/pom.xml | 8 -------- .../src/main/resources/application.yml | 6 +----- .../src/main/resources/application.properties | 1 - 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/spring-boot-modules/spring-boot-jasypt/pom.xml b/spring-boot-modules/spring-boot-jasypt/pom.xml index f48cd78595..d62a287e7b 100644 --- a/spring-boot-modules/spring-boot-jasypt/pom.xml +++ b/spring-boot-modules/spring-boot-jasypt/pom.xml @@ -46,14 +46,6 @@ - - - spring-milestone - Spring Milestone - https://repo.spring.io/milestone - - - 2.0.0 diff --git a/spring-cloud-modules/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml b/spring-cloud-modules/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml index 71275793ec..b7cd3e7726 100644 --- a/spring-cloud-modules/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml +++ b/spring-cloud-modules/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml @@ -19,8 +19,4 @@ spring: hibernate: dialect: org.hibernate.dialect.MySQL5Dialect batch: - initialize-schema: always -maven: - remoteRepositories: - springRepo: - url: https://repo.spring.io/libs-snapshot \ No newline at end of file + initialize-schema: always \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-task/springcloudtasksink/src/main/resources/application.properties b/spring-cloud-modules/spring-cloud-task/springcloudtasksink/src/main/resources/application.properties index 1660dc8516..e69de29bb2 100644 --- a/spring-cloud-modules/spring-cloud-task/springcloudtasksink/src/main/resources/application.properties +++ b/spring-cloud-modules/spring-cloud-task/springcloudtasksink/src/main/resources/application.properties @@ -1 +0,0 @@ -maven.remoteRepositories.springRepo.url=https://repo.spring.io/libs-snapshot \ No newline at end of file From 6929fe146925d4e9dafba8e25448739a2c7bd367 Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Fri, 15 Sep 2023 00:04:31 +0530 Subject: [PATCH 011/193] BAEL-6963 BAEL-6963 Changes --- .../multiple/objecttypes/CustomObject.java | 13 ++++++++ .../MultipleObjectTypeArrayList.java | 32 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java create mode 100644 core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java diff --git a/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java b/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java new file mode 100644 index 0000000000..ae30f2bc1c --- /dev/null +++ b/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java @@ -0,0 +1,13 @@ +package com.baeldung.list.multiple.objecttypes; + +public class CustomObject { + String classData; + + CustomObject(String classData) { + this.classData = classData; + } + + public String getClassData() { + return this.classData; + } +} diff --git a/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java b/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java new file mode 100644 index 0000000000..7ce99b7b9d --- /dev/null +++ b/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java @@ -0,0 +1,32 @@ +package com.baeldung.list.multiple.objecttypes; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MultipleObjectTypeArrayList { + + public static void main(String[] args) { + + List multiTypeList = new ArrayList<>(); + multiTypeList.add(Integer.valueOf(10)); + multiTypeList.add(Double.valueOf(11.5)); + multiTypeList.add("String Data"); + multiTypeList.add(Arrays.asList(1, 2, 3)); + multiTypeList.add(new CustomObject("Class Data")); + + for (Object dataObj : multiTypeList) { + if (dataObj instanceof Integer intData) + System.out.println(intData); + if (dataObj instanceof Double doubleData) + System.out.println(doubleData); + if (dataObj instanceof String stringData) + System.out.println(stringData); + if (dataObj instanceof List intList) + System.out.println(intList); + if (dataObj instanceof CustomObject customObj) + System.out.println(customObj.getClassData()); + } + } + +} From b7b167ea1ea0938943919ad1115e56d2f48e395b Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Fri, 15 Sep 2023 18:39:05 +0530 Subject: [PATCH 012/193] Updated output --- .../objecttypes/MultipleObjectTypeArrayList.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java b/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java index 7ce99b7b9d..33537a797f 100644 --- a/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java +++ b/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java @@ -17,15 +17,15 @@ public class MultipleObjectTypeArrayList { for (Object dataObj : multiTypeList) { if (dataObj instanceof Integer intData) - System.out.println(intData); + System.out.println("Integer Data : " + intData); if (dataObj instanceof Double doubleData) - System.out.println(doubleData); + System.out.println("Double Data : " + doubleData); if (dataObj instanceof String stringData) - System.out.println(stringData); + System.out.println("String Data : " + stringData); if (dataObj instanceof List intList) - System.out.println(intList); + System.out.println("List Data : " + intList); if (dataObj instanceof CustomObject customObj) - System.out.println(customObj.getClassData()); + System.out.println("CustomObject Data : " + customObj.getClassData()); } } From 5159e8ab6705908ce1509e47e7caad5422fe2623 Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Fri, 15 Sep 2023 19:48:05 +0530 Subject: [PATCH 013/193] Program Updates --- .../multiple/objecttypes/MultipleObjectTypeArrayList.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java b/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java index 33537a797f..12acc3843b 100644 --- a/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java +++ b/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java @@ -7,8 +7,9 @@ import java.util.List; public class MultipleObjectTypeArrayList { public static void main(String[] args) { - - List multiTypeList = new ArrayList<>(); + + ArrayList multiTypeList = new ArrayList<>(); + multiTypeList.add(Integer.valueOf(10)); multiTypeList.add(Double.valueOf(11.5)); multiTypeList.add("String Data"); From 7b188517e3c9795a9250836472a14a50f36d522e Mon Sep 17 00:00:00 2001 From: parthiv39731 <70740707+parthiv39731@users.noreply.github.com> Date: Fri, 15 Sep 2023 09:20:34 -0700 Subject: [PATCH 014/193] BAEL-6726, Merge Two Arrays and Remove Duplicates in Java --- .../MergeArraysAndRemoveDuplicate.java | 96 +++++++++++++++++++ ...MergeArraysAndRemoveDuplicateUnitTest.java | 74 ++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicate.java create mode 100644 core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicateUnitTest.java diff --git a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicate.java b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicate.java new file mode 100644 index 0000000000..e0b249565f --- /dev/null +++ b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicate.java @@ -0,0 +1,96 @@ +package com.baeldung.mergeandremoveduplicate; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Stream; + +public class MergeArraysAndRemoveDuplicate { + + public static int[] removeDuplicateOnSortedArray(int[] arr) { + // Initialize a new array to store unique elements + int[] uniqueArray = new int[arr.length]; + uniqueArray[0] = arr[0]; + int uniqueCount = 1; + + // Iterate through the sorted array to remove duplicates + for (int i = 1; i < arr.length; i++) { + if (arr[i] != arr[i - 1]) { + uniqueArray[uniqueCount] = arr[i]; + uniqueCount++; + } + } + int[] truncatedArray = new int[uniqueCount]; + System.arraycopy(uniqueArray, 0, truncatedArray, 0, uniqueCount); + return truncatedArray; + } + + public static int[] mergeAndRemoveDuplicatesUsingStream(int[] arr1, int[] arr2) { + Stream s1 = Arrays.stream(arr1).boxed(); + Stream s2 = Arrays.stream(arr2).boxed(); + return Stream.concat(s1, s2) + .distinct() + .mapToInt(Integer::intValue) + .toArray(); + } + + public static int[] mergeAndRemoveDuplicatesUsingSet(int[] arr1, int[] arr2) { + int[] mergedArr = mergeArrays(arr1, arr2); + Set uniqueInts = new HashSet<>(); + + for (int el : mergedArr) { + uniqueInts.add(el); + } + + return getArrayFromSet(uniqueInts); + } + + private static int[] getArrayFromSet(Set set) { + int[] mergedArrWithoutDuplicated = new int[set.size()]; + int i = 0; + for (Integer el: set) { + mergedArrWithoutDuplicated[i] = el; + i++; + } + return mergedArrWithoutDuplicated; + } + + public static int[] mergeAndRemoveDuplicates(int[] arr1, int[] arr2) { + return removeDuplicate(mergeArrays(arr1, arr2)); + } + + public static int[] mergeAndRemoveDuplicatesOnSortedArray(int[] arr1, int[] arr2) { + return removeDuplicateOnSortedArray(mergeArrays(arr1, arr2)); + } + + private static int[] mergeArrays(int[] arr1, int[] arr2) { + int[] mergedArrays = new int[arr1.length + arr2.length]; + System.arraycopy(arr1, 0, mergedArrays, 0, arr1.length); + System.arraycopy(arr2, 0, mergedArrays, arr1.length, arr2.length); + + return mergedArrays; + } + private static int[] removeDuplicate(int[] arr) { + int[] withoutDuplicates = new int[arr.length]; + int i = 0; + + for(int element : arr) { + if(!isElementPresent(withoutDuplicates, element)) { + withoutDuplicates[i] = element; + i++; + } + } + int[] truncatedArray = new int[i]; + System.arraycopy(withoutDuplicates, 0, truncatedArray, 0, i); + return truncatedArray; + } + + private static boolean isElementPresent(int[] arr, int element) { + for(int el : arr) { + if(el == element) { + return true; + } + } + return false; + } +} diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicateUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicateUnitTest.java new file mode 100644 index 0000000000..ce8d69b445 --- /dev/null +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicateUnitTest.java @@ -0,0 +1,74 @@ +package com.baeldung.mergeandremoveduplicate; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + +public class MergeArraysAndRemoveDuplicateUnitTest { + + private final Logger logger = LoggerFactory.getLogger(MergeArraysAndRemoveDuplicateUnitTest.class); + + private static String getCommaDelimited(int[] arr) { + return Arrays.stream(arr) + .mapToObj(Integer::toString) + .collect(Collectors.joining(", ")); + } + + @Test + public void givenNoLibrary_whenArr1andArr2_thenMergeAndRemoveDuplicates() { + int[] arr1 = {3, 2, 1, 4, 5, 6, 8, 7, 9}; + int[] arr2 = {8, 9, 10, 11, 12, 13, 15, 14, 15, 14, 16, 17}; + int[] expectedArr = {3, 2, 1, 4, 5, 6, 8, 7, 9, 10, 11, 12, 13, 15, 14, 16, 17}; + + int[] mergedArr = MergeArraysAndRemoveDuplicate.mergeAndRemoveDuplicates(arr1, arr2); + + //merged array maintains the order of the elements in the arrays + assertArrayEquals(expectedArr, mergedArr); + + logger.info(getCommaDelimited(mergedArr)); + } + + @Test + public void givenNoLibrary_whenArr1andArr2_thenMergeSortAndRemoveDuplicates() { + int[] arr1 = {1, 2, 3, 4, 5, 5, 6, 7, 7, 8}; + int[] arr2 = {8, 9, 10, 11, 12, 13, 14, 15, 15, 16, 17}; + int[] expectedArr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + + int[] mergedArr = MergeArraysAndRemoveDuplicate.mergeAndRemoveDuplicatesOnSortedArray(arr1, arr2); + + assertArrayEquals(expectedArr, mergedArr); + + logger.info(getCommaDelimited(mergedArr)); + } + + @Test + public void givenSet_whenArr1andArr2_thenMergeAndRemoveDuplicates() { + int[] arr1 = {3, 2, 1, 4, 5, 6, 8, 7, 9}; + int[] arr2 = {8, 9, 10, 11, 12, 13, 15, 14, 15, 14, 16, 17}; + int[] expectedArr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + + int[] mergedArr = MergeArraysAndRemoveDuplicate.mergeAndRemoveDuplicatesUsingSet(arr1, arr2); + + assertArrayEquals(expectedArr, mergedArr); + + logger.info(getCommaDelimited(mergedArr)); + } + + @Test + public void givenStream_whenArr1andArr2_thenMergeAndRemoveDuplicates() { + int[] arr1 = {3, 2, 1, 4, 5, 6, 8, 7, 9}; + int[] arr2 = {8, 9, 10, 11, 12, 13, 15, 14, 15, 14, 16, 17}; + int[] expectedArr = {3, 2, 1, 4, 5, 6, 8, 7, 9, 10, 11, 12, 13, 15, 14, 16, 17}; + + int[] mergedArr = MergeArraysAndRemoveDuplicate.mergeAndRemoveDuplicatesUsingStream(arr1, arr2); + + assertArrayEquals(expectedArr, mergedArr); + + logger.info(getCommaDelimited(mergedArr)); + } +} From 2d4d7308ad2b218f2f6fc9dcaa81e6340dd34925 Mon Sep 17 00:00:00 2001 From: parthiv39731 <70740707+parthiv39731@users.noreply.github.com> Date: Fri, 15 Sep 2023 21:26:37 -0700 Subject: [PATCH 015/193] BAEL-6726, modified method names --- .../MergeArraysAndRemoveDuplicateUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicateUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicateUnitTest.java index ce8d69b445..5076ef8159 100644 --- a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicateUnitTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/mergeandremoveduplicate/MergeArraysAndRemoveDuplicateUnitTest.java @@ -20,7 +20,7 @@ public class MergeArraysAndRemoveDuplicateUnitTest { } @Test - public void givenNoLibrary_whenArr1andArr2_thenMergeAndRemoveDuplicates() { + public void givenNoLibraryAndUnSortedArrays_whenArr1andArr2_thenMergeAndRemoveDuplicates() { int[] arr1 = {3, 2, 1, 4, 5, 6, 8, 7, 9}; int[] arr2 = {8, 9, 10, 11, 12, 13, 15, 14, 15, 14, 16, 17}; int[] expectedArr = {3, 2, 1, 4, 5, 6, 8, 7, 9, 10, 11, 12, 13, 15, 14, 16, 17}; @@ -34,7 +34,7 @@ public class MergeArraysAndRemoveDuplicateUnitTest { } @Test - public void givenNoLibrary_whenArr1andArr2_thenMergeSortAndRemoveDuplicates() { + public void givenNoLibraryAndSortedArrays_whenArr1andArr2_thenMergeAndRemoveDuplicates() { int[] arr1 = {1, 2, 3, 4, 5, 5, 6, 7, 7, 8}; int[] arr2 = {8, 9, 10, 11, 12, 13, 14, 15, 15, 16, 17}; int[] expectedArr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; From 149873e7b61cf45a092b6d3b5e94e524062e1854 Mon Sep 17 00:00:00 2001 From: Bipinkumar27 Date: Sun, 17 Sep 2023 17:59:58 +0530 Subject: [PATCH 016/193] JAVA-18763 : Changes made for Update Spring Drools article --- .../drools/config/DroolsBeanFactory.java | 47 +++++++------------ 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/drools/src/main/java/com/baeldung/drools/config/DroolsBeanFactory.java b/drools/src/main/java/com/baeldung/drools/config/DroolsBeanFactory.java index fd2090aecb..386b2ca4a7 100644 --- a/drools/src/main/java/com/baeldung/drools/config/DroolsBeanFactory.java +++ b/drools/src/main/java/com/baeldung/drools/config/DroolsBeanFactory.java @@ -1,8 +1,15 @@ package com.baeldung.drools.config; +import java.util.Arrays; +import java.util.List; + import org.drools.decisiontable.DecisionTableProviderImpl; import org.kie.api.KieServices; -import org.kie.api.builder.*; +import org.kie.api.builder.KieBuilder; +import org.kie.api.builder.KieFileSystem; +import org.kie.api.builder.KieModule; +import org.kie.api.builder.KieRepository; +import org.kie.api.builder.ReleaseId; import org.kie.api.io.Resource; import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; @@ -10,35 +17,19 @@ import org.kie.internal.builder.DecisionTableConfiguration; import org.kie.internal.builder.DecisionTableInputType; import org.kie.internal.builder.KnowledgeBuilderFactory; import org.kie.internal.io.ResourceFactory; -import java.util.Arrays; -import java.util.List; public class DroolsBeanFactory { private static final String RULES_PATH = "com/baeldung/drools/rules/"; private KieServices kieServices = KieServices.Factory.get(); - private KieFileSystem getKieFileSystem() { + private KieFileSystem getKieFileSystem() { KieFileSystem kieFileSystem = kieServices.newKieFileSystem(); - List rules = Arrays.asList("BackwardChaining.drl", "SuggestApplicant.drl", "Product_rules.drl.xls"); - for(String rule:rules) { + List rules = Arrays.asList("com/baeldung/drools/rules/BackwardChaining.drl", "com/baeldung/drools/rules/SuggestApplicant.drl", "com/baeldung/drools/rules/Product_rules.drl.xls"); + for (String rule : rules) { kieFileSystem.write(ResourceFactory.newClassPathResource(rule)); } return kieFileSystem; - - } - - public KieContainer getKieContainer() { - getKieRepository(); - - KieBuilder kb = kieServices.newKieBuilder(getKieFileSystem()); - kb.buildAll(); - - KieModule kieModule = kb.getKieModule(); - KieContainer kContainer = kieServices.newKieContainer(kieModule.getReleaseId()); - - return kContainer; - } private void getKieRepository() { @@ -47,20 +38,14 @@ public class DroolsBeanFactory { } public KieSession getKieSession() { - getKieRepository(); - KieFileSystem kieFileSystem = kieServices.newKieFileSystem(); - - kieFileSystem.write(ResourceFactory.newClassPathResource("com/baeldung/drools/rules/BackwardChaining.drl")); - kieFileSystem.write(ResourceFactory.newClassPathResource("com/baeldung/drools/rules/SuggestApplicant.drl")); - kieFileSystem.write(ResourceFactory.newClassPathResource("com/baeldung/drools/rules/Product_rules.drl.xls")); - - KieBuilder kb = kieServices.newKieBuilder(kieFileSystem); + KieBuilder kb = kieServices.newKieBuilder(getKieFileSystem()); kb.buildAll(); - KieModule kieModule = kb.getKieModule(); - KieContainer kContainer = kieServices.newKieContainer(kieModule.getReleaseId()); + KieRepository kieRepository = kieServices.getRepository(); + ReleaseId krDefaultReleaseId = kieRepository.getDefaultReleaseId(); + KieContainer kieContainer = kieServices.newKieContainer(krDefaultReleaseId); - return kContainer.newKieSession(); + return kieContainer.newKieSession(); } public KieSession getKieSession(Resource dt) { From 829593380b9ee3c19d248396c2668e70e29a9bf5 Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Mon, 18 Sep 2023 12:34:20 +0300 Subject: [PATCH 017/193] [JAVA-22209] Upgraded spring-cloud-zuul-eureka-integration module to jdk17 + fixed tests in spring-cloud-archaius module --- pom.xml | 4 +++- spring-cloud-modules/pom.xml | 2 +- .../spring-cloud-archaius/pom.xml | 4 +++- .../pom.xml | 3 ++- .../pom.xml | 16 ++++++++++++++++ .../spring-cloud-archaius-jdbc-config/pom.xml | 9 +++++++++ .../spring-cloud-stream-starters/pom.xml | 3 +-- .../eureka-client/pom.xml | 18 ++++++++++++++++++ .../eureka-server/pom.xml | 18 ++++++++++++++++++ .../zuul-server/pom.xml | 18 ++++++++++++++++++ 10 files changed, 89 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index c65f6ce62d..86d7d3328c 100644 --- a/pom.xml +++ b/pom.xml @@ -726,6 +726,7 @@ spring-cloud-modules/spring-cloud-contract spring-cloud-modules/spring-cloud-data-flow spring-cloud-modules/spring-cloud-circuit-breaker + spring-cloud-modules/spring-cloud-zuul-eureka-integration spring-exceptions spring-jenkins-pipeline spring-core @@ -999,6 +1000,8 @@ spring-drools spring-cloud-modules/spring-cloud-azure spring-cloud-modules/spring-cloud-circuit-breaker + spring-cloud-modules/spring-cloud-contract + spring-cloud-modules/spring-cloud-zuul-eureka-integration spring-exceptions spring-jenkins-pipeline spring-core @@ -1210,7 +1213,6 @@ gradle-modules/gradle/maven-to-gradle persistence-modules/spring-data-neo4j spring-actuator - spring-cloud-modules/spring-cloud-contract diff --git a/spring-cloud-modules/pom.xml b/spring-cloud-modules/pom.xml index 9c926bbe61..73276d7e0f 100644 --- a/spring-cloud-modules/pom.xml +++ b/spring-cloud-modules/pom.xml @@ -31,7 +31,7 @@ spring-cloud-connectors-heroku spring-cloud-aws spring-cloud-consul - spring-cloud-zuul-eureka-integration + spring-cloud-kubernetes spring-cloud-open-service-broker diff --git a/spring-cloud-modules/spring-cloud-archaius/pom.xml b/spring-cloud-modules/spring-cloud-archaius/pom.xml index 4d7ca3943d..3e90c7390c 100644 --- a/spring-cloud-modules/spring-cloud-archaius/pom.xml +++ b/spring-cloud-modules/spring-cloud-archaius/pom.xml @@ -40,6 +40,7 @@ org.springframework.cloud spring-cloud-starter-netflix-archaius + ${spring-cloud-starter-netflix-archaius.version} org.springframework.boot @@ -54,7 +55,8 @@ - 2.0.3.RELEASE + 2.2.10.RELEASE + 2.2.10.RELEASE \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-dynamodb-config/pom.xml b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-dynamodb-config/pom.xml index 6e25ace6a8..600fedc774 100644 --- a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-dynamodb-config/pom.xml +++ b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-dynamodb-config/pom.xml @@ -36,7 +36,7 @@ org.projectlombok lombok - provided + ${lombok.version} @@ -44,6 +44,7 @@ 1.11.407 5.0.3 0.7.6 + 1.18.26 \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-extra-configs/pom.xml b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-extra-configs/pom.xml index f90570abc2..383ad6a780 100644 --- a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-extra-configs/pom.xml +++ b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-extra-configs/pom.xml @@ -37,6 +37,22 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + + + + + + 2.0.1.RELEASE diff --git a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-jdbc-config/pom.xml b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-jdbc-config/pom.xml index 7fb5747739..2871f129b5 100644 --- a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-jdbc-config/pom.xml +++ b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-jdbc-config/pom.xml @@ -27,6 +27,15 @@ h2 runtime + + org.projectlombok + lombok + ${lombok.version} + + + 1.18.26 + + \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-stream-starters/pom.xml b/spring-cloud-modules/spring-cloud-stream-starters/pom.xml index eee5b27396..95176d1e5c 100644 --- a/spring-cloud-modules/spring-cloud-stream-starters/pom.xml +++ b/spring-cloud-modules/spring-cloud-stream-starters/pom.xml @@ -3,7 +3,6 @@ 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"> 4.0.0 - com.baeldung.spring.cloud spring-cloud-stream-starters 1.0.0-SNAPSHOT spring-cloud-stream-starters @@ -32,7 +31,7 @@ - 2021.0.0 + 2022.0.4 \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml b/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml index 3960cfde5d..46b3e7047f 100644 --- a/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml +++ b/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml @@ -53,6 +53,24 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + --add-opens java.base/java.text=ALL-UNNAMED + --add-opens java.desktop/java.awt.font=ALL-UNNAMED + + + + + + 2.17.1 diff --git a/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml b/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml index c9bc120e4d..796b908bca 100644 --- a/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml +++ b/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml @@ -53,6 +53,24 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + --add-opens java.base/java.text=ALL-UNNAMED + --add-opens java.desktop/java.awt.font=ALL-UNNAMED + + + + + + 2.17.1 diff --git a/spring-cloud-modules/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml b/spring-cloud-modules/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml index 76d899447f..11cc992523 100644 --- a/spring-cloud-modules/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml +++ b/spring-cloud-modules/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml @@ -61,6 +61,24 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + --add-opens java.base/java.text=ALL-UNNAMED + --add-opens java.desktop/java.awt.font=ALL-UNNAMED + + + + + + 2.17.1 From 808502520e57bbf87ae639da04a164f85cb9bc5c Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Tue, 19 Sep 2023 12:11:51 +0300 Subject: [PATCH 018/193] [JAVA-24600] Upgraded jasypt version to 3.0.5 --- spring-boot-modules/spring-boot-jasypt/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-modules/spring-boot-jasypt/pom.xml b/spring-boot-modules/spring-boot-jasypt/pom.xml index d62a287e7b..70bbe35319 100644 --- a/spring-boot-modules/spring-boot-jasypt/pom.xml +++ b/spring-boot-modules/spring-boot-jasypt/pom.xml @@ -27,7 +27,7 @@ com.github.ulisesbocchio - jasypt-spring-boot-starter + jasypt-spring-boot-starter ${jasypt.version} @@ -47,6 +47,6 @@ - 2.0.0 + 3.0.5 \ No newline at end of file From 5bcbd9dc00a3ff68c34ad0c3bbcce9c60c56b472 Mon Sep 17 00:00:00 2001 From: timis1 <12120641+timis1@users.noreply.github.com> Date: Tue, 19 Sep 2023 15:38:32 +0300 Subject: [PATCH 019/193] JAVA-24237 Update "Spring Data MongoDB" article (#14772) Co-authored-by: timis1 --- .../spring-data-mongodb/pom.xml | 44 +++---------------- .../MongoTransactionTemplateLiveTest.java | 1 + .../MongoTransactionalLiveTest.java | 1 + 3 files changed, 8 insertions(+), 38 deletions(-) diff --git a/persistence-modules/spring-data-mongodb/pom.xml b/persistence-modules/spring-data-mongodb/pom.xml index 87cf1acaf8..a59fcff3d9 100644 --- a/persistence-modules/spring-data-mongodb/pom.xml +++ b/persistence-modules/spring-data-mongodb/pom.xml @@ -8,31 +8,19 @@ com.baeldung - parent-spring-5 + parent-boot-2 0.0.1-SNAPSHOT - ../../parent-spring-5 + ../../parent-boot-2 - org.springframework.data - spring-data-mongodb - ${org.springframework.data.version} + org.springframework.boot + spring-boot-starter-data-mongodb - org.mongodb - mongodb-driver-sync - ${mongodb-driver.version} - - - org.mongodb - mongodb-driver-reactivestreams - ${mongodb-reactivestreams.version} - - - io.projectreactor - reactor-core - ${projectreactor.version} + org.springframework.boot + spring-boot-starter-data-mongodb-reactive io.projectreactor @@ -40,23 +28,6 @@ ${projectreactor.version} test - - org.springframework - spring-core - ${spring.version} - - - commons-logging - commons-logging - - - - - org.springframework - spring-test - ${spring.version} - test - com.querydsl querydsl-mongodb @@ -103,12 +74,9 @@ - 3.4.7 5.0.0 1.1.3 - 4.1.0 3.5.4 - 4.6.1 4.6.3 diff --git a/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/transaction/MongoTransactionTemplateLiveTest.java b/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/transaction/MongoTransactionTemplateLiveTest.java index 53b2c7a0e7..a53dfc6663 100644 --- a/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/transaction/MongoTransactionTemplateLiveTest.java +++ b/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/transaction/MongoTransactionTemplateLiveTest.java @@ -28,6 +28,7 @@ import com.baeldung.model.User; * * This test requires: * * mongodb instance running on the environment + * Run the src/live-test/resources/live-test-setup.sh * */ @RunWith(SpringJUnit4ClassRunner.class) diff --git a/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/transaction/MongoTransactionalLiveTest.java b/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/transaction/MongoTransactionalLiveTest.java index d92296beab..adc31ffea2 100644 --- a/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/transaction/MongoTransactionalLiveTest.java +++ b/persistence-modules/spring-data-mongodb/src/test/java/com/baeldung/transaction/MongoTransactionalLiveTest.java @@ -26,6 +26,7 @@ import com.baeldung.repository.UserRepository; * * This test requires: * * mongodb instance running on the environment + * Run the src/live-test/resources/live-test-setup.sh * */ @RunWith(SpringJUnit4ClassRunner.class) From 556002e8d18f0dd0c6d913909136c40b0db36b0c Mon Sep 17 00:00:00 2001 From: Hangga Aji Sayekti Date: Tue, 19 Sep 2023 19:53:41 +0700 Subject: [PATCH 020/193] EOF Detection | bazeniancode@gmail.com | Hangga Aji Sayekti (#14738) * [Add] add from my experiment repo github.com/hangga/eof-detection * [Update] reorder test * [Update] add close() * [Update] try with resource * [update] be careful with typo --- .../baeldung/eofdetections/EOFDetection.java | 60 ++++++++++++++ .../eofdetections/EOFDetectionUnitTest.java | 80 +++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 core-java-modules/core-java-io-apis-2/src/main/java/com/baeldung/eofdetections/EOFDetection.java create mode 100644 core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/eofdetections/EOFDetectionUnitTest.java diff --git a/core-java-modules/core-java-io-apis-2/src/main/java/com/baeldung/eofdetections/EOFDetection.java b/core-java-modules/core-java-io-apis-2/src/main/java/com/baeldung/eofdetections/EOFDetection.java new file mode 100644 index 0000000000..c6302a3fc9 --- /dev/null +++ b/core-java-modules/core-java-io-apis-2/src/main/java/com/baeldung/eofdetections/EOFDetection.java @@ -0,0 +1,60 @@ +package com.baeldung.eofdetections; + +import java.io.*; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.charset.StandardCharsets; +import java.util.*; + +public class EOFDetection { + + public String readWithFileInputStream(String pathFile) throws IOException { + try (FileInputStream fis = new FileInputStream(pathFile); + ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + int data; + while ((data = fis.read()) != -1) { + baos.write(data); + } + return baos.toString(); + } + } + + public String readWithBufferedReader(String pathFile) throws IOException { + try (FileInputStream fis = new FileInputStream(pathFile); + InputStreamReader isr = new InputStreamReader(fis); + BufferedReader reader = new BufferedReader(isr)) { + StringBuilder actualContent = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + actualContent.append(line); + } + return actualContent.toString(); + } + } + + public String readWithScanner(String pathFile) throws IOException { + File file = new File(pathFile); + Scanner scanner = new Scanner(file); + StringBuilder actualContent = new StringBuilder(); + while (scanner.hasNext()) { + String line = scanner.nextLine(); + actualContent.append(line); + } + scanner.close(); + return actualContent.toString(); + } + + public String readFileWithFileChannelAndByteBuffer(String pathFile) throws IOException { + try (FileInputStream fis = new FileInputStream(pathFile); + FileChannel channel = fis.getChannel()) { + + ByteBuffer buffer = ByteBuffer.allocate((int) channel.size()); + while (channel.read(buffer) != -1) { + buffer.flip(); + buffer.clear(); + } + return StandardCharsets.UTF_8.decode(buffer).toString(); + } + } +} + diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/eofdetections/EOFDetectionUnitTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/eofdetections/EOFDetectionUnitTest.java new file mode 100644 index 0000000000..525b242bf9 --- /dev/null +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/eofdetections/EOFDetectionUnitTest.java @@ -0,0 +1,80 @@ +package com.baeldung.eofdetections; + +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class EOFDetectionUnitTest { + + static final String LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum"; + String pathToFile = "sample.txt"; // init sample file path + EOFDetection eofDetection = new EOFDetection(); + @Test + @Order(1) + public void givenDummyText_whenReadWithFileInputStream_returnText() { + try { + String actualText = eofDetection.readWithFileInputStream(pathToFile); + assertEquals(LOREM_IPSUM, actualText); + } catch (IOException e) { + fail(e.getMessage()); + } + } + + @Test + @Order(2) + public void givenDummyText_whenReadFileWithBufferedReader_returnText() { + try { + String actualText = eofDetection.readWithBufferedReader(pathToFile); + assertEquals(LOREM_IPSUM, actualText); + } catch (IOException e) { + fail(e.getMessage()); + } + } + + @Test + @Order(3) + public void givenDummyText_whenReadFileWithScanner_returnText() { + try { + String actualText = eofDetection.readWithScanner(pathToFile); + assertEquals(LOREM_IPSUM, actualText); + } catch (IOException e) { + fail(e.getMessage()); + } + } + + @Test + @Order(4) + public void givenDummyText_whenReadFileWithFileChannelAndByteBuffer_returnText() { + try { + String actualText = eofDetection.readFileWithFileChannelAndByteBuffer(pathToFile); + assertEquals(LOREM_IPSUM, actualText); + } catch (IOException e) { + fail(e.getMessage()); + } + } + @Test + @Order(0) + public void prepareFileForTest() { + File file = new File(pathToFile); + + if (!file.exists()) { + try { + file.createNewFile(); + FileWriter writer = new FileWriter(file); + writer.write(LOREM_IPSUM); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} From da0beaeee0af95bec423a6979169e523ead13e4a Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Tue, 19 Sep 2023 21:25:59 +0530 Subject: [PATCH 021/193] Restructuring to new module Restructuring to new module --- .../README.md | 6 +++ .../pom.xml | 38 +++++++++++++++++++ .../multiple/objecttypes/CustomObject.java | 0 .../MultipleObjectTypeArrayList.java | 21 ++++++---- core-java-modules/pom.xml | 1 + 5 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 core-java-modules/core-java-collections-array-list-2/README.md create mode 100644 core-java-modules/core-java-collections-array-list-2/pom.xml rename core-java-modules/{core-java-collections-array-list => core-java-collections-array-list-2}/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java (100%) rename core-java-modules/{core-java-collections-array-list => core-java-collections-array-list-2}/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java (59%) diff --git a/core-java-modules/core-java-collections-array-list-2/README.md b/core-java-modules/core-java-collections-array-list-2/README.md new file mode 100644 index 0000000000..feef70a6dc --- /dev/null +++ b/core-java-modules/core-java-collections-array-list-2/README.md @@ -0,0 +1,6 @@ +## Core Java Collections ArrayList + +This module contains articles about the Java ArrayList collection + +### Relevant Articles: +- [Create an ArrayList with Multiple Object Types](https://drafts.baeldung.com/create-an-arraylist-with-multiple-object-types/) \ No newline at end of file diff --git a/core-java-modules/core-java-collections-array-list-2/pom.xml b/core-java-modules/core-java-collections-array-list-2/pom.xml new file mode 100644 index 0000000000..b0622368ad --- /dev/null +++ b/core-java-modules/core-java-collections-array-list-2/pom.xml @@ -0,0 +1,38 @@ + + 4.0.0 + core-java-collections-array-list-2 + core-java-collections-array-list-2 + jar + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${maven-compiler-plugin.source} + ${maven-compiler-plugin.target} + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + + --add-opens java.base/java.util=ALL-UNNAMED + + + + + + + 16 + 16 + 3.0.0-M3 + + \ No newline at end of file diff --git a/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java similarity index 100% rename from core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java rename to core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java diff --git a/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java similarity index 59% rename from core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java rename to core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java index 12acc3843b..34610785cb 100644 --- a/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java @@ -1,5 +1,7 @@ package com.baeldung.list.multiple.objecttypes; +import java.math.BigInteger; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -7,27 +9,32 @@ import java.util.List; public class MultipleObjectTypeArrayList { public static void main(String[] args) { - + ArrayList multiTypeList = new ArrayList<>(); - + multiTypeList.add(Integer.valueOf(10)); multiTypeList.add(Double.valueOf(11.5)); multiTypeList.add("String Data"); multiTypeList.add(Arrays.asList(1, 2, 3)); multiTypeList.add(new CustomObject("Class Data")); + multiTypeList.add(BigInteger.valueOf(123456789)); + multiTypeList.add(LocalDate.of(2023, 9, 19)); for (Object dataObj : multiTypeList) { if (dataObj instanceof Integer intData) System.out.println("Integer Data : " + intData); - if (dataObj instanceof Double doubleData) + else if (dataObj instanceof Double doubleData) System.out.println("Double Data : " + doubleData); - if (dataObj instanceof String stringData) + else if (dataObj instanceof String stringData) System.out.println("String Data : " + stringData); - if (dataObj instanceof List intList) + else if (dataObj instanceof List intList) System.out.println("List Data : " + intList); - if (dataObj instanceof CustomObject customObj) + else if (dataObj instanceof CustomObject customObj) System.out.println("CustomObject Data : " + customObj.getClassData()); + else if (dataObj instanceof BigInteger bigIntData) + System.out.println("BigInteger Data : " + bigIntData); + else if (dataObj instanceof LocalDate localDate) + System.out.println("LocalDate Data : " + localDate.toString()); } } - } diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index e9285eaf1e..88797a1bf3 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -177,6 +177,7 @@ core-java-collections-maps-6 core-java-records core-java-9-jigsaw + core-java-collections-array-list-2 From 2e58e30ffa7490fa11cbd6c553893df00c0f5e70 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Tue, 19 Sep 2023 18:51:33 +0200 Subject: [PATCH 022/193] BAEL-6221 Get Mocks from MockedConstruction in Mockito (#14776) Co-authored-by: jcook02 --- .../baeldung/construction/CoffeeMachine.java | 23 ++++++++ .../java/com/baeldung/construction/Fruit.java | 12 ++++ .../com/baeldung/construction/Grinder.java | 19 +++++++ .../com/baeldung/construction/WaterTank.java | 27 +++++++++ .../construction/CoffeeMachineUnitTest.java | 56 +++++++++++++++++++ .../baeldung/construction/FruitUnitTest.java | 50 +++++++++++++++++ 6 files changed, 187 insertions(+) create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/construction/CoffeeMachine.java create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/construction/Fruit.java create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/construction/Grinder.java create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/construction/WaterTank.java create mode 100644 testing-modules/mockito-2/src/test/java/com/baeldung/construction/CoffeeMachineUnitTest.java create mode 100644 testing-modules/mockito-2/src/test/java/com/baeldung/construction/FruitUnitTest.java diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/construction/CoffeeMachine.java b/testing-modules/mockito-2/src/main/java/com/baeldung/construction/CoffeeMachine.java new file mode 100644 index 0000000000..5cf1d4eecb --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/construction/CoffeeMachine.java @@ -0,0 +1,23 @@ +package com.baeldung.construction; + +public class CoffeeMachine { + + private Grinder grinder; + private WaterTank tank; + + public CoffeeMachine() { + this.grinder = new Grinder(); + this.tank = new WaterTank(); + } + + public CoffeeMachine(int mils) { + this.grinder = new Grinder(); + this.tank = new WaterTank(mils); + } + + public String makeCoffee() { + String type = this.tank.isEspresso() ? "Espresso" : "Americano"; + return String.format("Finished making a delicious %s made with %s beans", type, this.grinder.getBeans()); + } + +} diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/construction/Fruit.java b/testing-modules/mockito-2/src/main/java/com/baeldung/construction/Fruit.java new file mode 100644 index 0000000000..c63f28d25f --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/construction/Fruit.java @@ -0,0 +1,12 @@ +package com.baeldung.construction; + +public class Fruit { + + public String getName() { + return "Apple"; + } + + public String getColour() { + return "Red"; + } +} diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/construction/Grinder.java b/testing-modules/mockito-2/src/main/java/com/baeldung/construction/Grinder.java new file mode 100644 index 0000000000..e62b690bb2 --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/construction/Grinder.java @@ -0,0 +1,19 @@ +package com.baeldung.construction; + +public class Grinder { + + private String beans; + + public Grinder() { + this.beans = "Guatemalan"; + } + + public String getBeans() { + return beans; + } + + public void setBeans(String beans) { + this.beans = beans; + } + +} \ No newline at end of file diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/construction/WaterTank.java b/testing-modules/mockito-2/src/main/java/com/baeldung/construction/WaterTank.java new file mode 100644 index 0000000000..bf744930a0 --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/construction/WaterTank.java @@ -0,0 +1,27 @@ +package com.baeldung.construction; + +public class WaterTank { + + private int mils; + + public WaterTank() { + this.mils = 25; + } + + public WaterTank(int mils) { + this.mils = mils; + } + + public int getMils() { + return mils; + } + + public void setMils(int mils) { + this.mils = mils; + } + + public boolean isEspresso() { + return getMils() < 50; + } + +} diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/construction/CoffeeMachineUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/construction/CoffeeMachineUnitTest.java new file mode 100644 index 0000000000..7b93ad9db6 --- /dev/null +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/construction/CoffeeMachineUnitTest.java @@ -0,0 +1,56 @@ +package com.baeldung.construction; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.mockConstruction; +import static org.mockito.Mockito.when; + +import org.junit.jupiter.api.Test; +import org.mockito.MockedConstruction; + +class CoffeeMachineUnitTest { + + @Test + void givenNoMockedContructor_whenCoffeeMade_thenRealDependencyReturned() { + CoffeeMachine machine = new CoffeeMachine(); + assertEquals("Finished making a delicious Espresso made with Guatemalan beans", machine.makeCoffee()); + } + + @Test + void givenMockedContructor_whenCoffeeMade_thenMockDependencyReturned() { + try (MockedConstruction mockTank = mockConstruction(WaterTank.class); MockedConstruction mockGrinder = mockConstruction(Grinder.class)) { + + CoffeeMachine machine = new CoffeeMachine(); + + WaterTank tank = mockTank.constructed() + .get(0); + Grinder grinder = mockGrinder.constructed() + .get(0); + + when(tank.isEspresso()).thenReturn(false); + when(grinder.getBeans()).thenReturn("Peruvian"); + + assertEquals("Finished making a delicious Americano made with Peruvian beans", machine.makeCoffee()); + } + + } + + @Test + void givenMockedContructorWithArgument_whenCoffeeMade_thenMockDependencyReturned() { + try (MockedConstruction mockTank = mockConstruction(WaterTank.class, (mock, context) -> { + int mils = (int) context.arguments().get(0); + when(mock.getMils()).thenReturn(mils); + }); + MockedConstruction mockGrinder = mockConstruction(Grinder.class)) { + + CoffeeMachine machine = new CoffeeMachine(100); + + Grinder grinder = mockGrinder.constructed() + .get(0); + + when(grinder.getBeans()).thenReturn("Kenyan"); + assertEquals("Finished making a delicious Americano made with Kenyan beans", machine.makeCoffee()); + } + + } + +} diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/construction/FruitUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/construction/FruitUnitTest.java new file mode 100644 index 0000000000..c7baa1cc7d --- /dev/null +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/construction/FruitUnitTest.java @@ -0,0 +1,50 @@ +package com.baeldung.construction; + +import org.junit.jupiter.api.Test; +import org.mockito.Answers; +import org.mockito.MockedConstruction; + +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.withSettings; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; + +import static org.mockito.Mockito.mockConstruction; + +class FruitUnitTest { + + @Test + void givenMockedContructor_whenFruitCreated_thenMockIsReturned() { + assertEquals("Apple", new Fruit().getName()); + assertEquals("Red", new Fruit().getColour()); + + try (MockedConstruction mock = mockConstruction(Fruit.class)) { + + Fruit fruit = new Fruit(); + when(fruit.getName()).thenReturn("Banana"); + when(fruit.getColour()).thenReturn("Yellow"); + + assertEquals("Banana", fruit.getName()); + assertEquals("Yellow", fruit.getColour()); + + List constructed = mock.constructed(); + assertEquals(1, constructed.size()); + } + } + + @Test + void givenMockedContructorWithNewDefaultAnswer_whenFruitCreated_thenRealMethodInvoked() { + try (MockedConstruction mock = mockConstruction(Fruit.class, withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS))) { + + Fruit fruit = new Fruit(); + + assertEquals("Apple", fruit.getName()); + assertEquals("Red", fruit.getColour()); + + List constructed = mock.constructed(); + assertEquals(1, constructed.size()); + } + } + +} From 50515d3070194f66ad493a7b560b89f50bafb6ca Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Tue, 19 Sep 2023 23:39:38 +0530 Subject: [PATCH 023/193] Additional Approach Changes --- .../AlternativeMultipeTypeList.java | 46 +++++++++++++++++++ .../multiple/objecttypes/CustomObject.java | 10 ++++ .../objecttypes/UserFunctionalInterface.java | 18 ++++++++ 3 files changed, 74 insertions(+) create mode 100644 core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java create mode 100644 core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/UserFunctionalInterface.java diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java new file mode 100644 index 0000000000..ddef57e41c --- /dev/null +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java @@ -0,0 +1,46 @@ +package com.baeldung.list.multiple.objecttypes; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.function.Predicate; + +public class AlternativeMultipeTypeList { + + public static void main(String[] args) { + // List of Numbers + ArrayList myList = new ArrayList<>(); + myList.add(1.2); + myList.add(2); + myList.add(-3.5); + + // List of Map + ArrayList diffMapList = new ArrayList<>(); + diffMapList.add(new HashMap<>()); + diffMapList.add(new TreeMap<>()); + diffMapList.add(new LinkedHashMap<>()); + + ArrayList objList = new ArrayList<>(); + objList.add(new CustomObject("obj1", 1)); + objList.add(new CustomObject("obj2", 2)); + + List dataList = new ArrayList<>(); + + Predicate myPricate = inputData -> (inputData instanceof String || inputData instanceof Integer); + + UserFunctionalInterface myInterface = (listObj, data) -> { + if (myPricate.test(data)) + listObj.add(data); + return listObj; + }; + + myInterface.addToList(dataList, Integer.valueOf(2)); + myInterface.addToList(dataList, Double.valueOf(3.33)); + myInterface.addToList(dataList, "String Value"); + myInterface.printList(dataList); + } + +} diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java index ae30f2bc1c..f4d4be989d 100644 --- a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java @@ -2,12 +2,22 @@ package com.baeldung.list.multiple.objecttypes; public class CustomObject { String classData; + Integer intData; CustomObject(String classData) { this.classData = classData; } + CustomObject(String classData, Integer intData) { + this.classData = classData; + this.intData = intData; + } + public String getClassData() { return this.classData; } + + public Integer getIntData() { + return this.intData; + } } diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/UserFunctionalInterface.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/UserFunctionalInterface.java new file mode 100644 index 0000000000..7e39d5a152 --- /dev/null +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/UserFunctionalInterface.java @@ -0,0 +1,18 @@ +package com.baeldung.list.multiple.objecttypes; + +import java.util.List; + +@FunctionalInterface +public interface UserFunctionalInterface { + + List addToList(List list, Object data); + + default void printList(List dataList) { + for (Object data : dataList) { + if (data instanceof String stringData) + System.out.println("String Data: " + stringData); + if (data instanceof Integer intData) + System.out.println("Integer Data: " + intData); + } + } +} From 0f425a457365e2829a289142c3dd31f2e8e8954b Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Tue, 19 Sep 2023 23:45:25 +0530 Subject: [PATCH 024/193] Updated comments --- .../multiple/objecttypes/AlternativeMultipeTypeList.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java index ddef57e41c..d80f4627d3 100644 --- a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java @@ -11,22 +11,24 @@ import java.util.function.Predicate; public class AlternativeMultipeTypeList { public static void main(String[] args) { - // List of Numbers + // List of Parent Class ArrayList myList = new ArrayList<>(); myList.add(1.2); myList.add(2); myList.add(-3.5); - // List of Map + // List of Interface type ArrayList diffMapList = new ArrayList<>(); diffMapList.add(new HashMap<>()); diffMapList.add(new TreeMap<>()); diffMapList.add(new LinkedHashMap<>()); + // List of Custom Object ArrayList objList = new ArrayList<>(); objList.add(new CustomObject("obj1", 1)); objList.add(new CustomObject("obj2", 2)); + // List via Functional Interface List dataList = new ArrayList<>(); Predicate myPricate = inputData -> (inputData instanceof String || inputData instanceof Integer); From 030f308c5b922f5f3f7ed3b6508fa03a9e6a6c20 Mon Sep 17 00:00:00 2001 From: rajatgarg Date: Wed, 20 Sep 2023 00:36:33 +0530 Subject: [PATCH 025/193] Use ContentType to fetch the extensions --- .../baeldung/extension/ExtensionFromMimeTypeUnitTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java index f8f42861cc..2238cfcafa 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java +++ b/core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java @@ -14,7 +14,7 @@ import org.apache.tika.mime.MimeTypeException; import org.junit.Test; -import com.j256.simplemagic.ContentInfo; +import com.j256.simplemagic.ContentType; public class ExtensionFromMimeTypeUnitTest { private static final String IMAGE_JPEG_MIME_TYPE = "image/jpeg"; @@ -39,8 +39,7 @@ public class ExtensionFromMimeTypeUnitTest { @Test public void whenUsingMimetypesFileTypeMap_thenGetFileExtension() { List expectedExtensions = Arrays.asList("jpeg", "jpg", "jpe"); - ContentInfo contentInfo = new ContentInfo("", IMAGE_JPEG_MIME_TYPE, "", true); - String[] detectedExtensions = contentInfo.getFileExtensions(); + String[] detectedExtensions = ContentType.fromMimeType(IMAGE_JPEG_MIME_TYPE).getFileExtensions(); assertThat(detectedExtensions).containsExactlyElementsOf(expectedExtensions); } From 4ce8b0e70a341783254dcbb718841742f4b47409 Mon Sep 17 00:00:00 2001 From: mcasari Date: Tue, 19 Sep 2023 21:53:05 +0200 Subject: [PATCH 026/193] Test cases for float to BigDecimal conversion - first commit --- convert-float-to-bigdecimal/README.md | 7 +++ convert-float-to-bigdecimal/pom.xml | 16 +++++++ .../src/main/resources/logback.xml | 14 ++++++ .../ConvertFloatToBigDecimalUnitTest.java | 48 +++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 convert-float-to-bigdecimal/README.md create mode 100644 convert-float-to-bigdecimal/pom.xml create mode 100644 convert-float-to-bigdecimal/src/main/resources/logback.xml create mode 100644 convert-float-to-bigdecimal/src/test/java/com/baeldung/convertfloattobigdecimal/ConvertFloatToBigDecimalUnitTest.java diff --git a/convert-float-to-bigdecimal/README.md b/convert-float-to-bigdecimal/README.md new file mode 100644 index 0000000000..e01c981831 --- /dev/null +++ b/convert-float-to-bigdecimal/README.md @@ -0,0 +1,7 @@ +## Shallow vs Deep Copy + +This module contains an article about converting float to BigDecimal in Java + +### Relevant articles: + +- [Converting from Float to BigDecimal in Java](https://drafts.baeldung.com/?p=175240&preview=true) diff --git a/convert-float-to-bigdecimal/pom.xml b/convert-float-to-bigdecimal/pom.xml new file mode 100644 index 0000000000..8fa20b300f --- /dev/null +++ b/convert-float-to-bigdecimal/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + convert-float-to-bigdecimal + convert-float-to-bigdecimal + jar + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + \ No newline at end of file diff --git a/convert-float-to-bigdecimal/src/main/resources/logback.xml b/convert-float-to-bigdecimal/src/main/resources/logback.xml new file mode 100644 index 0000000000..830ab22727 --- /dev/null +++ b/convert-float-to-bigdecimal/src/main/resources/logback.xml @@ -0,0 +1,14 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/convert-float-to-bigdecimal/src/test/java/com/baeldung/convertfloattobigdecimal/ConvertFloatToBigDecimalUnitTest.java b/convert-float-to-bigdecimal/src/test/java/com/baeldung/convertfloattobigdecimal/ConvertFloatToBigDecimalUnitTest.java new file mode 100644 index 0000000000..c43d2ab87a --- /dev/null +++ b/convert-float-to-bigdecimal/src/test/java/com/baeldung/convertfloattobigdecimal/ConvertFloatToBigDecimalUnitTest.java @@ -0,0 +1,48 @@ +package com.baeldung.convertfloattobigdecimal; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import java.math.BigDecimal; + +import org.junit.jupiter.api.Test; + +class ConvertFloatToBigDecimalUnitTest { + + @Test + public void whenFloatComparedWithDifferentValues_thenCouldMatch() { + assertNotEquals(1.1f, 1.09f); + assertEquals(1.1f, 1.09999999f); + } + + @Test + public void whenCreatedFromFloat_thenCouldNotMatch() { + float floatToConvert = 0.5f; + BigDecimal bdFromFloat = new BigDecimal(floatToConvert); + assertEquals("0.5", bdFromFloat.toString()); + floatToConvert = 1.1f; + bdFromFloat = new BigDecimal(floatToConvert); + assertNotEquals("1.1", bdFromFloat.toString()); + } + + @Test + public void whenCreatedFromString_thenMatches() { + String floatValue = Float.toString(1.1f); + BigDecimal bdFromString = new BigDecimal(floatValue); + assertEquals("1.1", bdFromString.toString()); + } + + @Test + public void whenCreatedByValueOfAndIsFloat_thenDoesNotMatch() { + float floatToConvert = 1.1f; + BigDecimal bdByValueOf = BigDecimal.valueOf(floatToConvert); + assertNotEquals("1.1", bdByValueOf.toString()); + } + + @Test + public void whenCreatedByValueOfAndIsDouble_thenMatches() { + double doubleToConvert = 1.1d; + BigDecimal bdByValueOf = BigDecimal.valueOf(doubleToConvert); + assertEquals("1.1", bdByValueOf.toString()); + } +} From 52d10c1c4a3c59c33e8107a4ad3b9b6fef58b342 Mon Sep 17 00:00:00 2001 From: Alexander Molochko Date: Tue, 19 Sep 2023 21:19:31 -0600 Subject: [PATCH 027/193] BAEL-6866: Securing Spring Boot 3 Applications with SSL Bundles (#14725) * BAEL-6866: Securing Spring Boot 3 Applications with SSL Bundles * [bael-6866] Fix review issues --- .../spring-boot-ssl-bundles/README.md | 1 + .../spring-boot-ssl-bundles/pom.xml | 56 ++++++++++++++++++ .../springbootsslbundles/SSLBundlesApp.java | 19 ++++++ .../SecureRestTemplateConfig.java | 38 ++++++++++++ .../SecureServiceRestApi.java | 28 +++++++++ .../src/main/resources/application.yml | 11 ++++ .../src/main/resources/cert.pem | 31 ++++++++++ .../src/main/resources/key.pem | 54 +++++++++++++++++ .../src/main/resources/keystore.p12 | Bin 0 -> 4242 bytes .../src/main/resources/static/index.html | 13 ++++ .../SSLBundleApplicationTests.java | 12 ++++ 11 files changed, 263 insertions(+) create mode 100644 spring-boot-modules/spring-boot-ssl-bundles/README.md create mode 100644 spring-boot-modules/spring-boot-ssl-bundles/pom.xml create mode 100644 spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SSLBundlesApp.java create mode 100644 spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SecureRestTemplateConfig.java create mode 100644 spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SecureServiceRestApi.java create mode 100644 spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/application.yml create mode 100644 spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/cert.pem create mode 100644 spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/key.pem create mode 100644 spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/keystore.p12 create mode 100644 spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/static/index.html create mode 100644 spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SSLBundleApplicationTests.java diff --git a/spring-boot-modules/spring-boot-ssl-bundles/README.md b/spring-boot-modules/spring-boot-ssl-bundles/README.md new file mode 100644 index 0000000000..5616cce48b --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/README.md @@ -0,0 +1 @@ +## Relevant Articles diff --git a/spring-boot-modules/spring-boot-ssl-bundles/pom.xml b/spring-boot-modules/spring-boot-ssl-bundles/pom.xml new file mode 100644 index 0000000000..056d0308c2 --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.1.3 + + + springbootsslbundles + spring-boot-ssl-bundles + jar + Module for showing usage of SSL Bundles + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + org.apache.httpcomponents.client5 + httpclient5-fluent + ${apache.client5.version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + 5.0.3 + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SSLBundlesApp.java b/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SSLBundlesApp.java new file mode 100644 index 0000000000..f6cfb35d1e --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SSLBundlesApp.java @@ -0,0 +1,19 @@ +package com.baeldung.springbootsslbundles; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; +import org.springframework.boot.ssl.SslBundles; + +@SpringBootApplication +public class SSLBundlesApp { + public static void main(String[] args) { + SpringApplication.run(SSLBundlesApp.class, args); + } + @Bean + public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder, SslBundles sslBundles) { + return restTemplateBuilder.setSslBundle(sslBundles.getBundle("secure-service")).build(); + } +} diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SecureRestTemplateConfig.java b/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SecureRestTemplateConfig.java new file mode 100644 index 0000000000..48eda219dd --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SecureRestTemplateConfig.java @@ -0,0 +1,38 @@ +package com.baeldung.springbootsslbundles; + +import org.apache.hc.client5.http.classic.HttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.client5.http.io.HttpClientConnectionManager; +import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; +import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ssl.NoSuchSslBundleException; +import org.springframework.boot.ssl.SslBundle; +import org.springframework.boot.ssl.SslBundles; +import org.springframework.context.annotation.Bean; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +import javax.net.ssl.SSLContext; + +@Component +public class SecureRestTemplateConfig { + private final SSLContext sslContext; + + @Autowired + public SecureRestTemplateConfig(SslBundles sslBundles) throws NoSuchSslBundleException { + SslBundle sslBundle = sslBundles.getBundle("secure-service"); + this.sslContext = sslBundle.createSslContext(); + } + + @Bean + public RestTemplate secureRestTemplate() { + final SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder.create().setSslContext(this.sslContext).build(); + final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create().setSSLSocketFactory(sslSocketFactory).build(); + HttpClient httpClient = HttpClients.custom().setConnectionManager(cm).evictExpiredConnections().build(); + HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient); + return new RestTemplate(factory); + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SecureServiceRestApi.java b/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SecureServiceRestApi.java new file mode 100644 index 0000000000..3ed919b957 --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/main/java/com/baeldung/springbootsslbundles/SecureServiceRestApi.java @@ -0,0 +1,28 @@ +package com.baeldung.springbootsslbundles; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +public class SecureServiceRestApi { + private final RestTemplate restTemplate; + + @Autowired + public SecureServiceRestApi(RestTemplate restTemplate) { + this.restTemplate = restTemplate; + } + + public String fetchData(String dataId) { + ResponseEntity response = restTemplate.exchange( + "https://secure-service.com/api/data/{id}", + HttpMethod.GET, + null, + String.class, + dataId + ); + return response.getBody(); + } +} diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/application.yml b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/application.yml new file mode 100644 index 0000000000..1598645805 --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/application.yml @@ -0,0 +1,11 @@ +spring: + ssl: + bundle: + jks: + secure-service: + key: + alias: "secure-service" + keystore: + location: "classpath:keystore.p12" + password: "FooBar" + type: "PKCS12" \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/cert.pem b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/cert.pem new file mode 100644 index 0000000000..82ed122a80 --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/cert.pem @@ -0,0 +1,31 @@ +-----BEGIN CERTIFICATE----- +MIIFazCCA1OgAwIBAgIUCJcVMwyhLy/ln+ENMXbSWcsO0aswDQYJKoZIhvcNAQEL +BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM +GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMzA5MDUxNjAyMzdaFw0yNDA5 +MDQxNjAyMzdaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw +HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggIiMA0GCSqGSIb3DQEB +AQUAA4ICDwAwggIKAoICAQDMNn+ZmPfR4FUyG6PVGBB2rOAnIHqFqYMVyDUOtZja +9CxpgbQjHRwwWaUWcYzLPOsvN/tMC8BazAFHSI2KIeNKgjAesv9JTumqgFXdOmw8 +KT7a9C1IQXnCMhlbp9J7c7CLvjAvZvZBghxFLc7xBZo9rWA67QMZoOhXvdMoKv4G +5v9qD1ZqIKlCxJQrdErVUKyZPztlIWNqzPy9BJzFlBea2ArfrASulqJuWGyO09+o +6ABNgUAicp/zfCOeKIe9cni0oZj6Buwk4eVdYESzVohBO52h95KtN17Y/Tw+U8W5 +Szq9tit6Vkupbe8tih7Bkdnj22WeCLVwWdXCp1kJw2kFDJTiC3wQRa6P0OrVpPGx +Z5SmG9eSCz22alA+I521ZG85hmPDt3BleYRYlCtcW7GFT/7zLBEwlN93lY5Os1jj +PRS8o5eIg8UhTbU4QEaZRYcLzaFy0asfKfa4ZF3mH5whh/w07SEEBAKDfQPpiz3T +migd+r9qUnPWeoE8Hi7lA1KzUd4YeM2yNHqXoQiARjHkM4yrX6vVlfT+itVbrpqF +a5J7PjL26w+DsxvRt9Ad5gpOdDzuy5m2V6lphMDjeZoG4OXgBzQQ1YxK1r6wkI4U +ZwRNrb+BxmQebQHnXKEXI7jgS45uoFENwolIHm9Dou5VYGLI0z+/pDReugCcw2lO +/QIDAQABo1MwUTAdBgNVHQ4EFgQUlSkON/OM9HCXeaQ7VWQuiEwY2iAwHwYDVR0j +BBgwFoAUlSkON/OM9HCXeaQ7VWQuiEwY2iAwDwYDVR0TAQH/BAUwAwEB/zANBgkq +hkiG9w0BAQsFAAOCAgEAD+8sPSQR3+A4F9z704OOy1Mo6bvbnIuK9UdN7d4/zh+e +AoloyTFPLPZIldg9hXwCvrKjrfqS5YUKmXIp9tetX7ns13CeDFcqVwZfPnqjzdNN +ad255LEwMjIUm9hSNEV6AQBKW8E+a590SrUamEdkFm4fcUB1LaINwyJjls7C0VB2 +JL50OloaUlv0IMnAPRVp0Adlt9xs69R2B8Q4i297FvHB1PI7VMLYqNnX2+tnvszO +HvWtIqm6foyReDLfC0n87cuEBV7/9304V5vgEj20TR19isd0LffJDD1ujDXvN8dS +uGOB1VLRxAPonr9Iqk358EJ1T22uEcMdKE+sMnCBjw2fYIYRfjhGN+m6U6sb4MrF +zFUI6qB7W7T/5iukiRb4pLQ0OGgKOwYxpZoxcB3Ldjo5x58uKNOTNJ5zEJ8HUofA +BNfty10D3m3DlSyYbf7m1UUM0jj2l83LBGQzhGGUZgCnCsMczLrj64Gvf2iLGmCF +gu5zrxL01dptBkvTsYJwYBA67BBS4FcgYNMGx3m1uPsVUUIguJxufXWYfbub74QV +a1SH1NjO8HR3DLDU+S92tyTKWOUzJ5qOegEsR2cutVRzDuVTsFy7kayuNv/uLRrG +3P2HnUo8PG/nmysReBk6CGycUiDTt55DoPYGoQ5l19xTlkIt7ulNg7yX5pwFMeE= +-----END CERTIFICATE----- diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/key.pem b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/key.pem new file mode 100644 index 0000000000..b4202e9a8e --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/key.pem @@ -0,0 +1,54 @@ +-----BEGIN ENCRYPTED PRIVATE KEY----- +MIIJpDBOBgkqhkiG9w0BBQ0wQTApBgkqhkiG9w0BBQwwHAQIblni8xi+83QCAggA +MAwGCCqGSIb3DQIJBQAwFAYIKoZIhvcNAwcECJSRFMcxzIKiBIIJUEqyZcVQEBL1 +6jkeo5TGxVwolLnCNpEuj8UwLoK5Z2N5oVwSPzD5rMYuPg6OXXWk6zReaaKBkRR2 +vlpkckA4o+aSXfzvEXYGd+rZ3EeIK43zquIBjymlcN++FbEYOtAY1SoQm7FtyvdN +4QW7MOONUJcnN3EgRSRic2CCa0k6NSREfrBWaa+OcYB4C/JEuA2xgkCUw8bCcos6 +mksoF6mZDQearirNankMDR7gLQt9pdK7S55T4sCrFpL072s3k7lV0WtvTE/CQ8Wu +pdBKVPvpvkR1S9n3ajGMWVYBjkRuD0MMn1eGMW6t3mRI8+C15zTp9DjzySJTMzUm +C3l/m9VQBFewuHLziJFylqy7kgxrUUe39FShHYkJZDprZSYE33Lz67o8oHpLkkIh +YccDm2bgqIbKfslbAIXD4BKq0QOUbi681XGRslZ7ZGduwNm3Xly0yuKmstzhnqQu +TLkBWcNeauYA7eeTTwAQq5My/xt+Ls72AwjOjP3kGSNCvmrLBP+4zpJayr+l+OYl +r5G6YNGE3p3QVY/Wn05OWeRE6eVqp1BXvgeLdqNyQXNpPITas0LDeVncexTNilNc +R788Le77m6grpxaX4xKbMKf1dtsRtPf+LvVNAdfVj9lQcEvi3ub0yjKGUhtRuxKi +STvVyJkJM7mV3FsUsYwsJZ2rBXbB2ifz6RCa8BDDwLGqZ54AZcK7OyvS6yRXf2ip +jZ2N09OIoN3WaTXytueqEPmiZ+M8Sirt9YLzNa74BrWsqyazUYMtib1exhp6EVPH +EVh+SlTdwQ//tPZNBx8TCB1s+bOHyzplXZ8JVg+AiuvZtyP20jS6oil2qvOcLR94 +e1hQaIPy6QXFFOTcDnmcTmUnaJKBvPFfqSVg58OeMb3RyQkZWvTkoxiE6PZwh3d1 +hqVzb+l91GDiLbYndGE1QrqBmxbGzM7PKqUr91cWBU8723CqGciWK+bjk4CxWx/F +yHX6nDwDgfuhPe90r7Xrjj9/61/xoaWhg25BZVOgn/e1akDK+8qjHxDhc/anE7xS +DIefhiukPuj/7oaxRIe/pKndztVub3W9EbyvHJArU+H6Ixy4qaulCXymp7Hqo/07 +4dUCVz2AGAIWqC0X6jUO8j2iHuOgbQg/oZFYOl8zn4q1ic1pFp/MJWaaWG9rAXPt +miT34Rv8lvJW9nqKAGuW8uRJ6xqyw8DcpmOMjFamPOZ8H66aOOsVJwTFmg3YlUAh +Cy3ITprdDbLPuX8MLJB7hJxKrqpXpnaY68x1MXAfp3tPkQ41u3Eif8riVY33+XEJ +9OZN8Xwnv+spej8CGmjiNP7WhvyjLJnzsTycXR3BE1TL9IzrKoebdiE1pVUv5tcL +lFCl5eatcxuU03JFQt+DjhcMBuM2AT2dfZ4WyHm2kKbOVTQA5snSFwpLt1ZS2G64 +7XCvx+zLbloqzRZkcKCr7hXgmpWLOECp2Wk98E2iHOHVkMINE5kB+iIXsg2Ii8pN +8UwIDF4VHF/c3hTESFrY3tVIYGauB9hqcBU4NDcZNRuRd6MSx9NZe55xzJ7uR4oV +Et0yNkmluk/EySpMrwLhe6t5I8vQEP9Ug00yobUuRob6rSp2pjkmRm2aPu4q042B +JFqGGwZWTXoa7+THIua9xWQh4Bmz7UZ6oO9rBll5pmoNO8SzaJwF1ZzE9RL2iFQW +px9u+85ee9+a6aQhvZjX0C/XYt0oHeoWpeoLTb97nGlZEv1GouHkjgNKLmcgz0Kd +WugrakcxJolplqfQmPaoPWGMT3ukXauyvSOFrG7eJKrzQSrv2GSqKsvHLgqvtqeL +cDjwESbSHRdGBvEz/L/XJfIba6jOI76GtbWFi9Co872V7SkNWHqOdwcEbb06phxH +1u+ZUy0caU8rLe9exLg1/VLkEDHPy4aSOkkcCkptWG/UwjGOa5HOMPzWDsayDeDT +7bFZlgl11ZZGoRAW+GZkHUCRglLqxKA1lSyK7Pv7cVXe6wniPbfMnyjZQZnRIk+q +UFr7hc2Buw1nISmRF6vx1jdwfA5A/ECNCCCHZ+XQhOO3xcKZeG6FGjr11oHK0H1g +aJve3tkrSYC4nXZfE7Lij5Cx+S1wTfZ8G+fGlSQa2jdsJUfRBy/TXkIorApbzFc1 +P1x05HXzSnMhLUWFYRqLWSVdBQua0w/CYyKEOPZUaFCRa67u1NLH0plA/j7h39ZA +1uTceFbjYQHTAObsNu5z/zaHd+xTc3WN9NFuXQKGxFdgs+duEZk1XZnD3V3DIlbJ +YobwhOiVLelUzBQZBYKEo2LJ71E0oOjIiq0TiCy5YsB9UGl9Un3jn50cKrq7IldF +MQLBl+ixbOLQ0KbVs7K1P7AegQwfgdmvG4jdjFx5Myq77GHgCgmtvngCYJjrF1Vo +OLxrKjk7dZ+Hmy60zPjgYkHyvOdZRUKfIhZrpCM5Al/xKUqhR6rPtr2U7lkHw9zT +gsK6rxXfvmJjIzSFBQzBah8K9rYzk/DScXMQ+3XY7fu6r2LTnfWxCKYhX/2eEoXW +/+t0HsRNoGCLB9g8sDAt2tDbjOsGRIdtfQ28Q56Pi91+IlGE5/n4iJ/bws5F1MXB +amG44iYYNPHUnkr3YsQeCiyh/1GgiLbIi3P6ZVJ5vG1a5oPGNolsABMZ5HZzd/aD +LgZDFjIMDzL5WaP2xhfnTjQsaowpulLE0/7mrc5KnfKxwdlDmLGjLIRsa5fXbL6W +rqezhAkgRrGRhnljMnCgZGpkHMtZN3S0u78/u17FvtlbyDFOev1y9cpvMmp/RAP3 +OXp7Wo3JELz/7aMkmVt6a++j9hxuX0vas6PPCoM0PGlTdWxPo2y96fFuW41j59vh +XY54kI5sBFibuvxLJOr9lXw8EuXJTNiyKuoEoXu2QKNHYSOZi1OPzrJRsKxEwNBh +8TP1G99H/gdlYEI/CPYOGbhWMq1qZyukDHjQaOMdzRIRYawx4GbQE1HeGla5bFSy +n0Gki5ApqQk8b6muUxDXBgPdQKFL6o7KYhAg+8JsGvnByh7qVZl2kmwxjx2bJIcj +o7BBRSYLSWdW3cguXojtgoN2NcFZZON4IEDSBuu/1ESgi2a2W5T9NClK/3ZagPmJ +hX2T2qTTkVjWQ+xM15SD46s4s+5nZX2kGE1DHwtYSKgdHYR9n81po7CuEqVP1n/G +7NNrMLXj3PGrZ2vzKDGSAU1LzLOUrJ4m +-----END ENCRYPTED PRIVATE KEY----- diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/keystore.p12 b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/keystore.p12 new file mode 100644 index 0000000000000000000000000000000000000000..f58b35546780aa7e7abf00d71dda9a327513076d GIT binary patch literal 4242 zcmY+GcQ_mVx5tBsJ!;d~dz9F-R%z@asI913d(>XBw^A#W8dViam9|LKrnN_{8dXA3 z#42L{`n}J+_j~UjpXWTE*ZZ9F@9RL|v{{4%L=ZTw8Hh|INhj%)ihzWm3{I;JgwtyL z#djfaklMcys0y2| zY0orDl?(urxbhx2Z`zHQz1eJPGpSmz|<`{7v0 zFYZ!fT+>g(r%Br-PFC}%uj34KYo}8l`e;17cZD^#QFJ~g{ZEaY!hXl=mA>mY5Bhsk zrU^WhMR-udt0Ml+{-;Lln`bsi=rkpzT8Kg*?+n^l%I`Ynz5DBubmND7Vmzlg)FPyN zaDgIwpOM8ymZ_Ymtt@ZOT`uwh#Tu7-D4V%2pTvrm;ofv6AKI4S;1K2nwqQ%kY6HQcUfK3Pgsa}Rt&wrdxQ@~x z#}QA{zsd4(;#8xFB4dt>%{b+r$0=;2sGNK{LC24ZwD$^OyeXDT5I!Q)^dt>eqA180 z#)k0P`dREJW33;?G{}k8PYMMwDGML-N%>XHcV0<%OT?1$_~bI<%=U`6OYbl`_*bAO zF4-N-nwoMA1ZG&JyHavv2!xvjbzWT`B^{DhTS8wDK?$T45AV6~C%Pr8Ro05=}jwRz_
il`Z?B=kA=GX^4BuW@MZVdE2t^{M1Z&Tgb8#|B)Gi`81jx zqEoEVHV?m9S^F*;BAT~>u ze15|nQHu28bF};k+;R9y(6xi;ZFqFdDbbhG9%i^1vp|4w6ymO8k-T5Oetp&X?G~BRXxiHA;vfm8bWee_>L1igjmm%>l;VPemYj%i?L)%;L5 zYA8_H__?2*`PwlO`lhgy-QWJVoxP@i3R|%#z5+(UEc>JUi-PFwX#rGMbY4eU`|oRj zGR1wVRp)0L@q*bJYqcvk#RGF^32P)?Xik>0B7qa8R7nZq0+fC5EQ!%|_Nle3_XfUt zSDReeF_)ESTVFIIh(Nh|SKYAp zony=%Cn}jF*p$J=_EgiI#L^H&@k|JHqF+zhT*p`>WJy0rcr1TE(=!0bh@H}xyw!2- z+OHS#9+b;a)??wC{-kD=9XWjst0C{Uy-ci=$*bblmLdB3QpnfDerBay-zuidu5YiQ zb1TVpw!rn_Rt~XTH%)5OgSsY{S*e`QHv1UiJ;dSf4Wz^(B5`2Y{oH)YN#-Qa>~#hY z`P9ktA=#mzzHD9r_5|&<6#h>dp{v%_Zp{KIx9aPweB*UxIf7nK#&R8=W|x$|Q8&Y^ zENx%eUgo}Qh!xtRh)%z|Q3Y`H7uRWENQP(Y%&k5$4356QnhCd|<2yg)+bP*Wx+AE7 zY$p9At#^nVS3wZ?k}j>F|7CA}63n!FmS3-**47|oV2WjISVc#az5F}BRFU#H8~K~q zUQ_b>SJ?_BxTddXfphz!Z6AXFY+x&1^q9ZF3v;9mc>~wME|zUJgJlADC!g9rq=dCf z^WV#2PlNmNs$c+`72AK#?<@tw~{IxC8^7JYss*5n}RUPdh?4kVM+-VbfL z#~>29a8;(oK$C{p$)S}&V=f4s?BxH5q6|*90fdub|KjDpZvjN{KiVKCAp9FX{R;#B zpG}DVu}Oe-#ws(aBV8$srs6}V@Z>}+r>bg^!m!Sg^6R0>qXY@CnI$#j#!?LGQ1s1@b9O1_I(aDN&0~{i3!em1&aq}3n!^&h9w|D1?p#8SSjY)zo z)o8*l&yAePhlKn4sh?RckGi7Yj@b-33keX7HNM{(CSI*99z|4frxMhV!Znl?sQtJ` zI>+DL;(<%#l4_O-{vP9Kkyr_3!ggn86701{@#7j&thuH~-G(_$WNK|*sePL%;^DkU zx*@-6q4gP)^;Jmg4kazxS9y78TrD-S;Y0`l{558Y*hpX_6)&qyeSzpLf4A-e$+UWwuHTW)&r z=3$YBFI#(5x*<|p4?ELbd_e%yv7unq?zziheUM&$C}KnnVRfw;GuXK^fv97VSpi2a z6Xo~%eU~_uAX1x)R-LP{S2j(VXm=tzesxeFbKoGZEMex&cn~JUf5AI<;Jn}%vHcW! z4O-HqKBDe>lm^P;9C0~tw%QDe31dPA^^y|vfq!|;zNN#>zN@p2WI%tXSh{ayszl7) z)(hi9dDtxk4Xl@0(57h2%U*BzmG0aww)0T|B{FUolaaF9%?;U_N`;frCMV9r(UrUc z>%Xdh8@-h-QPk^-52a$oAbIU&8_#iLbVYNA9CCYD-NBK2}m61T!(jru_h+(dx5@g zsVY>vwwQBqo8O(7a_%p5FJDAWw@voJ+r~b5nbyCT%)JP&d}}w;q7bxOGSCf-4y4oN zqF5Z}9hf{?2X~{+gO?(`Pyv62kPpPTDT-|V9~S8^QOMn zsi||L^b&17qVAX7g2q0vq^sU9`;kto-^2N>LdxLsnZdlk51reBm-ar>kYv|RdP>|a z6RWh66JgP-Q|Rlr<*!V>VL~~-y!*!ENlo3BQ``^-6T!p{QP`meZKXnWUkyO=s0R`b-DC@$Rs zorFbeI2RcP@QX+?pZCLO&6m9{(+BxNY@gzaL`^Le)XF-f}LgMNH6`A8^T9!%m-59SDUj~ z%>yC~s^%UiHZvfv?zXC1ip1;`#<>z&e`9%$jhjP$k(InljV(V(qY&0BzX0dO>hmA_ zm=@lV>%cgHoq%u>nWLfh{-s%#S?n*(|dnpX>~>5`A4m!VCf*BFVv; z_~?#Ig$}PqOD(JDav53A$njC{#)B_L#;P_fpC?B#??n85rl(dReadt$t(F%v+y#uA zF~@=7D-l!0>#sY>bj{;*O9f7s-pD0n#wtghy;G$e^@=On)xJ2db%%{++lynwR9rDk zPN#jQ0t;soZ;xP%tRekv!(M7pgFToe3!D&JA2h*^!v=v3BxsY zT;FT-8@=6BrC+Dba5F2+^Vbmljt<(mQKn}n4_Jwfg_|X14Q7S2iul&L(tW628OPEuYgy$;QZN8Chma3yc>)&V40p`Q$?wG6~nSUhN**5?AJAsg(a2FQ%XoTVCM0 zDap*@JRzIj6ml+Eq;;suI`SBM5wT9EL`21|n@=kJp$rDNprFz+?SutduNd+eE%n9< zW`P`8uIG93Gz^-0TZMWwW2!coL+=C<=@BaJcNy&f1w!o}ES(go*`ri$&4(TR%tK@Z z0JGP6G*J!f0K6e%)X$E&Un>1SH(FoSE)DBP7O!r{KL-bm#4V+7w~r{I-d-M-jz!V1 zNm+!-PQ=ZPU1wC*^0_IHMv{z`-L=Q1}n{70Xj^=(5iW6ZP^^!-l%}WUHDG z1^v&6FI(XkJH4ozY;8x9uwTMr_uM zc5Ny~(TQtOd=ezNtijUeAwTrTC|ApQGW7mvsWdik2|^A_@7)>lmnD3$ZdaZV5nmy1 zaci1kp8K+1jg)R8X41{y13?-dbW%6 zR@Uz-yIr_Bq+~K9X$s-}-z$xbQIZMBU}L?fr!ZDHQ)f||URdY1GAEb!0V4Wu6N4lN z2N)0tZ~-_2f&l@4>z)7l1puA`JpM8lh$Ms?LIxrhr6wX|BL)B&)J+so`AEe%K{D`; Z`piIM31#vSkTfwI5tNV+;rP#K_a7xu_sswR literal 0 HcmV?d00001 diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/static/index.html b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/static/index.html new file mode 100644 index 0000000000..117910cc89 --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/main/resources/static/index.html @@ -0,0 +1,13 @@ + + + + + Spring SSL Bundler Demo Application + + +

Spring SSL Bundler Demo Application

+

+ This is a sample application that can be built as native executable. +

+ + diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SSLBundleApplicationTests.java b/spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SSLBundleApplicationTests.java new file mode 100644 index 0000000000..876641c8b5 --- /dev/null +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SSLBundleApplicationTests.java @@ -0,0 +1,12 @@ +package com.baeldung.springbootsslbundles; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SSLBundleApplicationTests { + @Test + void contextLoads() { + + } +} From e8c2e2cb9637daf75ec06660ec1999c332cb7c35 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Wed, 20 Sep 2023 17:34:27 +0330 Subject: [PATCH 028/193] #BAEL-6916: remove xml context --- .../src/main/resources/camel-context-test.xml | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 messaging-modules/apache-camel/src/main/resources/camel-context-test.xml diff --git a/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml b/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml deleted file mode 100644 index f306574868..0000000000 --- a/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - \ No newline at end of file From a34c8794edc009b8fa9c46bd4da43726d566a243 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Wed, 20 Sep 2023 17:41:47 +0330 Subject: [PATCH 029/193] #BAEL-6916: add Spring Boot main class --- .../java/com/baeldung/camel/apache/Application.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/Application.java diff --git a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/Application.java b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/Application.java new file mode 100755 index 0000000000..51b2540aa8 --- /dev/null +++ b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/Application.java @@ -0,0 +1,11 @@ +package com.baeldung.camel.apache; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} \ No newline at end of file From 85ac5582781c704284fb61b0d26dd8620c42a88c Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Wed, 20 Sep 2023 17:53:35 +0330 Subject: [PATCH 030/193] #BAEL-6916: add Spring Bean Annotation --- .../main/java/com/baeldung/camel/apache/file/FileProcessor.java | 2 ++ .../main/java/com/baeldung/camel/apache/file/FileRouter.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java index ce4d92e8ab..5ca8cc9d72 100644 --- a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java +++ b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java @@ -5,7 +5,9 @@ import java.util.Date; import org.apache.camel.Exchange; import org.apache.camel.Processor; +import org.springframework.stereotype.Component; +@Component public class FileProcessor implements Processor { public void process(Exchange exchange) throws Exception { diff --git a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileRouter.java b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileRouter.java index 760f37677b..b57232d41e 100644 --- a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileRouter.java +++ b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileRouter.java @@ -1,7 +1,9 @@ package com.baeldung.camel.apache.file; import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; +@Component public class FileRouter extends RouteBuilder { private static final String SOURCE_FOLDER = "src/test/source-folder"; From 036531949f12f019c1902cfac2e32ed33227de10 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Wed, 20 Sep 2023 17:58:00 +0330 Subject: [PATCH 031/193] #BAEL-6916: add dependencies --- messaging-modules/apache-camel/pom.xml | 60 +++++++++++++++++++++----- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/messaging-modules/apache-camel/pom.xml b/messaging-modules/apache-camel/pom.xml index bb20f178aa..026983484b 100644 --- a/messaging-modules/apache-camel/pom.xml +++ b/messaging-modules/apache-camel/pom.xml @@ -17,30 +17,68 @@ - org.apache.camel - camel-core - ${env.camel.version} + org.springframework.boot + spring-boot-starter-web + + + org.apache.camel.springboot + camel-spring-boot-starter + ${camel.version} + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + org.apache.camel - camel-spring-javaconfig - ${env.camel.version} + camel-test-spring-junit5 + ${camel.version} + test org.apache.camel - camel-jackson - ${env.camel.version} + camel-http + ${camel.version} - org.apache.camel - camel-test - ${env.camel.version} + org.apache.camel.springboot + camel-bindy-starter + ${camel.version} + + + org.apache.camel.springboot + camel-jackson-starter + ${camel.version} + + + org.junit.platform + junit-platform-launcher test - 3.14.7 + 3.21.0 + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M5 + + + \ No newline at end of file From d48a45c15a23a5b2723aec06fe321ef5359cf4ad Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Wed, 20 Sep 2023 18:00:31 +0330 Subject: [PATCH 032/193] #BAEL-6916: update test cases --- .../FruitArrayJacksonUnmarshalUnitTest.java | 65 ++++++++++++------- .../FruitListJacksonUnmarshalUnitTest.java | 64 +++++++++++------- .../FileProcessorIntegrationTest.java | 11 ++-- 3 files changed, 90 insertions(+), 50 deletions(-) diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java index bc0025b263..a5981ccb1a 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java @@ -1,5 +1,21 @@ package com.apache.baeldung.camel.jackson; +import com.baeldung.camel.apache.Application; +import com.baeldung.camel.apache.jackson.Fruit; +import org.apache.camel.Configuration; +import org.apache.camel.EndpointInject; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jackson.ListJacksonDataFormat; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Bean; +import org.springframework.test.annotation.DirtiesContext; + import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; @@ -7,25 +23,42 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jackson.ListJacksonDataFormat; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; +import static org.springframework.test.util.AssertionErrors.assertEquals; +import static org.springframework.test.util.AssertionErrors.assertNotNull; -import com.baeldung.camel.apache.jackson.Fruit; +@CamelSpringBootTest +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) +@SpringBootTest(classes = {Application.class, FruitArrayJacksonUnmarshalUnitTest.TestConfig.class}) +public class FruitArrayJacksonUnmarshalUnitTest { -public class FruitArrayJacksonUnmarshalUnitTest extends CamelTestSupport { + @Autowired + private ProducerTemplate template; + + @EndpointInject("mock:marshalledObject") + private MockEndpoint mock; + + @Configuration + static class TestConfig { + @Bean + RoutesBuilder route() { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:jsonInput").unmarshal(new ListJacksonDataFormat(Fruit.class)) + .to("mock:marshalledObject"); + } + }; + } + } @Test public void givenJsonFruitArray_whenUnmarshalled_thenSuccess() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:marshalledObject"); - mock.expectedMessageCount(1); + mock.setExpectedMessageCount(1); mock.message(0).body().isInstanceOf(List.class); String json = readJsonFromFile("/json/fruit-array.json"); template.sendBody("direct:jsonInput", json); - assertMockEndpointsSatisfied(); + mock.assertIsSatisfied(); @SuppressWarnings("unchecked") List fruitList = mock.getReceivedExchanges().get(0).getIn().getBody(List.class); @@ -41,18 +74,6 @@ public class FruitArrayJacksonUnmarshalUnitTest extends CamelTestSupport { assertEquals("Fruit name", "Apple", fruit.getName()); assertEquals("Fruit id", 101, fruit.getId()); } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - - from("direct:jsonInput").unmarshal(new ListJacksonDataFormat(Fruit.class)) - .to("mock:marshalledObject"); - } - }; - } private String readJsonFromFile(String path) throws URISyntaxException, IOException { URL resource = FruitArrayJacksonUnmarshalUnitTest.class.getResource(path); diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java index 2d15ebf46b..b5b0fee2f9 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java @@ -1,5 +1,21 @@ package com.apache.baeldung.camel.jackson; +import com.baeldung.camel.apache.Application; +import com.baeldung.camel.apache.jackson.Fruit; +import com.baeldung.camel.apache.jackson.FruitList; +import org.apache.camel.Configuration; +import org.apache.camel.EndpointInject; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jackson.JacksonDataFormat; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Bean; + import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; @@ -7,26 +23,41 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jackson.JacksonDataFormat; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; +import static org.springframework.test.util.AssertionErrors.assertEquals; +import static org.springframework.test.util.AssertionErrors.assertNotNull; -import com.baeldung.camel.apache.jackson.Fruit; -import com.baeldung.camel.apache.jackson.FruitList; +@CamelSpringBootTest +@SpringBootTest(classes = {Application.class, FruitListJacksonUnmarshalUnitTest.TestConfig.class}) +public class FruitListJacksonUnmarshalUnitTest { -public class FruitListJacksonUnmarshalUnitTest extends CamelTestSupport { + @Autowired + ProducerTemplate template; + + @EndpointInject("mock:marshalledObject") + private MockEndpoint mock; + + @Configuration + static class TestConfig { + @Bean + RoutesBuilder route() { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:jsonInput").unmarshal(new JacksonDataFormat(FruitList.class)) + .to("mock:marshalledObject"); + } + }; + } + } @Test public void givenJsonFruitList_whenUnmarshalled_thenSuccess() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:marshalledObject"); - mock.expectedMessageCount(1); + mock.setExpectedMessageCount(1); mock.message(0).body().isInstanceOf(FruitList.class); String json = readJsonFromFile("/json/fruit-list.json"); template.sendBody("direct:jsonInput", json); - assertMockEndpointsSatisfied(); + mock.assertIsSatisfied(); FruitList fruitList = mock.getReceivedExchanges().get(0).getIn().getBody(FruitList.class); assertNotNull("Fruit lists should not be null", fruitList); @@ -43,17 +74,6 @@ public class FruitListJacksonUnmarshalUnitTest extends CamelTestSupport { assertEquals("Fruit id", 101, fruit.getId()); } - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:jsonInput").unmarshal(new JacksonDataFormat(FruitList.class)) - .to("mock:marshalledObject"); - } - }; - } - private String readJsonFromFile(String path) throws URISyntaxException, IOException { URL resource = FruitListJacksonUnmarshalUnitTest.class.getResource(path); return new String(Files.readAllBytes(Paths.get(resource.toURI()))); diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java index e4390a95e5..5df7543c6f 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java @@ -1,16 +1,14 @@ package com.apache.camel.file.processor; -import java.io.File; - +import com.baeldung.camel.apache.file.FileProcessor; import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.DefaultCamelContext; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import com.baeldung.camel.apache.file.FileProcessor; +import java.io.File; public class FileProcessorIntegrationTest { @@ -67,9 +65,10 @@ public class FileProcessorIntegrationTest { @Test public void moveFolderContentSpringDSLTest() throws InterruptedException { - ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml"); +// ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml"); +// ApplicationContext applicationContext = ContextLoader.getCurrentWebApplicationContext(); Thread.sleep(DURATION_MILIS); - applicationContext.close(); + //applicationContext.close(); } } \ No newline at end of file From 910be42d8f37266fc4d764ba8dbf9646f5066f3e Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Wed, 20 Sep 2023 22:05:22 +0530 Subject: [PATCH 033/193] Review Comment changes --- .../multiple/objecttypes/AlternativeMultipeTypeList.java | 7 +++++-- .../baeldung/list/multiple/objecttypes/CustomObject.java | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java index d80f4627d3..6dd44e0ffa 100644 --- a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java @@ -25,8 +25,8 @@ public class AlternativeMultipeTypeList { // List of Custom Object ArrayList objList = new ArrayList<>(); - objList.add(new CustomObject("obj1", 1)); - objList.add(new CustomObject("obj2", 2)); + objList.add(new CustomObject("String")); + objList.add(new CustomObject(2)); // List via Functional Interface List dataList = new ArrayList<>(); @@ -36,6 +36,9 @@ public class AlternativeMultipeTypeList { UserFunctionalInterface myInterface = (listObj, data) -> { if (myPricate.test(data)) listObj.add(data); + else + System.out.println("Skipping input as data not allowed for class: " + data.getClass() + .getSimpleName()); return listObj; }; diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java index f4d4be989d..eec81523f4 100644 --- a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java @@ -8,8 +8,7 @@ public class CustomObject { this.classData = classData; } - CustomObject(String classData, Integer intData) { - this.classData = classData; + CustomObject(Integer intData) { this.intData = intData; } From 1f9bcc7ef1512e96c761ed425a9403ef71d29a39 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Wed, 20 Sep 2023 22:28:18 +0530 Subject: [PATCH 034/193] JAVA-20438 Create new spring-data-couchbase module (#14745) --- spring-reactive-modules/pom.xml | 1 + .../spring-5-data-reactive/README.md | 3 +- .../spring-5-data-reactive/pom.xml | 92 ----------- .../R2dbcApplicationIntegrationTest.java | 7 +- .../spring-data-couchbase/README.md | 9 ++ .../spring-data-couchbase/pom.xml | 146 ++++++++++++++++++ .../ReactiveCouchbaseApplication.java | 0 .../configuration/CouchbaseProperties.java | 0 .../N1QLReactiveCouchbaseConfiguration.java | 0 .../ReactiveCouchbaseConfiguration.java | 0 .../ViewReactiveCouchbaseConfiguration.java | 0 .../com/baeldung/couchbase/domain/Person.java | 0 .../repository/n1ql/N1QLPersonRepository.java | 0 .../n1ql/N1QLSortingPersonRepository.java | 0 .../repository/view/ViewPersonRepository.java | 0 .../src/main/resources/couchbase.properties | 0 .../src/main/resources/logback.xml | 13 ++ .../CouchbaseMockConfiguration.java | 0 .../n1ql/N1QLPersonRepositoryLiveTest.java | 0 .../N1QLSortingPersonRepositoryLiveTest.java | 0 .../ViewPersonRepositoryIntegrationTest.java | 0 21 files changed, 174 insertions(+), 97 deletions(-) create mode 100644 spring-reactive-modules/spring-data-couchbase/README.md create mode 100644 spring-reactive-modules/spring-data-couchbase/pom.xml rename spring-reactive-modules/{spring-5-data-reactive => spring-data-couchbase}/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-data-couchbase}/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-data-couchbase}/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-data-couchbase}/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-data-couchbase}/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-data-couchbase}/src/main/java/com/baeldung/couchbase/domain/Person.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-data-couchbase}/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-data-couchbase}/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-data-couchbase}/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-data-couchbase}/src/main/resources/couchbase.properties (100%) create mode 100644 spring-reactive-modules/spring-data-couchbase/src/main/resources/logback.xml rename spring-reactive-modules/{spring-5-data-reactive => spring-data-couchbase}/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-data-couchbase}/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-data-couchbase}/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-data-couchbase}/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java (100%) diff --git a/spring-reactive-modules/pom.xml b/spring-reactive-modules/pom.xml index e75682da78..309687f011 100644 --- a/spring-reactive-modules/pom.xml +++ b/spring-reactive-modules/pom.xml @@ -27,6 +27,7 @@ spring-5-reactive-filters spring-5-reactive-oauth spring-5-reactive-security + spring-data-couchbase spring-reactive spring-reactive-exceptions spring-reactor diff --git a/spring-reactive-modules/spring-5-data-reactive/README.md b/spring-reactive-modules/spring-5-data-reactive/README.md index ecb6d01267..3522d9681b 100644 --- a/spring-reactive-modules/spring-5-data-reactive/README.md +++ b/spring-reactive-modules/spring-5-data-reactive/README.md @@ -6,5 +6,4 @@ This module contains articles about reactive Spring 5 Data The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles -- [A Quick Look at R2DBC with Spring Data](https://www.baeldung.com/spring-data-r2dbc) -- [Spring Data Reactive Repositories with Couchbase](https://www.baeldung.com/spring-data-reactive-couchbase) +- [A Quick Look at R2DBC with Spring Data](https://www.baeldung.com/spring-data-r2dbc) \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-data-reactive/pom.xml b/spring-reactive-modules/spring-5-data-reactive/pom.xml index e4d3aeeddd..dc4a5b9bd1 100644 --- a/spring-reactive-modules/spring-5-data-reactive/pom.xml +++ b/spring-reactive-modules/spring-5-data-reactive/pom.xml @@ -26,15 +26,6 @@ - - io.projectreactor - reactor-core - ${reactor-core.version} - - - org.springframework.boot - spring-boot-starter-data-couchbase-reactive - org.springframework.boot spring-boot-starter-web @@ -42,21 +33,12 @@ org.projectlombok lombok - ${lombok.version} io.projectreactor reactor-test test - - io.reactivex.rxjava2 - rxjava - - - org.springframework - spring-test - org.springframework.boot spring-boot-starter-test @@ -66,101 +48,27 @@ org.springframework.boot spring-boot-starter-webflux - - org.springframework - spring-tx - ${spring-tx.version} - org.springframework.data spring-data-r2dbc - ${spring-data-r2dbc.version} io.r2dbc r2dbc-h2 - ${r2dbc-h2.version} - - - com.h2database - h2 - - - org.apache.httpcomponents - httpclient - ${httpclient.version} - - - com.couchbase.mock - CouchbaseMock - ${couchbaseMock.version} - test - - org.apache.maven.plugins - maven-surefire-plugin - - - --add-opens java.base/java.util=ALL-UNNAMED - - - org.springframework.boot spring-boot-maven-plugin - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - default-compile - none - - - - default-testCompile - none - - - java-compile - compile - - compile - - - - java-test-compile - test-compile - - testCompile - - - - - 5.2.2.RELEASE - 1.0.0.RELEASE - 0.8.1.RELEASE - 4.5.2 - 1.5.23 - 3.3.1.RELEASE - - 2.2.6.RELEASE 2.17.1 - 1.18.26 \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java b/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java index 1af570587e..b5e859ae2f 100644 --- a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java +++ b/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java @@ -1,6 +1,7 @@ package com.baeldung.r2dbc; +import com.baeldung.r2dbc.configuration.R2DBCConfiguration; import com.baeldung.r2dbc.model.Player; import com.baeldung.r2dbc.repository.PlayerRepository; import io.r2dbc.h2.H2ConnectionFactory; @@ -9,7 +10,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.r2dbc.core.DatabaseClient; +import org.springframework.r2dbc.core.DatabaseClient; import org.springframework.test.context.junit4.SpringRunner; import reactor.core.publisher.Flux; import reactor.core.publisher.Hooks; @@ -20,7 +21,7 @@ import java.util.Arrays; import java.util.List; @RunWith(SpringRunner.class) -@SpringBootTest +@SpringBootTest(classes = R2DBCConfiguration.class) public class R2dbcApplicationIntegrationTest { @@ -43,7 +44,7 @@ public class R2dbcApplicationIntegrationTest { "DROP TABLE IF EXISTS player;", "CREATE table player (id INT AUTO_INCREMENT NOT NULL, name VARCHAR2, age INT NOT NULL);"); - statements.forEach(it -> client.execute(it) // + statements.forEach(it -> client.sql(it) // .fetch() // .rowsUpdated() // .as(StepVerifier::create) // diff --git a/spring-reactive-modules/spring-data-couchbase/README.md b/spring-reactive-modules/spring-data-couchbase/README.md new file mode 100644 index 0000000000..e38ef10562 --- /dev/null +++ b/spring-reactive-modules/spring-data-couchbase/README.md @@ -0,0 +1,9 @@ +## Spring Data Reactive Project + +This module contains articles about reactive Spring Data Couchbase + +### The Course +The "REST With Spring" Classes: http://bit.ly/restwithspring + +### Relevant Articles +- [Spring Data Reactive Repositories with Couchbase](https://www.baeldung.com/spring-data-reactive-couchbase) diff --git a/spring-reactive-modules/spring-data-couchbase/pom.xml b/spring-reactive-modules/spring-data-couchbase/pom.xml new file mode 100644 index 0000000000..68ddd1cefa --- /dev/null +++ b/spring-reactive-modules/spring-data-couchbase/pom.xml @@ -0,0 +1,146 @@ + + + 4.0.0 + spring-data-couchbase + spring-data-couchbase + jar + + + com.baeldung.spring.reactive + spring-reactive-modules + 1.0.0-SNAPSHOT + + + + + + org.apache.logging.log4j + log4j-bom + ${log4j2.version} + import + pom + + + + + + + io.projectreactor + reactor-core + ${reactor-core.version} + + + org.springframework.boot + spring-boot-starter-data-couchbase-reactive + + + org.springframework.boot + spring-boot-starter-web + + + org.projectlombok + lombok + ${lombok.version} + + + io.projectreactor + reactor-test + test + + + io.reactivex.rxjava2 + rxjava + + + org.springframework + spring-test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework + spring-tx + ${spring-tx.version} + + + org.apache.httpcomponents + httpclient + ${httpclient.version} + + + com.couchbase.mock + CouchbaseMock + ${couchbaseMock.version} + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens java.base/java.util=ALL-UNNAMED + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + + + + + default-compile + none + + + + default-testCompile + none + + + java-compile + compile + + compile + + + + java-test-compile + test-compile + + testCompile + + + + + + + + + 5.2.2.RELEASE + 4.5.2 + 1.5.23 + 3.3.1.RELEASE + + 2.2.6.RELEASE + 2.17.1 + 1.18.26 + + + \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/Person.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/Person.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/Person.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/Person.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java rename to spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/resources/couchbase.properties b/spring-reactive-modules/spring-data-couchbase/src/main/resources/couchbase.properties similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/resources/couchbase.properties rename to spring-reactive-modules/spring-data-couchbase/src/main/resources/couchbase.properties diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/resources/logback.xml b/spring-reactive-modules/spring-data-couchbase/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-reactive-modules/spring-data-couchbase/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java rename to spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java rename to spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java rename to spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java rename to spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java From 914d01d03dd5671218bdb8d0e4a502307b0fcf77 Mon Sep 17 00:00:00 2001 From: Kasra Madadipouya Date: Thu, 21 Sep 2023 05:58:33 +0200 Subject: [PATCH 035/193] JAVA-25341 fix Java networking flaky tests (#14798) --- .../src/test/java/com/baeldung/socket/EchoIntegrationTest.java | 2 +- .../java/com/baeldung/socket/GreetServerIntegrationTest.java | 2 +- .../com/baeldung/socket/SocketEchoMultiIntegrationTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/EchoIntegrationTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/EchoIntegrationTest.java index 103824b6aa..1e85b9d6dd 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/EchoIntegrationTest.java +++ b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/EchoIntegrationTest.java @@ -24,7 +24,7 @@ public class EchoIntegrationTest { Executors.newSingleThreadExecutor() .submit(() -> new EchoServer().start(port)); - Thread.sleep(500); + Thread.sleep(2000); } private EchoClient client = new EchoClient(); diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java index 2bded156c5..09f20c970d 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java +++ b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java @@ -27,7 +27,7 @@ public class GreetServerIntegrationTest { Executors.newSingleThreadExecutor() .submit(() -> new GreetServer().start(port)); - Thread.sleep(500); + Thread.sleep(2000); } @Before diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java index 62e2dd44ae..f08542c1aa 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java +++ b/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java @@ -23,7 +23,7 @@ public class SocketEchoMultiIntegrationTest { s.close(); Executors.newSingleThreadExecutor().submit(() -> new EchoMultiServer().start(port)); - Thread.sleep(500); + Thread.sleep(2000); } @Test From e842b87ec53cc8e391de030e7b043c68e5168f68 Mon Sep 17 00:00:00 2001 From: Bipin kumar Date: Thu, 21 Sep 2023 15:22:42 +0530 Subject: [PATCH 036/193] =?UTF-8?q?JAVA-23380:=20Changes=20made=20for=20up?= =?UTF-8?q?grading=20sprint-boot-autoconfiguration=20=E2=80=A6=20(#14769)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spring-boot-autoconfiguration/pom.xml | 14 +++++++++++--- .../autoconfiguration/MySQLAutoconfiguration.java | 7 ++++--- .../annotationprocessor/DatabaseProperties.java | 6 ++++-- .../baeldung/autoconfiguration/example/MyUser.java | 4 ++-- .../src/main/resources/META-INF/spring.factories | 1 - ...rk.boot.autoconfigure.AutoConfiguration.imports | 1 + .../src/main/resources/mysql.properties | 2 +- 7 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/spring-boot-modules/spring-boot-autoconfiguration/pom.xml b/spring-boot-modules/spring-boot-autoconfiguration/pom.xml index 7a3f9f01e8..7880a033f8 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/pom.xml +++ b/spring-boot-modules/spring-boot-autoconfiguration/pom.xml @@ -10,9 +10,10 @@ This is simple boot application demonstrating a custom auto-configuration - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 @@ -66,6 +67,13 @@ org.apache.maven.plugins maven-war-plugin + + org.springframework.boot + spring-boot-maven-plugin + + com.baeldung.autoconfiguration.example.AutoconfigurationApplication + + diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java index 295e0d74c9..c470656597 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java @@ -3,10 +3,10 @@ package com.baeldung.autoconfiguration; import java.util.Arrays; import java.util.Properties; -import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureOrder; import org.springframework.boot.autoconfigure.condition.ConditionMessage; import org.springframework.boot.autoconfigure.condition.ConditionMessage.Style; @@ -20,7 +20,6 @@ import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.core.Ordered; import org.springframework.core.env.Environment; @@ -31,7 +30,9 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.util.ClassUtils; -@Configuration +import jakarta.persistence.EntityManagerFactory; + +@AutoConfiguration @ConditionalOnClass(DataSource.class) @AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) @PropertySource("classpath:mysql.properties") diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/annotationprocessor/DatabaseProperties.java b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/annotationprocessor/DatabaseProperties.java index 4fb5b408a2..47f07c808f 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/annotationprocessor/DatabaseProperties.java +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/annotationprocessor/DatabaseProperties.java @@ -1,11 +1,13 @@ package com.baeldung.autoconfiguration.annotationprocessor; -import javax.validation.constraints.Max; -import javax.validation.constraints.Min; + import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; + @Configuration @ConfigurationProperties(prefix = "database") public class DatabaseProperties { diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java index 31ce0fd969..26a2e04e2f 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java @@ -1,7 +1,7 @@ package com.baeldung.autoconfiguration.example; -import javax.persistence.Entity; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; @Entity public class MyUser { diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories index 11c775fc6c..e69de29bb2 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories @@ -1 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.baeldung.autoconfiguration.MySQLAutoconfiguration diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000000..ab28361814 --- /dev/null +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.baeldung.autoconfiguration.MySQLAutoconfiguration diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/mysql.properties b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/mysql.properties index 74f1ee1373..27092f852f 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/mysql.properties +++ b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/mysql.properties @@ -1,5 +1,5 @@ usemysql=local -mysql-hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +mysql-hibernate.dialect=org.hibernate.dialect.MySQLDialect mysql-hibernate.show_sql=true mysql-hibernate.hbm2ddl.auto=create-drop \ No newline at end of file From 2a34149e8a72294f82f74dd855bf65fb24f0b9f6 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 19:56:38 +0800 Subject: [PATCH 037/193] Update README.md [skip ci] --- core-java-modules/core-java-streams-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-streams-5/README.md b/core-java-modules/core-java-streams-5/README.md index 885949d937..dec4a7a0cb 100644 --- a/core-java-modules/core-java-streams-5/README.md +++ b/core-java-modules/core-java-streams-5/README.md @@ -2,3 +2,4 @@ - [Difference Between parallelStream() and stream().parallel() in Java](https://www.baeldung.com/java-parallelstream-vs-stream-parallel) - [Working With Empty Stream in Java](https://www.baeldung.com/java-empty-stream) - [Aggregate Runtime Exceptions in Java Streams](https://www.baeldung.com/java-streams-aggregate-exceptions) +- [Streams vs. Loops in Java](https://www.baeldung.com/java-streams-vs-loops) From 8b50598314bf0accaf602da53a2b837cae562dd6 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:04:09 +0800 Subject: [PATCH 038/193] Update README.md [skip ci] --- testing-modules/mockito-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/mockito-2/README.md b/testing-modules/mockito-2/README.md index 82c97305f6..b60885c6d5 100644 --- a/testing-modules/mockito-2/README.md +++ b/testing-modules/mockito-2/README.md @@ -7,3 +7,4 @@ This module contains articles about Mockito - [Resolving Mockito Exception: Wanted But Not Invoked](https://www.baeldung.com/mockito-exception-wanted-but-not-invoked) - [Matching Null With Mockito](https://www.baeldung.com/mockito-match-null) - [Mock Same Method with Different Parameters](https://www.baeldung.com/java-mock-same-method-other-parameters) +- [How to Mock Constructors for Unit Testing using Mockito](https://www.baeldung.com/java-mockito-constructors-unit-testing) From 62d47b8accf734082f6fc7414ced3caac705b24f Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:07:58 +0800 Subject: [PATCH 039/193] Update README.md [skip ci] --- core-java-modules/core-java-concurrency-collections-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-concurrency-collections-2/README.md b/core-java-modules/core-java-concurrency-collections-2/README.md index 2d65cf88e7..fdb7af5936 100644 --- a/core-java-modules/core-java-concurrency-collections-2/README.md +++ b/core-java-modules/core-java-concurrency-collections-2/README.md @@ -5,4 +5,5 @@ - [Java Concurrent HashSet Equivalent to ConcurrentHashMap](https://www.baeldung.com/java-concurrent-hashset-concurrenthashmap) - [Reading and Writing With a ConcurrentHashMap](https://www.baeldung.com/concurrenthashmap-reading-and-writing) - [ArrayBlockingQueue vs. LinkedBlockingQueue](https://www.baeldung.com/java-arrayblockingqueue-vs-linkedblockingqueue) +- [Difference Between Hashtable and ConcurrentHashMap in Java](https://www.baeldung.com/java-hashtable-vs-concurrenthashmap) - [[<-- Prev]](/core-java-modules/core-java-concurrency-collections) From 55c63f99116ebd66491483e13dfac1ba00c59ae0 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:15:27 +0800 Subject: [PATCH 040/193] Update README.md [skip ci] --- testing-modules/junit-5-basics-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing-modules/junit-5-basics-2/README.md b/testing-modules/junit-5-basics-2/README.md index f5e2558332..0e0faedb4b 100644 --- a/testing-modules/junit-5-basics-2/README.md +++ b/testing-modules/junit-5-basics-2/README.md @@ -1,2 +1,2 @@ ### Relevant Articles: -- [Test Main Method with JUnit](http://www.baeldung.com/junit-5) +- [Test Main Method with JUnit](https://www.baeldung.com/junit-test-main-method) From cd239006360e912337ce3af696a1d6d4c3042507 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:15:50 +0800 Subject: [PATCH 041/193] Update README.md [skip ci] From 7bf962ac8919587297fa2f7bf97e681d8dad3742 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:20:46 +0800 Subject: [PATCH 042/193] Update README.md [skip ci] --- persistence-modules/spring-data-cassandra-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/spring-data-cassandra-2/README.md b/persistence-modules/spring-data-cassandra-2/README.md index 3f49d6ae93..0578dcc429 100644 --- a/persistence-modules/spring-data-cassandra-2/README.md +++ b/persistence-modules/spring-data-cassandra-2/README.md @@ -2,3 +2,4 @@ - [Using Test Containers With Spring Data Cassandra](https://www.baeldung.com/spring-data-cassandra-test-containers) - [Cassandra – Object Mapping with DataStax Java Driver](https://www.baeldung.com/cassandra-object-mapping-datastax-java-driver) +- [Query With IN Clause in Spring Data Cassandra](https://www.baeldung.com/spring-cassandra-query-in-clause) From ed5c1ca1dace41243e3fb80dee5c826bbe22d929 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:25:05 +0800 Subject: [PATCH 043/193] Update README.md [skip ci] --- testing-modules/testing-assertions/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/testing-assertions/README.md b/testing-modules/testing-assertions/README.md index 37de3d4929..8f94277791 100644 --- a/testing-modules/testing-assertions/README.md +++ b/testing-modules/testing-assertions/README.md @@ -5,3 +5,4 @@ - [Assert That a Java Optional Has a Certain Value](https://www.baeldung.com/java-optional-assert-value) - [Assert That an Object Is From a Specific Type](https://www.baeldung.com/java-assert-object-of-type) - [Asserting Equality on Two Classes Without an equals() Method](https://www.baeldung.com/java-assert-equality-no-equals) +- [Assert Regex Matches in JUnit](https://www.baeldung.com/junit-assert-regex-matches) From 383ad4b354f23fc8b7ce00ef5321cff2f586f6ee Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:31:13 +0800 Subject: [PATCH 044/193] Update README.md [skip ci] --- core-java-modules/core-java-string-operations-5/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-string-operations-5/README.md b/core-java-modules/core-java-string-operations-5/README.md index 21ba1bf985..fda7f39654 100644 --- a/core-java-modules/core-java-string-operations-5/README.md +++ b/core-java-modules/core-java-string-operations-5/README.md @@ -10,4 +10,5 @@ - [Guide to Splitting a String by Whitespace in Java](https://www.baeldung.com/java-splitting-a-string-by-whitespace) - [Check if the First Letter of a String Is a Number](https://www.baeldung.com/java-check-if-string-starts-with-number) - [Print “” Quotes Around a String in Java](https://www.baeldung.com/java-string-print-quotes) -- [Remove Punctuation From a String in Java](https://www.baeldung.com/java-remove-punctuation-from-string) \ No newline at end of file +- [Remove Punctuation From a String in Java](https://www.baeldung.com/java-remove-punctuation-from-string) +- [Replacing Single Quote with \’ in Java String](https://www.baeldung.com/java-replacing-single-quote-string) From d185bbe19005685788f340ad92f1edb894c8d895 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:40:36 +0800 Subject: [PATCH 045/193] Update README.md [skip ci] --- core-java-modules/core-java-collections-set-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-collections-set-2/README.md b/core-java-modules/core-java-collections-set-2/README.md index feeffed1c4..ee41908faf 100644 --- a/core-java-modules/core-java-collections-set-2/README.md +++ b/core-java-modules/core-java-collections-set-2/README.md @@ -5,4 +5,5 @@ - [Sorting a HashSet in Java](https://www.baeldung.com/java-sort-hashset) - [How to Get First Item From a Java Set](https://www.baeldung.com/first-item-set) - [Cartesian Product of Any Number of Sets in Java](https://www.baeldung.com/java-cartesian-product-sets) +- [How to Get Index of an Item in Java Set](https://www.baeldung.com/java-set-element-find-index) - More articles: [[<-- prev]](/core-java-modules/core-java-collections-set) From 654c04d0f220f0ee34298bcf33c52e147d643608 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:48:07 +0800 Subject: [PATCH 046/193] Update README.md [skip ci] --- core-java-modules/core-java-8-datetime-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-8-datetime-2/README.md b/core-java-modules/core-java-8-datetime-2/README.md index b860ca979d..ac1e1ca81f 100644 --- a/core-java-modules/core-java-8-datetime-2/README.md +++ b/core-java-modules/core-java-8-datetime-2/README.md @@ -5,4 +5,5 @@ - [Parsing Date Strings with Varying Formats](https://www.baeldung.com/java-parsing-dates-many-formats) - [How Many Days Are There in a Particular Month of a Given Year?](https://www.baeldung.com/days-particular-month-given-year) - [Difference Between Instant and LocalDateTime](https://www.baeldung.com/java-instant-vs-localdatetime) +- [Add Minutes to a Time String in Java](https://www.baeldung.com/java-string-time-add-mins) - [[<-- Prev]](/core-java-modules/core-java-datetime-java8-1) From d1c7e516160660c37efb08dc5266b1851523cfa7 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:53:28 +0800 Subject: [PATCH 047/193] Update README.md [skip ci] --- spring-vault/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-vault/README.md b/spring-vault/README.md index 9e1d14ba6b..22fb0a7ff2 100644 --- a/spring-vault/README.md +++ b/spring-vault/README.md @@ -5,3 +5,4 @@ This module contains articles about Spring Vault ### Relevant Articles: - [Spring Vault](https://www.baeldung.com/spring-vault) +- [Secure Kubernetes Secrets with Vault](https://www.baeldung.com/spring-vault-kubernetes-secrets) From d83ba0aef8fd2b85ba8ffc34c1afc3fed1174698 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:55:24 +0800 Subject: [PATCH 048/193] Update README.md [skip ci] --- core-java-modules/core-java-21/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-21/README.md b/core-java-modules/core-java-21/README.md index c63f3b360b..2e7130c906 100644 --- a/core-java-modules/core-java-21/README.md +++ b/core-java-modules/core-java-21/README.md @@ -1 +1,2 @@ -## Relevant Articles \ No newline at end of file +## Relevant Articles +- [Sequenced Collections in Java 21](https://www.baeldung.com/java-21-sequenced-collections) From 3c898c96804044b551dee080d6befa6a318aa186 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:57:11 +0800 Subject: [PATCH 049/193] Update README.md [skip ci] --- gradle-modules/gradle-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle-modules/gradle-5/README.md b/gradle-modules/gradle-5/README.md index e37c100534..7871c0e822 100644 --- a/gradle-modules/gradle-5/README.md +++ b/gradle-modules/gradle-5/README.md @@ -2,3 +2,4 @@ - [Run a Java main Method Using Gradle](https://www.baeldung.com/gradle-run-java-main) - [Finding Unused Gradle Dependencies](https://www.baeldung.com/gradle-finding-unused-dependencies) +- [Intro to Gradle Lint Plugin](https://www.baeldung.com/java-gradle-lint-intro) From 30e4a9f12529e614452dd87f9ad35050394b0703 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:59:59 +0800 Subject: [PATCH 050/193] Update README.md [skip ci] --- spring-aop-2/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-aop-2/README.md b/spring-aop-2/README.md index a9694ac236..0aa20d32f0 100644 --- a/spring-aop-2/README.md +++ b/spring-aop-2/README.md @@ -7,4 +7,5 @@ This module contains articles about Spring aspect oriented programming (AOP) - [Spring Performance Logging](https://www.baeldung.com/spring-performance-logging) - [When Does Java Throw UndeclaredThrowableException?](https://www.baeldung.com/java-undeclaredthrowableexception) - [Get Advised Method Info in Spring AOP](https://www.baeldung.com/spring-aop-get-advised-method-info) -- More articles: [[<-- prev]](/spring-aop) \ No newline at end of file +- [Invoke Spring @Cacheable from Another Method of Same Bean](https://www.baeldung.com/spring-invoke-cacheable-other-method-same-bean) +- More articles: [[<-- prev]](/spring-aop) From ca1a5c36aca4492fb069688e4f8be96ca64568ea Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 21 Sep 2023 21:03:33 +0800 Subject: [PATCH 051/193] Update README.md [skip ci] --- spring-boot-modules/spring-boot-ssl-bundles/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-ssl-bundles/README.md b/spring-boot-modules/spring-boot-ssl-bundles/README.md index 5616cce48b..840cc21583 100644 --- a/spring-boot-modules/spring-boot-ssl-bundles/README.md +++ b/spring-boot-modules/spring-boot-ssl-bundles/README.md @@ -1 +1,2 @@ ## Relevant Articles +- [Securing Spring Boot 3 Applications With SSL Bundles](https://www.baeldung.com/spring-boot-security-ssl-bundles) From 7af1c7917f06688eb47d70d42062327c9527ca8b Mon Sep 17 00:00:00 2001 From: Bhaskar Ghosh Dastidar Date: Thu, 21 Sep 2023 21:53:10 +0530 Subject: [PATCH 052/193] BAEL-6823-middle-element-array (#14774) Co-authored-by: Bhaskar --- .../pom.xml | 46 +++++++++++++++++++ .../baeldung/arraymiddle/MiddleOfArray.java | 2 +- .../arraymiddle/MiddleOfArrayUnitTest.java | 2 +- core-java-modules/pom.xml | 1 + 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 core-java-modules/core-java-arrays-operations-advanced-2/pom.xml rename core-java-modules/{core-java-arrays-operations-advanced => core-java-arrays-operations-advanced-2}/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java (99%) rename core-java-modules/{core-java-arrays-operations-advanced => core-java-arrays-operations-advanced-2}/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java (99%) diff --git a/core-java-modules/core-java-arrays-operations-advanced-2/pom.xml b/core-java-modules/core-java-arrays-operations-advanced-2/pom.xml new file mode 100644 index 0000000000..53cccb8a73 --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced-2/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + core-java-arrays-operations-advanced-2 + core-java-arrays-operations-advanced-2 + jar + + + core-java-modules + com.baeldung.core-java-modules + 0.0.1-SNAPSHOT + + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + + + + + maven-assembly-plugin + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java similarity index 99% rename from core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java rename to core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java index f389893209..bfff003512 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java +++ b/core-java-modules/core-java-arrays-operations-advanced-2/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java @@ -62,4 +62,4 @@ public class MiddleOfArray { return array[mid]; } } -} +} \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java similarity index 99% rename from core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java rename to core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java index 706412d83e..64a9796e67 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java +++ b/core-java-modules/core-java-arrays-operations-advanced-2/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java @@ -86,4 +86,4 @@ public class MiddleOfArrayUnitTest { MiddleOfArray middleOfArray = new MiddleOfArray(); Assert.assertEquals(expectMedian, middleOfArray.medianOfArray(array, 0, 100)); } -} +} \ No newline at end of file diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 7fbd6cf657..34e5204868 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -65,6 +65,7 @@ core-java-arrays-convert core-java-arrays-operations-basic core-java-arrays-operations-advanced + core-java-arrays-operations-advanced-2 core-java-booleans core-java-char core-java-collections From e64dbf88ac7ccc72a82b32a64f1614627c209c2c Mon Sep 17 00:00:00 2001 From: Manfred <77407079+manfred106@users.noreply.github.com> Date: Thu, 21 Sep 2023 18:24:00 +0100 Subject: [PATCH 053/193] BAEL-6522: Expand Columns with Apache POI (#14801) --- apache-poi-3/pom.xml | 33 +++++++++ .../expandcolumn/ExpandColumnUnitTest.java | 70 +++++++++++++++++++ pom.xml | 2 + 3 files changed, 105 insertions(+) create mode 100644 apache-poi-3/pom.xml create mode 100644 apache-poi-3/src/test/java/com/baeldung/poi/excel/expandcolumn/ExpandColumnUnitTest.java diff --git a/apache-poi-3/pom.xml b/apache-poi-3/pom.xml new file mode 100644 index 0000000000..5031e1c5c7 --- /dev/null +++ b/apache-poi-3/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + apache-poi-3 + 0.0.1-SNAPSHOT + apache-poi-3 + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.apache.poi + poi-ooxml + ${poi.version} + + + org.apache.poi + poi-scratchpad + ${poi.version} + + + + + 5.2.3 + + + \ No newline at end of file diff --git a/apache-poi-3/src/test/java/com/baeldung/poi/excel/expandcolumn/ExpandColumnUnitTest.java b/apache-poi-3/src/test/java/com/baeldung/poi/excel/expandcolumn/ExpandColumnUnitTest.java new file mode 100644 index 0000000000..04d0aef211 --- /dev/null +++ b/apache-poi-3/src/test/java/com/baeldung/poi/excel/expandcolumn/ExpandColumnUnitTest.java @@ -0,0 +1,70 @@ +package com.baeldung.poi.excel.expandcolumn; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +import java.io.IOException; + +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ExpandColumnUnitTest { + + private Workbook workbook; + private Sheet sheet; + + @BeforeEach + void prepareSpreadsheet() { + workbook = new XSSFWorkbook(); + sheet = workbook.createSheet(); + + Row headerRow = sheet.createRow(0); + Cell headerCell1 = headerRow.createCell(0); + headerCell1.setCellValue("Full Name"); + Cell headerCell2 = headerRow.createCell(1); + headerCell2.setCellValue("Abbreviation"); + + Row dataRow = sheet.createRow(1); + Cell dataCell1 = dataRow.createCell(0); + dataCell1.setCellValue("Java Virtual Machine"); + Cell dataCell2 = dataRow.createCell(1); + dataCell2.setCellValue("JVM"); + + dataRow = sheet.createRow(2); + dataCell1 = dataRow.createCell(0); + dataCell1.setCellValue("Java Runtime Environment"); + dataCell2 = dataRow.createCell(1); + dataCell2.setCellValue("JRE"); + } + + @Test + void whenSetColumnWidth_thenColumnSetToTheSpecifiedWidth() { + + Row row = sheet.getRow(2); + String cellValue = row.getCell(0).getStringCellValue(); + int targetWidth = cellValue.length() * 256; + + sheet.setColumnWidth(0, targetWidth); + + assertEquals(targetWidth, sheet.getColumnWidth(0)); + } + + @Test + void whenAutoSizeColumn_thenColumnExpands() { + + int originalWidth = sheet.getColumnWidth(0); + + sheet.autoSizeColumn(0); + + assertThat(sheet.getColumnWidth(0)).isGreaterThan(originalWidth); + } + + @AfterEach + void cleanup() throws IOException { + workbook.close(); + } + +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index c65f6ce62d..060f158888 100644 --- a/pom.xml +++ b/pom.xml @@ -816,6 +816,7 @@ apache-olingo apache-poi-2 + apache-poi-3 apache-thrift apache-tika @@ -1089,6 +1090,7 @@ apache-olingo apache-poi-2 + apache-poi-3 apache-thrift apache-tika From f2b646005680f03581b8e0268e3a63a8451b38a3 Mon Sep 17 00:00:00 2001 From: Eugene Kovko <37694937+eukovko@users.noreply.github.com> Date: Thu, 21 Sep 2023 19:26:51 +0200 Subject: [PATCH 054/193] BAEL-6978: Adding the information about the bug (#14804) --- .../identity/IdentityHashMapDemonstrator.java | 2 +- .../IdentityHashMapDemonstratorUnitTest.java | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-collections-maps-5/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java b/core-java-modules/core-java-collections-maps-5/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java index 3cbe09b93f..3b98423120 100644 --- a/core-java-modules/core-java-collections-maps-5/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java +++ b/core-java-modules/core-java-collections-maps-5/src/main/java/com/baeldung/map/identity/IdentityHashMapDemonstrator.java @@ -53,7 +53,7 @@ public class IdentityHashMapDemonstrator { } } - private static class Book { + static class Book { String title; int year; diff --git a/core-java-modules/core-java-collections-maps-5/src/test/java/com/baeldung/map/identity/IdentityHashMapDemonstratorUnitTest.java b/core-java-modules/core-java-collections-maps-5/src/test/java/com/baeldung/map/identity/IdentityHashMapDemonstratorUnitTest.java index cc74ce4dd6..388338c3ab 100644 --- a/core-java-modules/core-java-collections-maps-5/src/test/java/com/baeldung/map/identity/IdentityHashMapDemonstratorUnitTest.java +++ b/core-java-modules/core-java-collections-maps-5/src/test/java/com/baeldung/map/identity/IdentityHashMapDemonstratorUnitTest.java @@ -1,8 +1,11 @@ package com.baeldung.map.identity; +import com.baeldung.map.identity.IdentityHashMapDemonstrator.Book; import org.junit.jupiter.api.Test; import java.util.IdentityHashMap; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -18,4 +21,44 @@ public class IdentityHashMapDemonstratorUnitTest { assertEquals("Fantasy", identityHashMap.get("genre")); assertEquals("Drama", identityHashMap.get(newGenreKey)); } + + @Test + @EnabledForJreRange(max = JRE.JAVA_19) + public void removeEntryComparingValueByEquality() { + Book book = new Book("A Passage to India", 1924); + IdentityHashMap identityHashMap = new IdentityHashMap<>(10); + identityHashMap.put(book, "A great work of fiction"); + identityHashMap.remove(book, new String("A great work of fiction")); + assertEquals(null, identityHashMap.get(book)); + } + + @Test + @EnabledForJreRange(max = JRE.JAVA_19) + public void replaceEntryComparingValueByEquality() { + Book book = new Book("A Passage to India", 1924); + IdentityHashMap identityHashMap = new IdentityHashMap<>(10); + identityHashMap.put(book, "A great work of fiction"); + identityHashMap.replace(book, new String("A great work of fiction"), "One of the greatest books"); + assertEquals("One of the greatest books", identityHashMap.get(book)); + } + + @Test + @EnabledForJreRange(min = JRE.JAVA_20) + public void dontRemoveEntryComparingValueByEquality() { + Book book = new Book("A Passage to India", 1924); + IdentityHashMap identityHashMap = new IdentityHashMap<>(10); + identityHashMap.put(book, "A great work of fiction"); + identityHashMap.remove(book, new String("A great work of fiction")); + assertEquals("A great work of fiction", identityHashMap.get(book)); + } + + @Test + @EnabledForJreRange(min = JRE.JAVA_20) + public void dontReplaceEntryComparingValueByEquality() { + Book book = new Book("A Passage to India", 1924); + IdentityHashMap identityHashMap = new IdentityHashMap<>(10); + identityHashMap.put(book, "A great work of fiction"); + identityHashMap.replace(book, new String("A great work of fiction"), "One of the greatest books"); + assertEquals("A great work of fiction", identityHashMap.get(book)); + } } From a7940d9658d262bf3671c99753b2d4ab8eead674 Mon Sep 17 00:00:00 2001 From: mcasari Date: Thu, 21 Sep 2023 20:28:15 +0200 Subject: [PATCH 055/193] BAEL-6846 - Convert from float to BigDecimal --- convert-float-to-bigdecimal/README.md | 7 ----- convert-float-to-bigdecimal/pom.xml | 16 ---------- .../src/main/resources/logback.xml | 14 --------- .../FloatToBigDecimalUnitTest.java | 24 ++++++++++---- shallow-deep-copy/README.md | 7 ----- shallow-deep-copy/pom.xml | 16 ---------- .../baeldung/shallowdeepcopy/Dependency.java | 23 -------------- .../com/baeldung/shallowdeepcopy/Main.java | 31 ------------------- .../src/main/resources/logback.xml | 14 --------- .../ShallowDeepCopyUnitTest.java | 28 ----------------- 10 files changed, 18 insertions(+), 162 deletions(-) delete mode 100644 convert-float-to-bigdecimal/README.md delete mode 100644 convert-float-to-bigdecimal/pom.xml delete mode 100644 convert-float-to-bigdecimal/src/main/resources/logback.xml rename convert-float-to-bigdecimal/src/test/java/com/baeldung/convertfloattobigdecimal/ConvertFloatToBigDecimalUnitTest.java => core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java (69%) delete mode 100644 shallow-deep-copy/README.md delete mode 100644 shallow-deep-copy/pom.xml delete mode 100644 shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Dependency.java delete mode 100644 shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Main.java delete mode 100644 shallow-deep-copy/src/main/resources/logback.xml delete mode 100644 shallow-deep-copy/src/test/java/com/baeldung/shallowdeepcopy/ShallowDeepCopyUnitTest.java diff --git a/convert-float-to-bigdecimal/README.md b/convert-float-to-bigdecimal/README.md deleted file mode 100644 index e01c981831..0000000000 --- a/convert-float-to-bigdecimal/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## Shallow vs Deep Copy - -This module contains an article about converting float to BigDecimal in Java - -### Relevant articles: - -- [Converting from Float to BigDecimal in Java](https://drafts.baeldung.com/?p=175240&preview=true) diff --git a/convert-float-to-bigdecimal/pom.xml b/convert-float-to-bigdecimal/pom.xml deleted file mode 100644 index 8fa20b300f..0000000000 --- a/convert-float-to-bigdecimal/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - 4.0.0 - convert-float-to-bigdecimal - convert-float-to-bigdecimal - jar - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - \ No newline at end of file diff --git a/convert-float-to-bigdecimal/src/main/resources/logback.xml b/convert-float-to-bigdecimal/src/main/resources/logback.xml deleted file mode 100644 index 830ab22727..0000000000 --- a/convert-float-to-bigdecimal/src/main/resources/logback.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/convert-float-to-bigdecimal/src/test/java/com/baeldung/convertfloattobigdecimal/ConvertFloatToBigDecimalUnitTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java similarity index 69% rename from convert-float-to-bigdecimal/src/test/java/com/baeldung/convertfloattobigdecimal/ConvertFloatToBigDecimalUnitTest.java rename to core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java index c43d2ab87a..20422edbd7 100644 --- a/convert-float-to-bigdecimal/src/test/java/com/baeldung/convertfloattobigdecimal/ConvertFloatToBigDecimalUnitTest.java +++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.convertfloattobigdecimal; +package com.baeldung.floattobigdecimal; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -7,7 +7,7 @@ import java.math.BigDecimal; import org.junit.jupiter.api.Test; -class ConvertFloatToBigDecimalUnitTest { +class FloatToBigDecimalUnitTest { @Test public void whenFloatComparedWithDifferentValues_thenCouldMatch() { @@ -16,12 +16,16 @@ class ConvertFloatToBigDecimalUnitTest { } @Test - public void whenCreatedFromFloat_thenCouldNotMatch() { + public void whenCreatedFromCertainFloatValues_thenMatches() { float floatToConvert = 0.5f; BigDecimal bdFromFloat = new BigDecimal(floatToConvert); assertEquals("0.5", bdFromFloat.toString()); - floatToConvert = 1.1f; - bdFromFloat = new BigDecimal(floatToConvert); + } + + @Test + public void whenCreatedFromCertainFloatValues_thenDoesNotMatch() { + float floatToConvert = 1.1f; + BigDecimal bdFromFloat = new BigDecimal(floatToConvert); assertNotEquals("1.1", bdFromFloat.toString()); } @@ -39,10 +43,18 @@ class ConvertFloatToBigDecimalUnitTest { assertNotEquals("1.1", bdByValueOf.toString()); } + @Test + public void whenFloatCastToDouble_thenGotADifferentNumber() { + float floatToConvert = 1.1f; + double doubleCast = floatToConvert; + assertEquals("1.100000023841858", Double.toString(doubleCast)); + } + @Test public void whenCreatedByValueOfAndIsDouble_thenMatches() { double doubleToConvert = 1.1d; BigDecimal bdByValueOf = BigDecimal.valueOf(doubleToConvert); assertEquals("1.1", bdByValueOf.toString()); } -} + +} \ No newline at end of file diff --git a/shallow-deep-copy/README.md b/shallow-deep-copy/README.md deleted file mode 100644 index e1a426a138..0000000000 --- a/shallow-deep-copy/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## Shallow vs Deep Copy - -This module contains an article about shallow vs deep copy of Java objects - -### Relevant articles: - -- [Creating a deep vs shallow copy of an object in Java](https://drafts.baeldung.com/?p=172294&preview=true) diff --git a/shallow-deep-copy/pom.xml b/shallow-deep-copy/pom.xml deleted file mode 100644 index 323f720df3..0000000000 --- a/shallow-deep-copy/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - 4.0.0 - shallow-deep-copy - shallow-deep-copy - jar - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - \ No newline at end of file diff --git a/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Dependency.java b/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Dependency.java deleted file mode 100644 index 2550acd268..0000000000 --- a/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Dependency.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.shallowdeepcopy; - -public class Dependency implements Cloneable { - private int value = 13; - - public Dependency(int value) { - super(); - this.value = value; - } - - public int getValue() { - return value; - } - - public void setValue(int value) { - this.value = value; - } - - @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); - } -} diff --git a/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Main.java b/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Main.java deleted file mode 100644 index 33d565bb10..0000000000 --- a/shallow-deep-copy/src/main/java/com/baeldung/shallowdeepcopy/Main.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.shallowdeepcopy; - -public class Main implements Cloneable { - private Dependency dependency; - - public Main(Dependency dependency) { - super(); - this.dependency = dependency; - } - - @Override - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - public Object deepClone() throws CloneNotSupportedException { - Main dependentClone = (Main) super.clone(); - Dependency dependencyClone = (Dependency) this.dependency.clone(); - dependentClone.setDependency(dependencyClone); - return dependentClone; - } - - public Dependency getDependency() { - return dependency; - } - - public void setDependency(Dependency dependency) { - this.dependency = dependency; - } - -} diff --git a/shallow-deep-copy/src/main/resources/logback.xml b/shallow-deep-copy/src/main/resources/logback.xml deleted file mode 100644 index 830ab22727..0000000000 --- a/shallow-deep-copy/src/main/resources/logback.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/shallow-deep-copy/src/test/java/com/baeldung/shallowdeepcopy/ShallowDeepCopyUnitTest.java b/shallow-deep-copy/src/test/java/com/baeldung/shallowdeepcopy/ShallowDeepCopyUnitTest.java deleted file mode 100644 index f75bbc040b..0000000000 --- a/shallow-deep-copy/src/test/java/com/baeldung/shallowdeepcopy/ShallowDeepCopyUnitTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.shallowdeepcopy; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - -class ShallowDeepCopyUnitTest { - - @Test - public void givenAnObjectAndADependency_whenShallowClonedAndDepencyChanges_ThenDepencyHasNewValue() throws Exception { - Dependency dependency = new Dependency(13); - Main main = new Main(dependency); - Main shallowClone = (Main) main.clone(); - dependency.setValue(17); - assertEquals(17, shallowClone.getDependency() - .getValue()); - } - - @Test - public void givenAnObjectAndADependency_whenDeepClonedAndDepencyChanges_ThenDepencyKeepsOldValue() throws Exception { - Dependency dependency = new Dependency(13); - Main main = new Main(dependency); - Main deepClone = (Main) main.deepClone(); - dependency.setValue(17); - assertEquals(13, deepClone.getDependency() - .getValue()); - } -} From 3cf341fb87767ee7db8e423ae93bdc2cc658241b Mon Sep 17 00:00:00 2001 From: Bipin kumar Date: Fri, 22 Sep 2023 01:41:55 +0530 Subject: [PATCH 056/193] JAVA-25297: Fix rethinkdb test failures on integration-jdk9-and-above (#14789) --- persistence-modules/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index ec02b0f37c..73c6b96bba 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -114,7 +114,7 @@ java-mongodb questdb neo4j - rethinkdb + scylladb spring-data-cassandra-2 spring-data-jpa-repo-3 From efab8b66cfb5ae6ab123f815ec19e9b70cd92159 Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Fri, 22 Sep 2023 11:21:24 +0530 Subject: [PATCH 057/193] Removing Maven Plugin --- .../pom.xml | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/core-java-modules/core-java-collections-array-list-2/pom.xml b/core-java-modules/core-java-collections-array-list-2/pom.xml index b0622368ad..9d8d7533b5 100644 --- a/core-java-modules/core-java-collections-array-list-2/pom.xml +++ b/core-java-modules/core-java-collections-array-list-2/pom.xml @@ -8,31 +8,4 @@ core-java-modules 0.0.1-SNAPSHOT - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${maven-compiler-plugin.source} - ${maven-compiler-plugin.target} - - - - org.apache.maven.plugins - maven-surefire-plugin - ${surefire.plugin.version} - - - --add-opens java.base/java.util=ALL-UNNAMED - - - - - - - 16 - 16 - 3.0.0-M3 - \ No newline at end of file From 2b7c4f684d9edbb5ef2764ae62462c48d99dee6a Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Fri, 22 Sep 2023 11:29:41 +0530 Subject: [PATCH 058/193] Removal of Surefire and Upgrading to JDK17 --- .../core-java-collections-array-list-2/pom.xml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core-java-modules/core-java-collections-array-list-2/pom.xml b/core-java-modules/core-java-collections-array-list-2/pom.xml index 9d8d7533b5..c9dd68b457 100644 --- a/core-java-modules/core-java-collections-array-list-2/pom.xml +++ b/core-java-modules/core-java-collections-array-list-2/pom.xml @@ -8,4 +8,20 @@ core-java-modules 0.0.1-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${maven-compiler-plugin.source} + ${maven-compiler-plugin.target} + + + + + + 17 + 17 + \ No newline at end of file From c757a1adc59b4a6668a5c227dfa4163fbdfb8d8f Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Fri, 22 Sep 2023 15:22:27 +0530 Subject: [PATCH 059/193] backlink updated --- aws-modules/aws-s3/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-modules/aws-s3/README.md b/aws-modules/aws-s3/README.md index cb039b7c61..9b862c8685 100644 --- a/aws-modules/aws-s3/README.md +++ b/aws-modules/aws-s3/README.md @@ -4,7 +4,7 @@ This module contains articles about Simple Storage Service (S3) on AWS ### Relevant articles -- [AWS S3 with Java](https://www.baeldung.com/aws-s3-java) +- [AWS S3 with Java](https://www.baeldung.com/java-aws-s3) - [Multipart Uploads in Amazon S3 with Java](https://www.baeldung.com/aws-s3-multipart-upload) - [Using the JetS3t Java Client With Amazon S3](https://www.baeldung.com/jets3t-amazon-s3) - [Check if a Specified Key Exists in a Given S3 Bucket Using Java](https://www.baeldung.com/java-aws-s3-check-specified-key-exists) From 1937f1a965ac45db5433c1e7626d7e45b769a768 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Fri, 22 Sep 2023 15:28:00 +0530 Subject: [PATCH 060/193] backlink updated --- core-java-modules/core-java-lang-oop-inheritance/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-lang-oop-inheritance/README.md b/core-java-modules/core-java-lang-oop-inheritance/README.md index 430f88e717..6091b15024 100644 --- a/core-java-modules/core-java-lang-oop-inheritance/README.md +++ b/core-java-modules/core-java-lang-oop-inheritance/README.md @@ -12,4 +12,4 @@ This module contains articles about inheritance in Java - [Guide to Inheritance in Java](https://www.baeldung.com/java-inheritance) - [Object Type Casting in Java](https://www.baeldung.com/java-type-casting) - [Variable and Method Hiding in Java](https://www.baeldung.com/java-variable-method-hiding) -- [Inner Classes Vs. Subclasses in Java](https://www.baeldung.com/java-inner-classes-vs-subclasses) +- [Inner Classes vs. Subclasses in Java](https://www.baeldung.com/java-inner-classes-vs-subclasses) From 65d94649f10dd91165f31b14fb428477929c2afd Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Fri, 22 Sep 2023 16:37:25 +0300 Subject: [PATCH 061/193] [JAVA-22209] Upgraded spring-cloud-netflix-feign module to jdk17 --- .../spring-cloud-netflix-feign/pom.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spring-cloud-modules/spring-cloud-netflix-feign/pom.xml b/spring-cloud-modules/spring-cloud-netflix-feign/pom.xml index f519b6316b..92d66c03df 100644 --- a/spring-cloud-modules/spring-cloud-netflix-feign/pom.xml +++ b/spring-cloud-modules/spring-cloud-netflix-feign/pom.xml @@ -58,6 +58,20 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens java.base/java.lang=ALL-UNNAMED + + + + + + Camden.SR7 8.18.0 From ab389ff0096d6f279fe4ed24752f95bc4b0e213e Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Fri, 22 Sep 2023 16:37:34 +0300 Subject: [PATCH 062/193] [JAVA-22209] Upgraded spring-cloud-netflix-feign module to jdk17 --- pom.xml | 5 ++++- spring-cloud-modules/pom.xml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 86d7d3328c..80a450314d 100644 --- a/pom.xml +++ b/pom.xml @@ -723,10 +723,12 @@ spring-boot-rest spring-drools spring-cloud-modules/spring-cloud-azure + spring-cloud-modules/spring-cloud-circuit-breaker spring-cloud-modules/spring-cloud-contract spring-cloud-modules/spring-cloud-data-flow - spring-cloud-modules/spring-cloud-circuit-breaker + spring-cloud-modules/spring-cloud-netflix-feign spring-cloud-modules/spring-cloud-zuul-eureka-integration + spring-exceptions spring-jenkins-pipeline spring-core @@ -1001,6 +1003,7 @@ spring-cloud-modules/spring-cloud-azure spring-cloud-modules/spring-cloud-circuit-breaker spring-cloud-modules/spring-cloud-contract + spring-cloud-modules/spring-cloud-netflix-feign spring-cloud-modules/spring-cloud-zuul-eureka-integration spring-exceptions spring-jenkins-pipeline diff --git a/spring-cloud-modules/pom.xml b/spring-cloud-modules/pom.xml index 73276d7e0f..27a5f5363c 100644 --- a/spring-cloud-modules/pom.xml +++ b/spring-cloud-modules/pom.xml @@ -46,7 +46,7 @@ spring-cloud-eureka-self-preservation spring-cloud-openfeign - spring-cloud-netflix-feign + spring-cloud-netflix-sidecar spring-cloud-sentinel spring-cloud-dapr From 0907865ea61a29f726d90eed034fc60adce8f954 Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Fri, 22 Sep 2023 16:52:18 +0300 Subject: [PATCH 063/193] [JAVA-22209] Upgraded spring-cloud-stream-starters module to jdk17 --- pom.xml | 3 ++- spring-cloud-modules/pom.xml | 2 +- .../spring-cloud-stream-starters/twitterhdfs/pom.xml | 8 +++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 80a450314d..0edd6b2b36 100644 --- a/pom.xml +++ b/pom.xml @@ -727,8 +727,8 @@ spring-cloud-modules/spring-cloud-contract spring-cloud-modules/spring-cloud-data-flow spring-cloud-modules/spring-cloud-netflix-feign + spring-cloud-modules/spring-cloud-stream-starters spring-cloud-modules/spring-cloud-zuul-eureka-integration - spring-exceptions spring-jenkins-pipeline spring-core @@ -1004,6 +1004,7 @@ spring-cloud-modules/spring-cloud-circuit-breaker spring-cloud-modules/spring-cloud-contract spring-cloud-modules/spring-cloud-netflix-feign + spring-cloud-modules/spring-cloud-stream-starters spring-cloud-modules/spring-cloud-zuul-eureka-integration spring-exceptions spring-jenkins-pipeline diff --git a/spring-cloud-modules/pom.xml b/spring-cloud-modules/pom.xml index 27a5f5363c..b21b208414 100644 --- a/spring-cloud-modules/pom.xml +++ b/spring-cloud-modules/pom.xml @@ -27,7 +27,7 @@ spring-cloud-gateway spring-cloud-gateway-2 spring-cloud-stream - spring-cloud-stream-starters + spring-cloud-connectors-heroku spring-cloud-aws spring-cloud-consul diff --git a/spring-cloud-modules/spring-cloud-stream-starters/twitterhdfs/pom.xml b/spring-cloud-modules/spring-cloud-stream-starters/twitterhdfs/pom.xml index 51e8703e6e..1a19415a3f 100644 --- a/spring-cloud-modules/spring-cloud-stream-starters/twitterhdfs/pom.xml +++ b/spring-cloud-modules/spring-cloud-stream-starters/twitterhdfs/pom.xml @@ -61,16 +61,21 @@ org.junit.vintage junit-vintage-engine + + org.codehaus.groovy + groovy + ${groovy.version} + + twitterhdfs org.springframework.boot spring-boot-maven-plugin - twitterhdfs @@ -83,6 +88,7 @@ 4.13.2 5.8.1 2.17.1 + 3.0.8 \ No newline at end of file From e9d8fd0f5582116a5a32a4fcabf283b86b53d77f Mon Sep 17 00:00:00 2001 From: Gaetano Piazzolla Date: Fri, 22 Sep 2023 18:22:57 +0200 Subject: [PATCH 064/193] JAVA-71 | added custom dockerfile to run preconfigured couchbase instance (#14663) --- .../src/test/docker/Dockerfile | 4 + .../src/test/docker/configure.sh | 106 ++++++++++++++++++ .../src/test/docker/dockerbuild.sh | 14 +++ .../com/baeldung/SpringContextLiveTest.java | 21 ++-- .../CustomTypeKeyCouchbaseConfig.java | 26 ----- .../ReadYourOwnWritesCouchbaseConfig.java | 11 -- 6 files changed, 132 insertions(+), 50 deletions(-) create mode 100644 persistence-modules/spring-data-couchbase-2/src/test/docker/Dockerfile create mode 100644 persistence-modules/spring-data-couchbase-2/src/test/docker/configure.sh create mode 100644 persistence-modules/spring-data-couchbase-2/src/test/docker/dockerbuild.sh delete mode 100644 persistence-modules/spring-data-couchbase-2/src/test/java/com/baeldung/spring/data/couchbase/CustomTypeKeyCouchbaseConfig.java delete mode 100644 persistence-modules/spring-data-couchbase-2/src/test/java/com/baeldung/spring/data/couchbase/ReadYourOwnWritesCouchbaseConfig.java diff --git a/persistence-modules/spring-data-couchbase-2/src/test/docker/Dockerfile b/persistence-modules/spring-data-couchbase-2/src/test/docker/Dockerfile new file mode 100644 index 0000000000..1dffcb31f1 --- /dev/null +++ b/persistence-modules/spring-data-couchbase-2/src/test/docker/Dockerfile @@ -0,0 +1,4 @@ +FROM couchbase/server:community-5.0.1 + +COPY configure.sh /configure.sh +CMD ["/configure.sh"] \ No newline at end of file diff --git a/persistence-modules/spring-data-couchbase-2/src/test/docker/configure.sh b/persistence-modules/spring-data-couchbase-2/src/test/docker/configure.sh new file mode 100644 index 0000000000..c2b62dba7c --- /dev/null +++ b/persistence-modules/spring-data-couchbase-2/src/test/docker/configure.sh @@ -0,0 +1,106 @@ +#!/bin/bash + +function retry() { + for i in $(seq 1 10); do + $1 "$2" + if [[ $? == 0 ]]; then + return 0 + fi + sleep 1 + done + return 1 +} + +function bucketCreate(){ + couchbase-cli bucket-create -c localhost -u Administrator -p password \ + --bucket="$1" \ + --bucket-type=couchbase \ + --bucket-ramsize=512 \ + --bucket-replica=1 \ + --wait + if [[ $? != 0 ]]; then + return 1 + fi +} + +function userCreate(){ + createOutput=$(couchbase-cli user-manage -c localhost -u Administrator -p password \ + --set --rbac-username "$1" --rbac-password "$1" \ + --roles admin --auth-domain local) + if [[ $? != 0 ]]; then + echo $createOutput >&2 + return 1 + fi +} + +function clusterUp(){ + # wait for service to come up + until $(curl --output /dev/null --silent --head --fail http://localhost:8091); do + printf '.' + sleep 1 + done + + # initialize cluster + initOutput=$(couchbase-cli cluster-init -c localhost \ + --cluster-username=Administrator \ + --cluster-password=password \ + --cluster-port=8091 \ + --services=data,index,query,fts \ + --cluster-ramsize=1024 \ + --cluster-index-ramsize=256 \ + --cluster-fts-ramsize=256 \ + --index-storage-setting=default) + if [[ $? != 0 ]]; then + echo $initOutput >&2 + return 1 + fi +} + +function main(){ + set -ex + echo "Couchbase UI :8091" + echo "Couchbase logs /opt/couchbase/var/lib/couchbase/logs" + ./entrypoint.sh couchbase-server & + if [[ $? != 0 ]]; then + echo "Couchbase startup failed. Exiting." >&2 + exit 1 + fi + + clusterUp + if [[ $? != 0 ]]; then + echo "Cluster init failed. Exiting." >&2 + exit 1 + fi + + retry userCreate baeldung + if [[ $? != 0 ]]; then + echo "User create failed. Exiting." >&2 + exit 1 + fi + + retry userCreate baeldung2 + if [[ $? != 0 ]]; then + echo "User create failed. Exiting." >&2 + exit 1 + fi + + retry bucketCreate baeldung + if [[ $? != 0 ]]; then + echo "Bucket create failed. Exiting." >&2 + exit 1 + fi + + retry bucketCreate baeldung2 + if [[ $? != 0 ]]; then + echo "Bucket create failed. Exiting." >&2 + exit 1 + fi + + set +ex + + # entrypoint.sh launches the server but since config.sh is pid 1 we keep it + # running so that the docker container does not exit. + wait +} + +main \ No newline at end of file diff --git a/persistence-modules/spring-data-couchbase-2/src/test/docker/dockerbuild.sh b/persistence-modules/spring-data-couchbase-2/src/test/docker/dockerbuild.sh new file mode 100644 index 0000000000..37add165c6 --- /dev/null +++ b/persistence-modules/spring-data-couchbase-2/src/test/docker/dockerbuild.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# setup +set -ex +docker rm couchbase_container -f + +# main +docker build -t couchbase_image . + +# cleanup +set +ex + +# run +docker run -d --name couchbase_container -p 8091-8096:8091-8096 -p 11210-11211:11210-11211 couchbase_image diff --git a/persistence-modules/spring-data-couchbase-2/src/test/java/com/baeldung/SpringContextLiveTest.java b/persistence-modules/spring-data-couchbase-2/src/test/java/com/baeldung/SpringContextLiveTest.java index 553520e6e6..74dccbadd0 100644 --- a/persistence-modules/spring-data-couchbase-2/src/test/java/com/baeldung/SpringContextLiveTest.java +++ b/persistence-modules/spring-data-couchbase-2/src/test/java/com/baeldung/SpringContextLiveTest.java @@ -12,16 +12,10 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution /** * This LiveTest requires: * - * 1- Couchbase instance running (e.g. with `docker run -d --name db -p 8091-8096:8091-8096 -p 11210-11211:11210-11211 couchbase`) - * - * - * 2- Couchbase configured with (we can use the console in localhost:8091): - * - * 2.1- Buckets: named 'baeldung' and 'baeldung2' - * - * 2.2- Security: users 'baeldung' and 'baeldung2'. Note: in newer versions an empty password is not allowed, then we have to change the passwords in the project) - * - * 2.3- Spacial View: Add new spacial view (in Index tab) in document 'campus_spatial', view 'byLocation' with the following function: + * 1- Couchbase 5 instance Running and Configured. + * It's enough to execute the "dockerbuild.sh" script in the test/docker folder. + * + * 2.1- Spacial View: Add new spacial view (in Index tab) in document 'campus_spatial', view 'byLocation' with the following function: * {@code * function (doc) { * if (doc.location && @@ -30,8 +24,9 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution * } * }} * - * 2.4- MapReduce Views: Add new views in document 'campus': - * 2.4.1- view 'all' with function: + * 2.2- MapReduce Views: Add new views in document 'campus': + * + * 2.2.1- view 'all' with function: * {@code * function (doc, meta) { * if(doc._class == "com.baeldung.spring.data.couchbase.model.Campus") { @@ -39,7 +34,7 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution * } * }} * - * 2.4.2- view 'byName' with function: + * 2.2.2- view 'byName' with function: * {@code * function (doc, meta) { * if(doc._class == "com.baeldung.spring.data.couchbase.model.Campus" && diff --git a/persistence-modules/spring-data-couchbase-2/src/test/java/com/baeldung/spring/data/couchbase/CustomTypeKeyCouchbaseConfig.java b/persistence-modules/spring-data-couchbase-2/src/test/java/com/baeldung/spring/data/couchbase/CustomTypeKeyCouchbaseConfig.java deleted file mode 100644 index eacecb4e1e..0000000000 --- a/persistence-modules/spring-data-couchbase-2/src/test/java/com/baeldung/spring/data/couchbase/CustomTypeKeyCouchbaseConfig.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.spring.data.couchbase; - -import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter; - -public class CustomTypeKeyCouchbaseConfig extends MyCouchbaseConfig { - - @Override - public String getConnectionString() { - return NODE_LIST; - } - - @Override - public String getUserName() { - return BUCKET_USERNAME; - } - - @Override - public String getPassword() { - return BUCKET_PASSWORD; - } - - @Override - public String typeKey() { - return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE; - } -} diff --git a/persistence-modules/spring-data-couchbase-2/src/test/java/com/baeldung/spring/data/couchbase/ReadYourOwnWritesCouchbaseConfig.java b/persistence-modules/spring-data-couchbase-2/src/test/java/com/baeldung/spring/data/couchbase/ReadYourOwnWritesCouchbaseConfig.java deleted file mode 100644 index 33a6c4f091..0000000000 --- a/persistence-modules/spring-data-couchbase-2/src/test/java/com/baeldung/spring/data/couchbase/ReadYourOwnWritesCouchbaseConfig.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.spring.data.couchbase; - -import com.couchbase.client.java.query.QueryScanConsistency; - -public class ReadYourOwnWritesCouchbaseConfig extends MyCouchbaseConfig { - - @Override - public QueryScanConsistency getDefaultConsistency() { - return QueryScanConsistency.REQUEST_PLUS; - } -} From 8ea2cc9703ff037de2fbc3bd466c5ca96808222b Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Sat, 23 Sep 2023 02:59:43 +0200 Subject: [PATCH 065/193] [duration-improvement] isNegative, isZero Tests (#14791) --- .../dateapi/JavaDurationUnitTest.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/dateapi/JavaDurationUnitTest.java b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/dateapi/JavaDurationUnitTest.java index be43fb609a..d1bd77776a 100644 --- a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/dateapi/JavaDurationUnitTest.java +++ b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/dateapi/JavaDurationUnitTest.java @@ -3,9 +3,11 @@ package com.baeldung.dateapi; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.Duration; import java.time.Instant; +import java.time.LocalDateTime; import java.time.LocalTime; import java.time.temporal.ChronoUnit; @@ -19,7 +21,7 @@ public class JavaDurationUnitTest { LocalTime finalTime = initialTime.plus(Duration.ofSeconds(30)); long seconds = Duration.between(initialTime, finalTime) - .getSeconds(); + .getSeconds(); assertThat(seconds).isEqualTo(30); } @@ -34,6 +36,22 @@ public class JavaDurationUnitTest { assertThat(seconds).isEqualTo(30); } + @Test + public void givenADuration_whenCallingisZeroAndisNegative_thenGetExpectedResult() { + LocalDateTime start = LocalDateTime.parse("2020-01-01T08:00:00"); + LocalDateTime end = LocalDateTime.parse("2020-01-01T12:00:00"); + assertFalse(Duration.between(start, end) + .isNegative()); + assertTrue(Duration.between(end, start) + .isNegative()); + + LocalDateTime theTime = LocalDateTime.parse("2023-09-09T08:00:00"); + assertTrue(Duration.between(theTime, theTime) + .isZero()); + assertFalse(Duration.between(theTime, theTime) + .isNegative()); + } + @Test public void test2() { Instant start = Instant.parse("2017-10-03T10:15:30.00Z"); @@ -53,17 +71,17 @@ public class JavaDurationUnitTest { assertEquals(1, fromMinutes.toHours()); assertEquals(120, duration.plusSeconds(60) - .getSeconds()); + .getSeconds()); assertEquals(30, duration.minusSeconds(30) - .getSeconds()); + .getSeconds()); assertEquals(120, duration.plus(60, ChronoUnit.SECONDS) - .getSeconds()); + .getSeconds()); assertEquals(30, duration.minus(30, ChronoUnit.SECONDS) - .getSeconds()); + .getSeconds()); Duration fromChar1 = Duration.parse("P1DT1H10M10.5S"); Duration fromChar2 = Duration.parse("PT10M"); } -} +} \ No newline at end of file From b5c06059f031bad344d00259899499c5b0fe5a2a Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Sat, 23 Sep 2023 17:30:40 +0330 Subject: [PATCH 066/193] #BAEL-6916: refactor dependencies --- messaging-modules/apache-camel/pom.xml | 54 +++++--------------------- 1 file changed, 10 insertions(+), 44 deletions(-) diff --git a/messaging-modules/apache-camel/pom.xml b/messaging-modules/apache-camel/pom.xml index 026983484b..88c807a86a 100644 --- a/messaging-modules/apache-camel/pom.xml +++ b/messaging-modules/apache-camel/pom.xml @@ -16,69 +16,35 @@ - - org.springframework.boot - spring-boot-starter-web - org.apache.camel.springboot camel-spring-boot-starter ${camel.version} - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - org.apache.camel - camel-test-spring-junit5 - ${camel.version} - test - - - org.apache.camel - camel-http - ${camel.version} - - - org.apache.camel.springboot - camel-bindy-starter - ${camel.version} - org.apache.camel.springboot camel-jackson-starter ${camel.version} + + org.apache.camel + camel-test-spring-junit5 + ${camel.version} + test + org.junit.platform junit-platform-launcher test + + org.springframework.boot + spring-boot-starter-web + 3.21.0 - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M5 - - - \ No newline at end of file From c56bc04f95f7b9c9929d32f5c02ee359d8535265 Mon Sep 17 00:00:00 2001 From: mcasari Date: Sat, 23 Sep 2023 17:02:20 +0200 Subject: [PATCH 067/193] BAEL-6846 - change assertNotEquals to assertEquals --- .../baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java index 20422edbd7..2d6d1ab5d0 100644 --- a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java +++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java @@ -26,7 +26,7 @@ class FloatToBigDecimalUnitTest { public void whenCreatedFromCertainFloatValues_thenDoesNotMatch() { float floatToConvert = 1.1f; BigDecimal bdFromFloat = new BigDecimal(floatToConvert); - assertNotEquals("1.1", bdFromFloat.toString()); + assertEquals("1.10000002384185791015625", bdFromFloat.toString()); } @Test @@ -40,7 +40,7 @@ class FloatToBigDecimalUnitTest { public void whenCreatedByValueOfAndIsFloat_thenDoesNotMatch() { float floatToConvert = 1.1f; BigDecimal bdByValueOf = BigDecimal.valueOf(floatToConvert); - assertNotEquals("1.1", bdByValueOf.toString()); + assertEquals("1.100000023841858", bdByValueOf.toString()); } @Test From 1a9337f238c5350fa493c82beb97d23a6313abcf Mon Sep 17 00:00:00 2001 From: Nadia <62909670+nadiahylary@users.noreply.github.com> Date: Sat, 23 Sep 2023 17:08:15 +0100 Subject: [PATCH 068/193] BAEL-6921, How To Convert Excel Data Into List Of Java Objects (#14813) * BAEL-6921, How To Convert Excel Data into List of Java Objects * BAEL-6921, How To Convert Excel Data into List of Java Objects --- apache-poi-3/pom.xml | 64 ++++++++++++++++++ .../convert/exceldatatolist/FoodInfo.java | 54 +++++++++++++++ .../ExcelDataToListOfObjectsFastExcel.java | 42 ++++++++++++ .../ExcelDataToListOfObjectsJxl.java | 37 ++++++++++ .../poi/ExcelDataToListApachePOI.java | 39 +++++++++++ .../poiji/ExcelDataToListOfObjectsPOIJI.java | 13 ++++ apache-poi-3/src/main/resources/food_info.xls | Bin 0 -> 29696 bytes .../src/main/resources/food_info.xlsx | Bin 0 -> 6389 bytes .../ExcelDataToListOfObjectsUnitTest.java | 53 +++++++++++++++ 9 files changed, 302 insertions(+) create mode 100644 apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/FoodInfo.java create mode 100644 apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/fastexcel/ExcelDataToListOfObjectsFastExcel.java create mode 100644 apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/jexcelapi/ExcelDataToListOfObjectsJxl.java create mode 100644 apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poi/ExcelDataToListApachePOI.java create mode 100644 apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poiji/ExcelDataToListOfObjectsPOIJI.java create mode 100644 apache-poi-3/src/main/resources/food_info.xls create mode 100644 apache-poi-3/src/main/resources/food_info.xlsx create mode 100644 apache-poi-3/src/test/java/com/baeldung/convert/exceldatatolist/ExcelDataToListOfObjectsUnitTest.java diff --git a/apache-poi-3/pom.xml b/apache-poi-3/pom.xml index 5031e1c5c7..905db3d58c 100644 --- a/apache-poi-3/pom.xml +++ b/apache-poi-3/pom.xml @@ -24,10 +24,74 @@ poi-scratchpad ${poi.version} + + + com.github.ozlerhakan + poiji + ${poiji.version} + + + + + org.apache.poi + poi + ${poi.version} + + + + org.apache.poi + poi-ooxml-schemas + 4.1.2 + + + + org.apache.xmlbeans + xmlbeans + 5.1.1 + + + + org.apache.commons + commons-collections4 + 4.4 + + + + org.dhatim + fastexcel + ${fastexcel.version} + + + + org.dhatim + fastexcel-reader + ${fastexcel.version} + + + + net.sourceforge.jexcelapi + jxl + ${jxl.version} + + + + org.apache.logging.log4j + log4j-api + 2.17.1 + + + + org.apache.logging.log4j + log4j-core + 2.17.1 + 5.2.3 + 4.1.1 + 0.15.7 + 2.6.12 \ No newline at end of file diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/FoodInfo.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/FoodInfo.java new file mode 100644 index 0000000000..b8fe4522de --- /dev/null +++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/FoodInfo.java @@ -0,0 +1,54 @@ +package com.baeldung.convert.exceldatatolist; + +import com.poiji.annotation.ExcelCellName; + +public class FoodInfo { + + @ExcelCellName("Category") + private String category; //food category + @ExcelCellName("Name") + private String name; // food name + @ExcelCellName("Measure") + private String measure; + @ExcelCellName("Calories") + private double calories; //amount of calories in kcal/measure + + @Override + public String toString() { + return "FoodInfo{" + "category='" + category + '\'' + ", name='" + name + '\'' + ", measure='" + measure + '\'' + ", calories=" + calories + "} \n"; + } + + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMeasure() { + return measure; + } + + public void setMeasure(String measure) { + this.measure = measure; + } + + public double getCalories() { + return calories; + } + + public void setCalories(double calories) { + this.calories = calories; + } + +} diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/fastexcel/ExcelDataToListOfObjectsFastExcel.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/fastexcel/ExcelDataToListOfObjectsFastExcel.java new file mode 100644 index 0000000000..87d31520e6 --- /dev/null +++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/fastexcel/ExcelDataToListOfObjectsFastExcel.java @@ -0,0 +1,42 @@ +package com.baeldung.convert.exceldatatolist.fastexcel; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Stream; + +import org.dhatim.fastexcel.reader.ReadableWorkbook; +import org.dhatim.fastexcel.reader.Row; +import org.dhatim.fastexcel.reader.Sheet; + +import com.baeldung.convert.exceldatatolist.FoodInfo; + +public class ExcelDataToListOfObjectsFastExcel { + public static List excelDataToListOfObjets_withFastExcel(String fileLocation)throws IOException, NumberFormatException { + List foodData = new ArrayList(); + + try (FileInputStream file = new FileInputStream(fileLocation); + ReadableWorkbook wb = new ReadableWorkbook(file)) { + Sheet sheet = wb.getFirstSheet(); + for (Row row: + sheet.read() + ) { + if(row.getRowNum() == 1) { + continue; + } + FoodInfo food = new FoodInfo(); + food.setCategory(row.getCellText(0)); + food.setName(row.getCellText(1)); + food.setMeasure(row.getCellText(2)); + food.setCalories(Double.parseDouble(row.getCellText(3))); + + foodData.add(food); + + } + } + + return foodData; + } +} diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/jexcelapi/ExcelDataToListOfObjectsJxl.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/jexcelapi/ExcelDataToListOfObjectsJxl.java new file mode 100644 index 0000000000..61ba5e4700 --- /dev/null +++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/jexcelapi/ExcelDataToListOfObjectsJxl.java @@ -0,0 +1,37 @@ +package com.baeldung.convert.exceldatatolist.jexcelapi; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import com.baeldung.convert.exceldatatolist.FoodInfo; + +import jxl.Sheet; +import jxl.Workbook; +import jxl.read.biff.BiffException; + +public class ExcelDataToListOfObjectsJxl { + public static List excelDataToListOfObjets_withJxl(String fileLocation) throws IOException, BiffException { + + List foodData = new ArrayList(); + + Workbook workbook = Workbook.getWorkbook(new File(fileLocation)); + Sheet sheet = workbook.getSheet(0); + + int rows = sheet.getRows(); + + for (int i = 1; i < rows; i++) { + FoodInfo foodInfo = new FoodInfo(); + + foodInfo.setCategory(sheet.getCell(0, i).getContents()); + foodInfo.setName(sheet.getCell(1, i).getContents()); + foodInfo.setMeasure(sheet.getCell(2, i).getContents()); + foodInfo.setCalories(Double.parseDouble(sheet.getCell(3, i).getContents())); + + foodData.add(foodInfo); + + } + return foodData; + } +} diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poi/ExcelDataToListApachePOI.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poi/ExcelDataToListApachePOI.java new file mode 100644 index 0000000000..8b568b889a --- /dev/null +++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poi/ExcelDataToListApachePOI.java @@ -0,0 +1,39 @@ +package com.baeldung.convert.exceldatatolist.poi; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.poi.ss.usermodel.DataFormatter; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import com.baeldung.convert.exceldatatolist.FoodInfo; + +public class ExcelDataToListApachePOI { + public static List excelDataToListOfObjets_withApachePOI(String fileLocation) throws IOException { + FileInputStream file = new FileInputStream(new File(fileLocation)); + Workbook workbook = new XSSFWorkbook(file); + Sheet sheet = workbook.getSheetAt(0); + List foodData = new ArrayList(); + DataFormatter dataFormatter = new DataFormatter(); + for (int n = 1; n < sheet.getPhysicalNumberOfRows(); n++) { + Row row = sheet.getRow(n); + FoodInfo foodInfo = new FoodInfo(); + int i = row.getFirstCellNum(); + + foodInfo.setCategory(dataFormatter.formatCellValue(row.getCell(i))); + foodInfo.setName(dataFormatter.formatCellValue(row.getCell(++i))); + foodInfo.setMeasure(dataFormatter.formatCellValue(row.getCell(++i))); + foodInfo.setCalories(Double.parseDouble(dataFormatter.formatCellValue(row.getCell(++i)))); + + foodData.add(foodInfo); + + } + return foodData; + } +} diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poiji/ExcelDataToListOfObjectsPOIJI.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poiji/ExcelDataToListOfObjectsPOIJI.java new file mode 100644 index 0000000000..be190d38f7 --- /dev/null +++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poiji/ExcelDataToListOfObjectsPOIJI.java @@ -0,0 +1,13 @@ +package com.baeldung.convert.exceldatatolist.poiji; + +import java.io.File; +import java.util.List; + +import com.baeldung.convert.exceldatatolist.FoodInfo; +import com.poiji.bind.Poiji; + +public class ExcelDataToListOfObjectsPOIJI { + public static List excelDataToListOfObjets_withPOIJI(String fileLocation){ + return Poiji.fromExcel(new File(fileLocation), FoodInfo.class); + } +} diff --git a/apache-poi-3/src/main/resources/food_info.xls b/apache-poi-3/src/main/resources/food_info.xls new file mode 100644 index 0000000000000000000000000000000000000000..1377d8e18dbe6036c1bf4df453ece2142f2be588 GIT binary patch literal 29696 zcmeHQ33wCL_PJR>>^U3 z@KB(F2neDqkHv*WP!vRqD6%{@5d={|eezHq3gmyzolG*BOw#tRe&7H9eVKlfnS1WN zzjN-n=bpRFo$2St!oFVf&o-Bc=y;I$ko(p^;xC}f;JybR4kZw8wPKLJX2Ly?yvP3| z4FoEnBK`fy=%Ggg-Y0V6uOQ?ST(|jRh>**0jwO>w2q8LysiH_{GEQdAmhq|-=5IZ+ zsSH{f%5VS-uMgbGNF7kaNHmqKCH-whf49a!PxVTSjha>#dZ)P1K$8y z4&|vQg_M88l6jW96v|^Om4w_%nG9n0qN*igeLcpW2OYZ4i~0)Vv?+m%vEd$LdwYz1 z&_k?@WVtO7%ADpQmOw1E07;o;B+z5tAP;%vq_v0GhBO%{nYV*)JK_hpBqlbdv$AvN zl<|qZ#wPHAv56ggJAoH(=M+C?1Y0!DIZ+G=AnhHAl2e>8Q~mF>(S27_{kzh)x}mRdL*L|v?ha?AoAhtGp}*{g{)QX+|2293=|)a> z`r*=pw-VLYHj3j)f6fhkha394Zs@z*&^dXUyU4SdrVr!kOT)rmZ1!R^;=7E}TiNNw z#rr$%??`;#rt|>tA=D243km4K*=GQ_Gikcg4ZW)*JpwQ(&Mh0ft$hXabi4g?b`r?b zPmp173$2EeC&-x|$RLIF=*AG|kEqVG0G68Pe@c1owx?N7r&I5RQ zU07ITvq;c0*B)VPYRBjF%;`S>`d}%2!r)a>KTr^kegcM7B*m_WaGowImmkonpLrB+ z@bG`IBl>f9betv8^e6xxHoxSWUKz>Z$hh=lx#Yy3r>6qFGY+}A!$$Xqo{8dPMdRTX ze{~3lFUH~NV!rO^ygaVyrz^tAbiSNam_g*&*4key72Qas6P*f5nuFeOXbFcE2NBTy zc5MNgl)Gj?cP(#925!jO1P(q;<>1@Y3|Qq&Dg)Y1lQLjqX;KEPlqO|Bx6z~w=ueuI z0Ub?~GN9o%DFeFnCS^e1)T9jP{5)nDCTb54LIxjd-e`ts?0kFhwY8Cc<`1po6S+aD zpMb{Lj!K0XGwUzF6t~;HfXNk1ET^sAiiOZLD8$Y~*IWvQH1`F|{u?lJ{sK&~vidbu zS-A}gapv-WT$F`0_sYuq8!-F-4VVKO#B92u3~UgyVSS1#H3=|1Hf?bRWm7YBYifq% zre=WYaMQ}r%bo$7J)XRK!e%e4RA@y03}(v$eE4$byt>5=vk!>j@WxPA&Nkp$iXM=`VKfkM&cK(#YOQxE#rEynU5rLZ<4b`w0Hz0T zG(wu||RmtJk2p$5L-$N06WH^SOh0Y zP(3_|d%uNKa|eiUFiWN5K-gkumn)V8=j9E8)aQE!fu-$+LB!5qEJ z2C2{Y4AP-7AS$(IkT@q02uSM$=jiTrg3E`E(1~Y|=*EE5=X(a}*ccF%+A~PJ69@#P zb%M(f?sbAoagET4XAoFuY#5|I-!ll)7!Z}(Ge{RF5C}-?1Xo(z>jam38=(`=AZ;51 zQlIY`q*G%+RB9o}5_wA!3f&h`rNlAa7>!QH8ZD`{iov87RcAY7z8$R1;W=Rni6ac@ z2B(JT;EyFnV!`Kepa2;OCIP-|@tJG)tbTZpy$y8gakz?zY{JBBRIY4dJh0*BAe4`J(Y+8xgq`9)`>VXZ;V{A$bV2i)_<*YQD za50;7S2oEW*x+=*#zw&wTQAj1vxyM1$#7+(^1y~0)>5Sfvc+eA`HwW4NMw`d+0r@! zo3ut)T7CYG&;F2R(^||%!qPf>U?a4&`uy8Fw@9;z60?!8v@Ral2raEX|K63A(rlu| zY$Pl#$pagqrPb%Z_RZVUY}$y~NLX5T4{U^%R-bSEXt^|-wqiCCmZtW=MrdjE`MbXP zPMS?SWRv09(imWq(FjXZsh{6i}k=pXlW|-&6>H=Y&wY9NLX5e2R1@W zQ>pL$t5ljzM==`-OH+DaBeXP?`l(Y(rP(lIHWHSW;(?9O(p2jE8%m_vbP}_Xu(UJ} zY=oAkQrDcmAjKvaHrl|r%ieElMEz!aYk=Fnl922VJjDB-a6mBH|E(GCh0B?j#z z0u@>jAwT4#OM}KbK*4^*pm8Elq0JET$6jA)&^QMuSc@1mQ3NWq5aO->O zL3WY72lm575m+I_(GlL`GNP@%z@NZ$A0lx*Lk5Y3A%#;Y&?&S;9s>Kr;JIN= zDXW{vV0L&F@nGr*rvDqM=9gF>O9^HSmZlfPXmF2qa4 zg?OpB&=OeTN~-p;)+!ihQT%*>Ne-x_4F0shiV#eztoDbr38J+Auy5LtmLX%HCm3hX z)2-SU^2Ces_*xZ^rvi3+n(5eAN2b|xBv%JOj$~1e0Bf*I4rg8wq&tkjN$%812CY$R zF`1_^qu8mIT19_nD0#Xyl;o1Bu+10i-bm};1cFQhosR->rh+}-;uT-}SlKr73WT!3 z@=Sk|2@JKDGp?+S)tB@KrI|#giYwwg7BJ(nTEKW8W)K5dZIRws!oXZXB&bg)Xm$Vy zgto5-K}$eDZjL}r09UQ}c>$VY07%9;!X@$+Fv$>rgYOfAhe?2Q{?84#HS3iReush} zxLODfK2QwaQUaXwgKogNp@E!&rwPHq7m6H$Pb&#<^oLxH1qju$L>@%ap(4pZy+;u95{!GlRv6KIZVXIW(gSPlV8H&X|JP>%Kj0X};myg>mFLrfO7R#E7T zArFG~f*2MMia_~z&x;Gyyi3DHW{0EYLcB}kLcB}kLQCY$NKXQbT0<)=w8p21m_`8f zP^tshIv2Wp^pH+`1N@@g) zB#WSQVemH!KniJTM}o-H=-pr_J37M(usaoKQBNjQ3v#5u7E}VgC@!aDkO}mKhdEHH zJ{r`rKN(rdvX;~piYT%|z*B~iaNu<@7gjJn&MzqTV7#iX`I1i*0bf{lCxQOqeNT6mctr+Hp`loOcC1+ zhAXC0lR^I!Tcl(X^0kG9S__k$K5B3x7(^lwee5PZ&7mY0E849`w8A@ZdhDRIi)J z8kusfv1p23SE^(RL4qRitU6mv5(BU96zR)g5w4s`VkWaCtVLUBV9Nn2)t(Q~Gt??c zz!J0GU}y{=V5rsUo$W$7WC7urVyN{ZCSj7E)v@JRCn|=!his}IYS`vrD~m)nAeoFT z$Xw1O7%NJk1m%fPi5ZM7Kq1m$Ulu?Z^jKgp6tfYlTa}pty-l_jI~yFVl*2>C9Ie@G zvM8BSQyE(Z%3`MIEv1Z3P<4!6hs`=c#Tc~H&@xqOT^UoP*Onzhb*6StRRMH*nhLBi zhlP9wrcev1ip>>z3scPLD`5z9Kl*O{&04*YH(y8v8B^8i@F0r zCeyQLET7V5B1}TMR9b{h!=mPtYV}}wT8o8Rdsv;5!FboL0iQ1Gecc~hRT&p zo|!f3N>M9ZbI4Rd^Kp|3dUDnQc^(3Jbig7HdiP`nbr)7;+u=zM6u-Q8Sp$DyjU@$RzgeC z8o~NNWmv?_LGJ5tT?N;5FySl!m~@yUeh1f2;ra}SI|4R%_<>u}DI(zn0NW91yUNKj zMQ-3SK@3I=d&tK(92`87JCX0d3fT`m3~2{^TETTpj>%{NZ!mt;v`K9Fxa6s2hBp^~ zI^^k^T-G)J1Z)PXOUT@of-1>`|L(gn}Wd4jcQN6Y6LteVI`@Ovhne(a# z&R;QN{nOu0D#_p8r)H74^}XsAM=OS(kGej8agT3~YbNjFE84;J1b+zn}c!`vvwS)J#k~>oxCHF*~y>0+vV5fbxHHr9DVGAQFo%Z zefKz<{zdx6ub7+7o^N?@Tk!nx$4Z#!Zr|?jwQBy2bEh6N?7dL4y=HpGSr z_m0?-UG&9~(Bp%0&!rW{R&7}PV|zebKYojGC43mcDEcN|QqUp4go zs;$baxxU8CrTO|Rg=;o;|7PUAMH|^oCpvt->zzBN?mNm48Kf4%ya^*wKA5+!^G=Gjgn*8kB|DLYg(01e50qs6g8ZI4<`1bp$QAc(zY;|$q z$K}H-JD*%MXY;NL%&A>TCp-PDyzuzDu}}0_(7)ijFK;Ja&b^)#A0+P~Eqrmiy3YHc zrOb!zyVx28Vsk}EMX~D(#+c5ggg>)-r#19yWt=Qq7O^Svx!<S#K5bGJ?~7v`|^VQx-DB)mtXE(cxcDW83jQON=`=l!C z+3Cx7w`l!r-m~H1-OsnKzi|EPwV?&2$s_7?0jEYj*uPn3#H)27{=I$Gms{t~Pn^D> z*|N^Et;*!cNQ${ zFn#{l$}^i4H{4Cc;EXK4zFNg_%k2&! z8{RJ-`(s)4E#2wc7miL%3sUaARCVIg-goznoAy?f-|_p0+utpnu5O;U3#$0mP#`pbVu`kgdA(BBx= zdQ`jXYujCDZSWz1u>*=ugmsUr8Lrqj?Vze(Y}>TM8!vXa`CzYl#-# zYzZFqjXrj^cJ!^HuA9b2r6q5$ z7Cvd*tQ|M~mFBZo4AN};&(29*){@cj{jPqnP?L5kwfmYWJqC{rSnT^#t2GmTKd^eO zGVYtgg;O`R+S0H88=6&t_3dh}HY=EWap{a<>pMNSGRs%<-)&clnWT;j+l609R@La* z1?{*oH@A57{+S<4-2C0WP0Ln?EK6F@XX(=`^M-y_bK}fV-)@m(e^<>Ie#r0nHZLDd z(9K=6>)sTm;2$@BJ0ErR@n@GNZi;^{@!K|A`t4k^_Nx``qD&9hFB;Z4?j&wo+l6_xz24aM z)7Ps$&kr0hb;o_s>K>XqMCbkc6Tzi#r=i{38I zyJZYGv?D(2&0aS~r+oD5z7g!`d#%%~J0tcy9r{B0*fqENO?r6HU1ikFH$Hyk!oW6X zhCTFRm87?7{>7rzZ$U$E3$a~94W4t+)CCB9md#}k4*DP^eD>{`QxqoCm%Bq3$6t8% z^UWuGW?xBfo{<$h{Kk*Xwhb@cloYT=9O{J2z_j zj))vG|4gr3-B%d;^hpxEY}g9xj(a`Y%rEKQF>>7f;hOR@bNmusJyid7 z=arlCeLoqqd-sPIpZH8cq_#>CoO3L`my|*y;oAPfWw1n3#qe8^tu- z*e9mp#x^1C9&Kxc;OkR_a3TD>0}8=~6I>vkRt~=Cl1Na1qt=(kjbCQgtmft z{i#eml0P8j(cwGFWZ+A4zENgBKJj0FX5FdjNUk_7KVx10j?t$OQ>KibJMmRHn|hyv?XgvGx#ZJkEv$?^}y(9Q}|( zreG>lye%*GVGhd-rW)^JLkf05LYvjV!)#77%_&l%J%n}F)gHpqB|!*F*W3jOtvlC_ zge@}{zWTx8V(S_R+Xwj&mM+d+Fb~hsk<#N_D&jm3l5>BOR*t^xFBJx za`=K!Dic1CL@NjdB!@2urB(pzK(utBE=brS9WsScnXpSmBpfMd?7kq3%9Lh93Ufii z*6NU{C6x)*l_(N^G%44P)RM}SVMA)^f`si;0}s)-ysfBAJ?tTrsi!@Jb%(Eh<6e)u0iI*vY>Ir)d zlqtdm3HvCAOp#QkEE`g!lT49RroJ|$NEamZMGl!-Q<*e2q}EO{wWcy<+mKqjAYp%~ z0Znq{iK0mT>><=R@5iGkQmzdt$^{91V6Gi0nwBolhJ+u`%7s3G;}T6vH^7Dz?Syn1 z9#_r=S9eR6O$Igb??Kp^`xbTr&;xS^mSh2pr5B(ZwjbHxWwD*n1G{NFmV=13!6k~; zq(qPyI$PY#5B46<(1iQviI7J_k<4i*lIr;r-XJmaLp4jef=71FM z;njdw16~byHQ?2NR|8%Rcs1bFfL8-v4R|%+)qqz6e^LXU=Ku1OM^Dxzw+&tLBFz7l zcedbse;b@Q=g0Z~061~!3+Mf~^!zBCILDs=CqMtkMYc(B;<~_8IB}g|0i68005{JM zrTKyE_Syk}ktaS1;5ICiU?3q3E-fJY0+V@SIqqdHr;ACL+Ix64;MIUv16~byHQ?2N zR|8%Rcs1bFfL8-v4R|%+)c|S$XURB;#(6kArl-&LanA*{5zhBTtr2+u;~EJHZ(P zXJ)dkCr-@YiOG9ktB860=G3BVuQ p5VoJj^2g1RwDG{j54I+n;Ijw#`abu~!=}m8<9|_p-0H~l{~uzn-h}`F literal 0 HcmV?d00001 diff --git a/apache-poi-3/src/main/resources/food_info.xlsx b/apache-poi-3/src/main/resources/food_info.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..c604ff367dc000a5d5fe5e00a7d3c1b4444b1e80 GIT binary patch literal 6389 zcmai21z1$;)}}j#?hXlwp}R#wYUq~kMnaGpx}`->BnFg_Qb3xKmJ;cdmZ6ap@E`Er zE64wybJxr>v-h+2diVa;x9VM*s>mqB2pAX`2)@)j`Utm#9DeNQ%wz3o;p^aP=k@Oc zAh(~3bMCOIYX>h5`X131p6h2pb-@zhX6!cmwxH9 z-2qqc_ooV$M1f43)r6>zNow~^necYqYSP(6!X_SqyA@56J6(U&QV5n0H5D^%2bdLC z6FiBB8mZ_>iY@ZtY>d|8uFykL#9m_#D*NaSmTulVkip0f_*nmvb!oF5IU9NT@JekW z{JkL7iEJ+Qxd=lzspUE9iS1(9YxD{&NzDtyuHZ2KSfnVS432sj`;?O0r39wP73I-f z52&SY%)DogxEqm11A4bX{&7!K6{}fGs*R%WPH3GyGEHcIPrb~^1uh2U-PUkAK z`SMRSjCJOks^}Q#mJVQ4L<9tMWCR4w|7A*FH%})odm9^XFP@vfU#5I!?3J%V91+}p zhEKYSxwFQaA@(RA5-<;e46Z)YB7BWu5HfOhf*$HVRjOQe$Oq&!cME9njY@yfS?3g( z(-dV$Th#kGulqF+Gu8A%Qp!Zp{)zbzKEG88nQS$Fq5~m!!h(fspz&o@ec_aG5C+r| zM5=U9M{h>0M4Z_^R;;Q zYU-i<{>}@UPT6B0DakYzjaBZTd)+0crrV`lhb;nwhJ0?0616k+<%4pq;@WKiB-jm}7 zN58Wdjb3JjRame(daG)D^RUAzgW~Ssf+rqqg8Lgr_<>F$vcf2%ItztIDu>j;5I~nt~ zXj#Y*`lziIO)D#JnIQNvd6M1&7gLu=?;XrDbzA*jqqY`-&)diWpV)Ayj}ei2lKYgp zQ^z*JeDdUYxc;LxRtYazPuZjJP|;FBJKc|4L|#gtvP78!Z7WzWf;bK9>PUUNQF~Es z66$M=eUCHC<-<O9+4&Fo%RWtr|3r5PwIC*C11kkhLhmuxnEezJnaw~C{OhwDK z3T`ZqPwxAFrr$a(a|%b(;1}wqqNAzic6+jujGcnrN9SRXsQsh%#S)HZ5@na=efv3H zW+|^JnM>t&lWlHPkaZ$r%-Bs%`O@Zxa^`i~P=hezF6bznWwit{JWJw4t>A zXTItI5vI87urM*;@0MQ$P%y<}{3LQg@J9ZWNfEl2ERzM^qBy~n{dM`Sf+;y;yx5{P z_;mIT-y+dyGW3vEmKy2i!30`lF&LvbrwSiK`QOCoxhn!mL?w<1J~C=Dv&D9$5Ih=* zzIaO&8x4iNjFc^q@*#dvl$?rETPYt~$uf4^vQ_?tH_i{5>T%!}xf`YJFepe7 zb%hD8uM)q?G_uMhJIUkz#^RJ=47iw0E~ z*dp<6uu0GZ)Om!jB!GFugifZBPNq2C`FBwfEAkTgkwEGZn!EwQ5m-Rmi}SoA5eKvVZ$A^G+Cz>GwN z%*61xR7~}!`=@lpVv+UQWRMB47uMOe)d-W5KFwdANnvwq9fe{K z3v4TfyB5(tRD$3;(=zXm%sfxXU+h@@G!zIm7sThUp^6X@<$Se*%3Iy{trw4QaL%I{ znUu&Vp{9n};uVHk^BZ*mt3F|moIq=eDy@#Jlm%>pF(ou6-xtp6kI8T#5|OfgI%L#J z&asx99mR-8nY~6_47DFn#<^ZxRhcem#Nw%&;!b^Eju=MVZ7^U3;-oRVUrjedQ|w3; zOk>{09uZyJpu7a8Rs&xl2fPIRefc5!Wdm<}8y6d%o8OztGoU}?I!h0@47);JYHpus zW^dH0ey&Srq`UcklfP=esC^Pi$l8fExEt6l>!w%JWjyQ z$==)m03cnl=vxxJIP&`Gj~JSq6_K?TU-p%VV9)XJ8{u1PIX`e~DVG?`UE z-9#&;K5|FEI*U~C64lbu}2y?cZqG?)KvV;2B2{&$+fhY39AzMKq?_CxaT%Ej;V?57S zZT#Zox&~igJjYlJd>KZqHKMvTpS$6ch#*M4OKIw9XhIWU?$wJ>BlVWR! zyj3>m=`bkc?4Th4`kLSAct2QVDVlF-0gqt{T`hFf#cHQhvm%UW1Z~2MM{h1P#v}uZ zic_X=XDBe;zU7vGrXlF^fyMH^w+NH}Ec~)zynog2b*>i0VQ0V>O59zvz7PC+C4)II z&TIrSC-T>@2e>tI`WZCB?Vp}1z)8>v_(9*N74SNFnTiI!$-Bqm8zqKec;4$>R~86Ay&!HE?=s2YFxSN6wrOUG>rb#q)EYM1L zW7o*KiSwxJL}RA6`V9R#&}<4qE!f~aUOC=B1sd_MK=ZP<@U*ek_V&E)n{V1>y&2bO znd?Y{_JEl6Sti%Ab!5II6Y64plOM$=-|C#VZC3T2C|rSwqfP737AQQC-NFf2dpyY3 zaIVWSi3KYh8KwW$g@}=x{a`bYGBDU6#~fu*ViPBQ#FBC=9J|7HmvzuTuXI`s-0@?e zo6XaKLB-p&h9FzQ$x8LRcdh@5klw>JEQY|>`DWBf`GiGy^n&Tf#6q+vnhs|*goj|8 zS$tcfJ9b3U&kM*Jsv4D7>{3hK(`=m>#6n!yhjlZat*14mcL;7zgmH8?4KO&P^LZq4 z2u5ff7+TX{?7F{`!=L*KJ$Q1cg2cWFsmlDgJsj}~TO>?gMC!-kqj%tPEnRk_J^ikL zPDfSl^D-0N^0sFn1u63M#h#UDjjz!><09SHJ6)&rm zu^^B2Ih%k;{%GohIJ`1Pv*`E(2|pj^cR#JOXM-36L?3 z%J>s{M&kj$@#RLJgru}#7g))N(Q?c>gjwqoiiEPc%=r)~?18cs!&YdADHmpQkdYi~ z)rv_hq0s2pkR(HZgfa%<q=XoXpu5uzG;0Zxk z%G2c#k3yz!Xk8vNm^7oHP-i%xA_|$*o4dK3`l7^|gT4kNJ&wyabYx@$(rwupk#j{2 z1bv?x&kyQwP}g~#xnHW|e6gTufhL@hks7%rR$2M|4PON-7p17Jmn5R%(epb7Ok^sG zjFEet1t}K|luc)A45$01Ha1nZz$})X_;EIxR_YoDo z$J^i8<|c3k^!q)Z^AcZ|sDdY9RSqD#kO!NQ>cZa`cOKLsg^wuUE2e1oOz6u2+^b9* zJ;aXDcI4NoD=KL5Tsc*8?3kI??xM`EqKHHnNkE-R!sz->mx$a8!|sB^`H90QmEEbH zU=+T=e0&!GN>qHvhY|r=O@Q^)$`JRdnlVC{M9GLbTw>EXRYM=L4$!O2ezW#m1w~U- zVhE?NL%qZ0Jvi!D8a_M_edPaQnKF?Mr)k}yM9G}76UgnT|sU?jq`fPOU``+ivp;NyPb8HF&Icn;_R#R-VYND?~RrygR1e4Ii%dz?S-QXaQDJt3NJv%C!j;-%^ zoD-|QTz)wI9v^HbS))2gp+3m{+HQKjIQ{52VfSa+u6wR)02clZ5|wbMz8lZbEQkEw z!)Q$R6hT%jeySOf6+v6QqxHsw<6xTn8`lj;@L>&syKXSfKe;acFW0^9GcDcRoNlsy ziYk0a0*KTY7FU=DTPbixD^2R8!@twCZIeWnU+-H#7np5HO;*Tv&ab%0ag&<*>AFCf zE3gRm6uRU5ECr>^9Whd?q=Sqf4wn zAQ}q?UsWI6nflou%EWyc6FH5X`3fmoaa1?EMH8CNA}qJI&TC@Gf%sP41ZUC@>^Cft z|D;5RMlsug&Rr36H;i)`B*LFOETd_U`d#k1I0MrfImOOU=Ht*FO0GneQorqH)(5Gn zadlH|1`jAr)gmuzx;FMb`^OKP=xDuE>wJ&704SC`-Y)Ru|pu+W%uC*3n0z+NAe(Ny1FASpl0Vz_Q^p;L!X0r|E_1A zI#)`VxxY|p7*xj0&VZ{o*L>euoL0YJ9ZwC-Yi!+>H0Q8OK^ykqVI}C39TIkpQrsOgh{$TOVO=9)iDk2 zjC<&0wv|frNmkhiQeXl0!|lyIy5}EUHT@VLy&UPHBQcL*R(0dWGGM)8mY$F9y8EiF zG$mNVpc%e2bc{l`SM=5Jg|Pik5@amz=IU+Z>TRy$?{4E|dL5+iwENZJUU7kR#c)6( z=qgGdo_*Z5jG>f!`zxqG@@sVoIv*O ze3`dlLP3TxNu7rq>cna7PL=IeEXPWgQjOW%#{{nztu@l^JrhqrDUQR4=?wXHg?PQP zYc@uG7>=l_X~N6<M$S$&y@Mmj`uXTJLcte~rh@_If_-zsR}~3zG+(AYRFr`X_Ktv>npL4f zUEy891^QJo_XixldO=|3MqYOO^cM^0g2|e#>mL&!3_Q|!IipePl{SM61IP;9y)3Yy zfH-J`Z;xm?e=s(6%4SGVlYOaZ244Kn?SUtem13LyJ9a}YH&%CvuGJKTTbu&r+QAT! zh!K8|k#A2$ugA!LmA@M*|A}&&;Qtjx75-c}$}Lj=d!G6y%592#Jq-9QU1)!z{MXUI zpMbZiz%{e}Eq&-WfPeDrKLKv{Lf4GpxA4Q`5x%bf#~=PgxLuO2d#2yw1?MN%2> foodInfoList = ExcelDataToListOfObjectsPOIJI.excelDataToListOfObjets_withPOIJI("src/main/resources/food_info.xlsx"); + + assertEquals("Beverages", foodInfoList.get(0).getCategory()); + assertEquals("Dairy", foodInfoList.get(3).getCategory()); + } + + @Test + public void whenParsingExcelFileWithApachePOI_thenConvertsToList() throws IOException { + List foodInfoList = ExcelDataToListApachePOI.excelDataToListOfObjets_withApachePOI("src/main/resources/food_info.xlsx"); + + assertEquals("Beverages", foodInfoList.get(0).getCategory()); + assertEquals("Dairy", foodInfoList.get(3).getCategory()); + } + + @Test + public void whenParsingExcelFileWithFastExcel_thenConvertsToList() throws IOException { + List foodInfoList = ExcelDataToListOfObjectsFastExcel.excelDataToListOfObjets_withFastExcel("src/main/resources/food_info.xlsx"); + + assertEquals("Beverages", foodInfoList.get(0).getCategory()); + assertEquals("Dairy", foodInfoList.get(3).getCategory()); + } + + @Test + public void whenParsingExcelFileWithJxl_thenConvertsToList() throws IOException, BiffException { + List foodInfoList = ExcelDataToListOfObjectsJxl.excelDataToListOfObjets_withJxl("src/main/resources/food_info.xls"); + + assertEquals("Beverages", foodInfoList.get(0).getCategory()); + assertEquals("Dairy", foodInfoList.get(3).getCategory()); + } + +} From 8171a4604fb08728ae4c122a6e8853d7c7aa85b9 Mon Sep 17 00:00:00 2001 From: Eugene Kovko <37694937+eukovko@users.noreply.github.com> Date: Sun, 24 Sep 2023 04:22:37 +0200 Subject: [PATCH 069/193] BAEL-6985: Patterns With Locales (#14808) --- .../datetime/DateTimeFormatterUnitTest.java | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java index 172882af2c..d5128c522e 100644 --- a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java +++ b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java @@ -96,7 +96,8 @@ public class DateTimeFormatterUnitTest { String newYorkDateTimePattern = "dd.MM.yyyy HH:mm z"; DateTimeFormatter newYorkDateFormatter = DateTimeFormatter.ofPattern(newYorkDateTimePattern); LocalDateTime summerDay = LocalDateTime.of(2016, 7, 31, 14, 15); - Assert.assertEquals("31.07.2016 14:15 EDT", newYorkDateFormatter.format(ZonedDateTime.of(summerDay, ZoneId.of("America/New_York")))); + Assert.assertEquals("31.07.2016 14:15 EDT", + newYorkDateFormatter.format(ZonedDateTime.of(summerDay, ZoneId.of("America/New_York")))); } @Test @@ -121,8 +122,10 @@ public class DateTimeFormatterUnitTest { @Test public void shouldPrintFormattedDateTimeWithPredefined() { Assert.assertEquals("2018-03-09", DateTimeFormatter.ISO_LOCAL_DATE.format(LocalDate.of(2018, 3, 9))); - Assert.assertEquals("2018-03-09-03:00", DateTimeFormatter.ISO_OFFSET_DATE.format(LocalDate.of(2018, 3, 9).atStartOfDay(ZoneId.of("UTC-3")))); - Assert.assertEquals("Fri, 9 Mar 2018 00:00:00 -0300", DateTimeFormatter.RFC_1123_DATE_TIME.format(LocalDate.of(2018, 3, 9).atStartOfDay(ZoneId.of("UTC-3")))); + Assert.assertEquals("2018-03-09-03:00", + DateTimeFormatter.ISO_OFFSET_DATE.format(LocalDate.of(2018, 3, 9).atStartOfDay(ZoneId.of("UTC-3")))); + Assert.assertEquals("Fri, 9 Mar 2018 00:00:00 -0300", + DateTimeFormatter.RFC_1123_DATE_TIME.format(LocalDate.of(2018, 3, 9).atStartOfDay(ZoneId.of("UTC-3")))); } @Test @@ -165,30 +168,62 @@ public class DateTimeFormatterUnitTest { public void shouldPrintFormattedZonedDateTime() { ZonedDateTime zonedDateTime = ZonedDateTime.of(2021, 02, 15, 0, 0, 0, 0, ZoneId.of("Europe/Paris")); String formattedZonedDateTime = DateTimeFormatter.ISO_INSTANT.format(zonedDateTime); - + Assert.assertEquals("2021-02-14T23:00:00Z", formattedZonedDateTime); } - + @Test(expected = UnsupportedTemporalTypeException.class) public void shouldExpectAnExceptionIfInputIsLocalDateTime() { DateTimeFormatter.ISO_INSTANT.format(LocalDate.now()); } - + @Test public void shouldParseZonedDateTime() { DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.systemDefault()); ZonedDateTime zonedDateTime = ZonedDateTime.parse("2021-10-01T05:06:20Z", formatter); - + Assert.assertEquals("2021-10-01T05:06:20Z", DateTimeFormatter.ISO_INSTANT.format(zonedDateTime)); } - + @Test(expected = DateTimeParseException.class) public void shouldExpectAnExceptionIfTimeZoneIsMissing() { ZonedDateTime zonedDateTime = ZonedDateTime.parse("2021-11-01T05:06:20Z", DateTimeFormatter.ISO_INSTANT); } - + @Test(expected = DateTimeParseException.class) public void shouldExpectAnExceptionIfSecondIsMissing() { ZonedDateTime zonedDateTime = ZonedDateTime.parse("2021-12-02T08:06Z", DateTimeFormatter.ISO_INSTANT); } + + @Test + public void testUSShortFormatting() { + LocalDate date = LocalDate.of(2023, 9, 18); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd, yy: EEE").withLocale(Locale.US); + String formattedDate = date.format(formatter); + Assert.assertEquals("Sep 18, 23: Mon", formattedDate); + } + + @Test + public void testUSFullFormatting() { + LocalDate date = LocalDate.of(2023, 9, 18); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy: EEEE").withLocale(Locale.US); + String formattedDate = date.format(formatter); + Assert.assertEquals("September 18, 2023: Monday", formattedDate); + } + + @Test + public void testKoreanShortFormatting() { + LocalDate date = LocalDate.of(2023, 9, 18); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd, yy: EEE").withLocale(Locale.KOREA); + String formattedDate = date.format(formatter); + Assert.assertEquals("9월 18, 23: 월", formattedDate); + } + + @Test + public void testKoreanFullFormatting() { + LocalDate date = LocalDate.of(2023, 9, 18); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy: EEEE").withLocale(Locale.KOREA); + String formattedDate = date.format(formatter); + Assert.assertEquals("9월 18, 2023: 월요일", formattedDate); + } } From 6c4848958f18c84133b79301fe06ab896aee7b85 Mon Sep 17 00:00:00 2001 From: Azhwani <13301425+azhwani@users.noreply.github.com> Date: Sun, 24 Sep 2023 04:43:53 +0200 Subject: [PATCH 070/193] BAEL-6783: Converting HashMap to an ArrayList in Java (#14814) --- .../README.md | 5 ++ .../pom.xml | 26 ++++++++ .../HashMapToArrayListConverterUtils.java | 66 +++++++++++++++++++ ...hMapToArrayListConverterUtilsUnitTest.java | 60 +++++++++++++++++ 4 files changed, 157 insertions(+) create mode 100644 core-java-modules/core-java-collections-conversions-3/README.md create mode 100644 core-java-modules/core-java-collections-conversions-3/pom.xml create mode 100644 core-java-modules/core-java-collections-conversions-3/src/main/java/com/baeldung/hashmaptoarraylist/HashMapToArrayListConverterUtils.java create mode 100644 core-java-modules/core-java-collections-conversions-3/src/test/java/com/baeldung/hashmaptoarraylist/HashMapToArrayListConverterUtilsUnitTest.java diff --git a/core-java-modules/core-java-collections-conversions-3/README.md b/core-java-modules/core-java-collections-conversions-3/README.md new file mode 100644 index 0000000000..f89cd199ff --- /dev/null +++ b/core-java-modules/core-java-collections-conversions-3/README.md @@ -0,0 +1,5 @@ +## Java Collections Cookbooks and Examples + +This module contains articles about conversions among Collection types in Java. + +### Relevant Articles: diff --git a/core-java-modules/core-java-collections-conversions-3/pom.xml b/core-java-modules/core-java-collections-conversions-3/pom.xml new file mode 100644 index 0000000000..4813d33713 --- /dev/null +++ b/core-java-modules/core-java-collections-conversions-3/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + core-java-collections-conversions-3 + core-java-collections-conversions-3 + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + + + core-java-collections-conversions-3 + + + src/main/resources + true + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java-collections-conversions-3/src/main/java/com/baeldung/hashmaptoarraylist/HashMapToArrayListConverterUtils.java b/core-java-modules/core-java-collections-conversions-3/src/main/java/com/baeldung/hashmaptoarraylist/HashMapToArrayListConverterUtils.java new file mode 100644 index 0000000000..dd5cc1fe47 --- /dev/null +++ b/core-java-modules/core-java-collections-conversions-3/src/main/java/com/baeldung/hashmaptoarraylist/HashMapToArrayListConverterUtils.java @@ -0,0 +1,66 @@ +package com.baeldung.hashmaptoarraylist; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Maps.EntryTransformer; + +public class HashMapToArrayListConverterUtils { + + static ArrayList convertUsingConstructor(HashMap hashMap) { + if (hashMap == null) { + return null; + } + return new ArrayList(hashMap.values()); + } + + static ArrayList convertUsingAddAllMethod(HashMap hashMap) { + if (hashMap == null) { + return null; + } + + ArrayList arrayList = new ArrayList(hashMap.size()); + arrayList.addAll(hashMap.values()); + + return arrayList; + } + + static ArrayList convertUsingStreamApi(HashMap hashMap) { + if (hashMap == null) { + return null; + } + + return hashMap.values() + .stream() + .collect(Collectors.toCollection(ArrayList::new)); + } + + static ArrayList convertUsingForLoop(HashMap hashMap) { + if (hashMap == null) { + return null; + } + + ArrayList arrayList = new ArrayList(hashMap.size()); + for (Map.Entry entry : hashMap.entrySet()) { + arrayList.add(entry.getValue()); + } + + return arrayList; + } + + static public ArrayList convertUsingGuava(HashMap hashMap) { + if (hashMap == null) { + return null; + } + + EntryTransformer entryMapTransformer = (key, value) -> value; + + return Lists.newArrayList(Maps.transformEntries(hashMap, entryMapTransformer) + .values()); + } + +} diff --git a/core-java-modules/core-java-collections-conversions-3/src/test/java/com/baeldung/hashmaptoarraylist/HashMapToArrayListConverterUtilsUnitTest.java b/core-java-modules/core-java-collections-conversions-3/src/test/java/com/baeldung/hashmaptoarraylist/HashMapToArrayListConverterUtilsUnitTest.java new file mode 100644 index 0000000000..26a42e77c0 --- /dev/null +++ b/core-java-modules/core-java-collections-conversions-3/src/test/java/com/baeldung/hashmaptoarraylist/HashMapToArrayListConverterUtilsUnitTest.java @@ -0,0 +1,60 @@ +package com.baeldung.hashmaptoarraylist; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.junit.Before; +import org.junit.Test; + +public class HashMapToArrayListConverterUtilsUnitTest { + + private HashMap hashMap; + + @Before + public void beforeEach() { + hashMap = new HashMap<>(); + hashMap.put(1, "AAA"); + hashMap.put(2, "BBB"); + hashMap.put(3, "CCC"); + hashMap.put(4, "DDD"); + } + + @Test + public void givenAHashMap_whenConvertUsingConstructor_thenReturnArrayList() { + ArrayList myList = HashMapToArrayListConverterUtils.convertUsingConstructor(hashMap); + + assertThat(hashMap.values(), containsInAnyOrder(myList.toArray())); + } + + @Test + public void givenAHashMap_whenConvertUsingAddAllMethod_thenReturnArrayList() { + ArrayList myList = HashMapToArrayListConverterUtils.convertUsingAddAllMethod(hashMap); + + assertThat(hashMap.values(), containsInAnyOrder(myList.toArray())); + } + + @Test + public void givenAHashMap_whenConvertUsingForLoop_thenReturnArrayList() { + ArrayList myList = HashMapToArrayListConverterUtils.convertUsingForLoop(hashMap); + + assertThat(hashMap.values(), containsInAnyOrder(myList.toArray())); + } + + @Test + public void givenAHashMap_whenConvertUsingStreamApi_thenReturnArrayList() { + ArrayList myList = HashMapToArrayListConverterUtils.convertUsingStreamApi(hashMap); + + assertThat(hashMap.values(), containsInAnyOrder(myList.toArray())); + } + + @Test + public void givenAHashMap_whenConvertUsingGuava_thenReturnArrayList() { + ArrayList myList = HashMapToArrayListConverterUtils.convertUsingGuava(hashMap); + + assertThat(hashMap.values(), containsInAnyOrder(myList.toArray())); + } + +} From 74c8e40b1822a39a31d19a3f7f6bd8db76e5e99a Mon Sep 17 00:00:00 2001 From: Ulisses Lima Date: Sun, 24 Sep 2023 13:09:15 -0300 Subject: [PATCH 071/193] guidelines v1 --- .github/ISSUE_TEMPLATE/issue_report.md | 38 ++++++++++++++++++++++++++ CONTRIBUTING.md | 11 ++++++++ 2 files changed, 49 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/issue_report.md create mode 100644 CONTRIBUTING.md diff --git a/.github/ISSUE_TEMPLATE/issue_report.md b/.github/ISSUE_TEMPLATE/issue_report.md new file mode 100644 index 0000000000..725ae12064 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/issue_report.md @@ -0,0 +1,38 @@ +--- +name: Issue Report +about: Report an issue to help us improve +title: '[ISSUE] ' +--- + +**Article and Module Links** +A link to the affected article and the affected module. The link to the module is the one in the "over on GitHub" standard phrase. + +**Describe the Issue** +A clear and concise description of what the issue is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected Behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Environment (please complete the following information):** +- OS: [e.g. Windows] +- Browser [e.g. chrome, safari] +- Version [e.g. 22] + +**Additional Context** +Add any other context about the issue here. + +Note that, unfortunately, we can only help with issues that are specifically and directly related to the article - not with your own, custom application. + +StackOverflow is a great place to ask more general questions. + +That's primarily because we get a large number of questions and - while we do try to go through as much as everything and help wherever we can, we can't really get back to all of them. \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..642f4c6707 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,11 @@ +# Contributing to Baeldung Tutorials +First off, thank you for considering contributing to Baeldung Tutorials. + +## Reporting Issues +Before you submit an issue, please review the guidelines below: + +1. **No Custom Modifications:** If your issue arises from any custom modifications you've made to the code in the repository, we won't be able to assist. We can only help if the issue is reproducible with the untouched codebase from this repo. If you're working with a modified version, consider asking for help on StackOverflow or other relevant forums. +2. **Use a clear and descriptive title** for the issue to identify the problem. +3. **Include a link to the article** you're having issues with. +4. **Describe the exact steps which reproduce the problem** in as many details as possible. +5. **Additional Details:** Offer any other context or descriptions that could be useful. Screenshots, error messages, copy/pasteable snippets, or logs can be immensely helpful. \ No newline at end of file From d2ede7f67cf2a1b1347fd29e9d8dff0327a086d5 Mon Sep 17 00:00:00 2001 From: rajatgarg Date: Mon, 25 Sep 2023 01:34:58 +0530 Subject: [PATCH 072/193] Address review comments --- core-java-modules/core-java-io-5/.gitignore | 2 + core-java-modules/core-java-io-5/README.md | 8 +++ core-java-modules/core-java-io-5/pom.xml | 66 +++++++++++++++++++ .../ExtensionFromMimeTypeUnitTest.java | 8 +-- core-java-modules/core-java-io/pom.xml | 13 ---- core-java-modules/pom.xml | 1 + 6 files changed, 80 insertions(+), 18 deletions(-) create mode 100644 core-java-modules/core-java-io-5/.gitignore create mode 100644 core-java-modules/core-java-io-5/README.md create mode 100644 core-java-modules/core-java-io-5/pom.xml rename core-java-modules/{core-java-io => core-java-io-5}/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java (94%) diff --git a/core-java-modules/core-java-io-5/.gitignore b/core-java-modules/core-java-io-5/.gitignore new file mode 100644 index 0000000000..0c0cd871c5 --- /dev/null +++ b/core-java-modules/core-java-io-5/.gitignore @@ -0,0 +1,2 @@ +test-link* +0.* \ No newline at end of file diff --git a/core-java-modules/core-java-io-5/README.md b/core-java-modules/core-java-io-5/README.md new file mode 100644 index 0000000000..6072e0b6d9 --- /dev/null +++ b/core-java-modules/core-java-io-5/README.md @@ -0,0 +1,8 @@ +## Core Java IO + +This module contains articles about core Java input and output (IO) + +### Relevant Articles: + +- [[<-- Prev]](/core-java-modules/core-java-io-4) + diff --git a/core-java-modules/core-java-io-5/pom.xml b/core-java-modules/core-java-io-5/pom.xml new file mode 100644 index 0000000000..11116b071c --- /dev/null +++ b/core-java-modules/core-java-io-5/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + core-java-io-5 + core-java-io-5 + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + + + + + org.apache.tika + tika-core + ${tika.version} + + + net.sf.jmimemagic + jmimemagic + ${jmime-magic.version} + + + org.jodd + jodd-util + ${jodd-util.version} + + + com.j256.simplemagic + simplemagic + ${simplemagic.version} + + + + + core-java-io-5 + + + src/main/resources + true + + + + + maven-compiler-plugin + + 11 + 11 + + + + + + + + 2.8.0 + 0.1.5 + 6.2.1 + 1.17 + + \ No newline at end of file diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java b/core-java-modules/core-java-io-5/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java similarity index 94% rename from core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java rename to core-java-modules/core-java-io-5/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java index 2238cfcafa..6b1fd490a8 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java +++ b/core-java-modules/core-java-io-5/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java @@ -11,10 +11,8 @@ import java.util.Map; import java.util.Set; import org.apache.tika.mime.MimeTypeException; - -import org.junit.Test; - import com.j256.simplemagic.ContentType; +import org.junit.Test; public class ExtensionFromMimeTypeUnitTest { private static final String IMAGE_JPEG_MIME_TYPE = "image/jpeg"; @@ -37,14 +35,14 @@ public class ExtensionFromMimeTypeUnitTest { } @Test - public void whenUsingMimetypesFileTypeMap_thenGetFileExtension() { + public void whenUsingSimpleMagic_thenGetFileExtension() { List expectedExtensions = Arrays.asList("jpeg", "jpg", "jpe"); String[] detectedExtensions = ContentType.fromMimeType(IMAGE_JPEG_MIME_TYPE).getFileExtensions(); assertThat(detectedExtensions).containsExactlyElementsOf(expectedExtensions); } @Test - public void whenUsingCustomLogic_thenGetFileExtension() { + public void whenUsingCustomMap_thenGetFileExtension() { Map> mimeExtensionsMap = new HashMap<>(); List expectedExtensions = Arrays.asList(".jpg", ".jpe", ".jpeg"); addMimeExtensions(mimeExtensionsMap, "image/jpeg", ".jpg"); diff --git a/core-java-modules/core-java-io/pom.xml b/core-java-modules/core-java-io/pom.xml index 12e957a3ba..faeddafd81 100644 --- a/core-java-modules/core-java-io/pom.xml +++ b/core-java-modules/core-java-io/pom.xml @@ -43,17 +43,6 @@ ${angus-activation.version} test - - org.jodd - jodd-util - ${jodd-util.version} - - - com.j256.simplemagic - simplemagic - ${simplemagic.version} - - @@ -153,8 +142,6 @@ 4.4.2 2.1.2 2.0.1 - 6.2.1 - 1.17 \ No newline at end of file diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 34e5204868..bee10854d0 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -108,6 +108,7 @@ core-java-io-2 core-java-io-3 core-java-io-4 + core-java-io-5 core-java-io-apis core-java-io-apis-2 core-java-io-conversions From c68970838351add6f10ddb3275d74430498c96b7 Mon Sep 17 00:00:00 2001 From: Bhaskar Ghosh Dastidar Date: Mon, 25 Sep 2023 06:02:12 +0530 Subject: [PATCH 073/193] [BAEL-6956] string templates (#14825) Co-authored-by: Bhaskar --- core-java-modules/core-java-21/pom.xml | 37 +++++----- .../StringCompositionTechniques.java | 37 ++++++++++ .../StringTemplateExamples.java | 56 ++++++++++++++++ .../StringTemplatesUnitTest.java | 67 +++++++++++++++++++ 4 files changed, 178 insertions(+), 19 deletions(-) create mode 100644 core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringCompositionTechniques.java create mode 100644 core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringTemplateExamples.java create mode 100644 core-java-modules/core-java-21/src/test/java/com.baeldung.stringtemplates/StringTemplatesUnitTest.java diff --git a/core-java-modules/core-java-21/pom.xml b/core-java-modules/core-java-21/pom.xml index 83b2b1c858..0504f787c6 100644 --- a/core-java-modules/core-java-21/pom.xml +++ b/core-java-modules/core-java-21/pom.xml @@ -12,23 +12,22 @@ 0.0.1-SNAPSHOT - - - - - - - - - - - - - - - - - - - + + + + org.apache.maven.plugins + maven-compiler-plugin + + 21 + 21 + --enable-preview + + + + + + 21 + 21 + UTF-8 + \ No newline at end of file diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringCompositionTechniques.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringCompositionTechniques.java new file mode 100644 index 0000000000..7e66144f1c --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringCompositionTechniques.java @@ -0,0 +1,37 @@ +package com.baeldung.stringtemplates; + +import java.text.MessageFormat; + +public class StringCompositionTechniques { + String composeUsingPlus(String feelsLike, String temperature, String unit) { + return "Today's weather is " + feelsLike + ", with a temperature of " + temperature + " degrees " + unit; + } + + String composeUsingStringBuffer(String feelsLike, String temperature, String unit) { + return new StringBuffer().append("Today's weather is ") + .append(feelsLike) + .append(", with a temperature of ") + .append(temperature) + .append(" degrees ") + .append(unit) + .toString(); + } + + String composeUsingStringBuilder(String feelsLike, String temperature, String unit) { + return new StringBuilder().append("Today's weather is ") + .append(feelsLike) + .append(", with a temperature of ") + .append(temperature) + .append(" degrees ") + .append(unit) + .toString(); + } + + String composeUsingFormatters(String feelsLike, String temperature, String unit) { + return String.format("Today's weather is %s, with a temperature of %s degrees %s", feelsLike, temperature, unit); + } + + String composeUsingMessageFormatter(String feelsLike, String temperature, String unit) { + return MessageFormat.format("Today''s weather is {0}, with a temperature of {1} degrees {2}", feelsLike, temperature, unit); + } +} diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringTemplateExamples.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringTemplateExamples.java new file mode 100644 index 0000000000..0fb18a84e9 --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringTemplateExamples.java @@ -0,0 +1,56 @@ +package com.baeldung.stringtemplates; + +import static java.lang.StringTemplate.RAW; +import static java.util.FormatProcessor.FMT; + +public class StringTemplateExamples { + String interpolationUsingSTRProcessor(String feelsLike, String temperature, String unit) { + return STR + . "Today's weather is \{ feelsLike }, with a temperature of \{ temperature } degrees \{ unit }" ; + } + + String interpolationOfJSONBlock(String feelsLike, String temperature, String unit) { + return STR + . """ + { + "feelsLike": "\{ feelsLike }", + "temperature": "\{ temperature }", + "unit": "\{ unit }" + } + """ ; + } + + String interpolationWithExpressions() { + return STR + . "Today's weather is \{ getFeelsLike() }, with a temperature of \{ getTemperature() } degrees \{ getUnit() }" ; + } + + String interpolationWithTemplates() { + StringTemplate str = RAW + . "Today's weather is \{ getFeelsLike() }, with a temperature of \{ getTemperature() } degrees \{ getUnit() }" ; + return STR.process(str); + } + + String interpolationOfJSONBlockWithFMT(String feelsLike, float temperature, String unit) { + return FMT + . """ + { + "feelsLike": "%1s\{ feelsLike }", + "temperature": "%2.2f\{ temperature }", + "unit": "%1s\{ unit }" + } + """ ; + } + + private String getFeelsLike() { + return "pleasant"; + } + + private String getTemperature() { + return "25"; + } + + private String getUnit() { + return "Celsius"; + } +} diff --git a/core-java-modules/core-java-21/src/test/java/com.baeldung.stringtemplates/StringTemplatesUnitTest.java b/core-java-modules/core-java-21/src/test/java/com.baeldung.stringtemplates/StringTemplatesUnitTest.java new file mode 100644 index 0000000000..b9917cab18 --- /dev/null +++ b/core-java-modules/core-java-21/src/test/java/com.baeldung.stringtemplates/StringTemplatesUnitTest.java @@ -0,0 +1,67 @@ +package com.baeldung.stringtemplates; + +import org.junit.Assert; +import org.junit.Test; + +public class StringTemplatesUnitTest { + + @Test + public void whenStringConcat_thenReturnComposedString() { + StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingPlus("pleasant", "25", "Celsius")); + } + + @Test + public void whenStringBuffer_thenReturnComposedString() { + StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingStringBuffer("pleasant", "25", "Celsius")); + } + + @Test + public void whenStringBuilder_thenReturnComposedString() { + StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingStringBuilder("pleasant", "25", "Celsius")); + } + + @Test + public void whenStringFormatter_thenReturnComposedFormattedString() { + StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingFormatters("pleasant", "25", "Celsius")); + } + + @Test + public void whenMessageFormatter_thenReturnComposedFormattedString() { + StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingMessageFormatter("pleasant", "25", "Celsius")); + } + + @Test + public void whenUsingStringTemplateSTR_thenReturnInterpolatedString() { + StringTemplateExamples templateExamples = new StringTemplateExamples(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", templateExamples.interpolationUsingSTRProcessor("pleasant", "25", "Celsius")); + } + + @Test + public void whenUsingMultilineStringTemplateSTR_thenReturnInterpolatedString() { + StringTemplateExamples templateExamples = new StringTemplateExamples(); + Assert.assertEquals("{\n" + " \"feelsLike\": \"pleasant\",\n" + " \"temperature\": \"25\",\n" + " \"unit\": \"Celsius\"\n" + "}\n", templateExamples.interpolationOfJSONBlock("pleasant", "25", "Celsius")); + } + + @Test + public void whenUsingExpressionSTR_thenReturnInterpolatedString() { + StringTemplateExamples templateExamples = new StringTemplateExamples(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", templateExamples.interpolationWithExpressions()); + } + + @Test + public void whenUsingExpressionRAW_thenReturnInterpolatedString() { + StringTemplateExamples templateExamples = new StringTemplateExamples(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", templateExamples.interpolationWithTemplates()); + } + + @Test + public void whenUsingExpressionFMT_thenReturnInterpolatedString() { + StringTemplateExamples templateExamples = new StringTemplateExamples(); + Assert.assertEquals("{\n" + " \"feelsLike\": \"pleasant\",\n" + " \"temperature\": \"25.86\",\n" + " \"unit\": \"Celsius\"\n" + "}\n", templateExamples.interpolationOfJSONBlockWithFMT("pleasant", 25.8636F, "Celsius")); + } +} \ No newline at end of file From a3ab8131c9525284066ac5aef96c2827d9e03f58 Mon Sep 17 00:00:00 2001 From: timis1 <12120641+timis1@users.noreply.github.com> Date: Mon, 25 Sep 2023 06:42:56 +0300 Subject: [PATCH 074/193] JAVA-24463 Cleanup spring-reactive-modules (#14811) Co-authored-by: timis1 --- spring-reactive-modules/pom.xml | 22 +-- .../spring-5-reactive/README.md | 14 -- .../spring-5-reactive/pom.xml | 165 ---------------- .../spring-data-couchbase/pom.xml | 4 +- .../ReactiveCouchbaseApplication.java | 2 +- .../configuration/CouchbaseProperties.java | 2 +- .../N1QLReactiveCouchbaseConfiguration.java | 2 +- .../ReactiveCouchbaseConfiguration.java | 2 +- .../ViewReactiveCouchbaseConfiguration.java | 2 +- .../com/baeldung/couchbase/domain/Person.java | 2 +- .../repository/n1ql/N1QLPersonRepository.java | 2 +- .../n1ql/N1QLSortingPersonRepository.java | 2 +- .../repository/view/ViewPersonRepository.java | 2 +- .../CouchbaseMockConfiguration.java | 16 +- .../n1ql/N1QLPersonRepositoryLiveTest.java | 9 +- .../N1QLSortingPersonRepositoryLiveTest.java | 9 +- .../ViewPersonRepositoryIntegrationTest.java | 17 +- .../.gitignore | 0 .../README.md | 2 +- .../pom.xml | 2 +- .../consumer/ConsumerSSEApplication.java | 0 .../consumer/controller/ClientController.java | 0 .../server/ServerSSEApplication.java | 0 .../server/controllers/ServerController.java | 0 .../StaticContentApplication.java | 0 .../staticcontent/StaticContentConfig.java | 0 .../FunctionalValidationsApplication.java | 0 .../handlers/AbstractValidationHandler.java | 0 .../handlers/FunctionalHandler.java | 0 ...notatedRequestEntityValidationHandler.java | 0 .../CustomRequestEntityValidationHandler.java | 0 .../impl/OtherEntityValidationHandler.java | 0 .../model/AnnotatedRequestEntity.java | 0 .../functional/model/CustomRequestEntity.java | 0 .../functional/model/OtherEntity.java | 0 .../routers/ValidationsRouters.java | 0 .../CustomRequestEntityValidator.java | 0 .../validators/OtherEntityValidator.java | 0 ...lication-assets-custom-location.properties | 0 .../backpressure/BackpressureUnitTest.java | 0 .../ServiceSentEventLiveTest.java | 0 ...cContentCustomLocationIntegrationTest.java | 0 ...ContentDefaultLocationIntegrationTest.java | 0 .../stepverifier/PostExecutionUnitTest.java | 0 .../stepverifier/StepByStepUnitTest.java | 0 .../TestingTestPublisherUnitTest.java | 0 .../stepverifier/TimeBasedUnitTest.java | 0 ...FunctionalEndpointValidationsLiveTest.java | 0 .../src/test/resources/assets/index.html | 0 .../src/test/resources/img/example-image.png | Bin .../src/test/resources/logback-test.xml | 0 .../src/test/resources/public/index.html | 0 .../.gitignore | 0 .../README.md | 3 +- .../pom.xml | 2 +- .../databuffer/DataBufferToInputStream.java | 0 .../logging/WebFluxLoggingExample.java | 0 .../src/main/resources/application.properties | 0 .../cancelflux/CancelFluxUnitTest.java | 0 .../DataBufferToInputStreamUnitTest.java | 0 .../src/test/resources/logback-test.xml | 0 .../src/test/resources/user-response.json | 0 .../README.md | 0 .../pom.xml | 10 +- .../limitrequests/LimitRequestsApp.java | 0 .../limitrequests/client/DelayElements.java | 0 .../limitrequests/client/GuavaRateLimit.java | 0 .../client/LimitConcurrency.java | 0 .../client/Resilience4jRateLimit.java | 0 .../limitrequests/client/ZipWithInterval.java | 0 .../limitrequests/client/utils/Client.java | 0 .../client/utils/RandomConsumer.java | 0 .../limitrequests/server/Concurrency.java | 0 .../server/RandomController.java | 0 .../streamlargefile/StreamLargeFileApp.java | 0 .../client/LargeFileDownloadWebClient.java | 0 .../client/LimitedFileDownloadWebClient.java | 0 .../server/LargeFileController.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../streamlargefile/generate-sample-files.sh | 0 .../src/main/resources/streamlargefile/run.sh | 0 .../RandomControllerLiveTest.java | 0 .../LargeFileControllerLiveTest.java | 0 .../src/test/resources/logback-test.xml | 0 .../.gitignore | 0 .../README.md | 2 +- .../pom.xml | 14 +- .../reactive/controller/UploadController.java | 0 .../com/baeldung/reactive/enums/Role.java | 0 .../reactive/exception/ServiceException.java | 0 .../com/baeldung/reactive/model/Employee.java | 0 .../java/com/baeldung/reactive/model/Foo.java | 0 .../reactive/service/EmployeeService.java | 0 .../service/ReactiveUploadService.java | 0 .../webclient/simultaneous/Client.java | 0 .../reactive/webclient/simultaneous/Item.java | 0 .../reactive/webclient/simultaneous/User.java | 0 .../webclient/simultaneous/UserWithItem.java | 0 .../java/com/baeldung/webclient/Product.java | 0 .../webclient/ProductsFeignClient.java | 0 .../ProductsSlowServiceController.java | 0 .../webclient/WebClientApplication.java | 0 .../com/baeldung/webclient/WebController.java | 0 .../webclient/json/ReaderConsumerService.java | 0 .../json/ReaderConsumerServiceImpl.java | 0 .../baeldung/webclient/json/model/Book.java | 0 .../baeldung/webclient/json/model/Reader.java | 0 .../status/WebClientStatusCodeHandler.java | 0 .../exception/CustomBadRequestException.java | 0 .../exception/CustomServerErrorException.java | 0 .../timeout/WebClientTimeoutProvider.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../java/com/baeldung/SpringContextTest.java | 0 .../reactive/ReactiveIntegrationTest.java | 0 .../Spring5ReactiveTestApplication.java | 0 .../WebClientLoggingIntegrationTest.java | 0 .../reactive/logging/filters/LogFilters.java | 0 .../logging/jetty/RequestLogEnhancer.java | 0 .../EmployeeServiceIntegrationTest.java | 0 .../service/EmployeeServiceUnitTest.java | 0 .../ReactiveUploadServiceUnitTest.java | 0 .../simultaneous/ClientIntegrationTest.java | 0 ...lientStatusCodeHandlerIntegrationTest.java | 0 .../WebControllerIntegrationTest.java | 0 .../ReaderConsumerServiceImplUnitTest.java | 0 .../WebClientTimeoutIntegrationTest.java | 0 .../src/test/resources/logback-test.xml | 0 .../README.md | 2 +- .../pom.xml | 11 +- .../pagination/PaginationApplication.java | 0 .../CustomWebMvcConfigurationSupport.java | 0 .../pagination/config/DatabaseConfig.java | 0 .../ProductPaginationController.java | 0 .../baeldung/pagination/model/Product.java | 0 .../repository/ProductRepository.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/init.sql | 0 ...ctPaginationControllerIntegrationTest.java | 0 .../README.md | 2 +- .../pom.xml | 4 +- .../com/baeldung/r2dbc/R2dbcApplication.java | 0 .../configuration/R2DBCConfiguration.java | 0 .../java/com/baeldung/r2dbc/model/Player.java | 0 .../r2dbc/repository/PlayerRepository.java | 0 .../src/main/resources/logback.xml | 0 .../java/com/baeldung/SpringContextTest.java | 0 .../R2dbcApplicationIntegrationTest.java | 0 .../spring-reactive-exceptions/README.md | 1 + .../ErrorHandlingApplication.java | 2 +- .../errorhandling/GlobalErrorAttributes.java | 6 +- .../GlobalErrorWebExceptionHandler.java | 10 +- .../reactive/errorhandling/Handler.java | 3 +- .../errorhandling/NameRequiredException.java | 2 +- .../reactive/errorhandling/Router.java | 10 +- .../ErrorHandlingIntegrationTest.java | 2 +- .../.gitignore | 0 .../README.md | 1 + .../pom.xml | 16 +- .../Spring5ReactiveFiltersApplication.java | 0 .../filters/ExampleHandlerFilterFunction.java | 0 .../reactive/filters/ExampleWebFilter.java | 0 .../reactive/filters/PlayerHandler.java | 0 .../reactive/filters/PlayerRouter.java | 0 .../reactive/filters/UserController.java | 0 .../reactive/filters}/WebClientFilters.java | 2 +- .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../java/com/baeldung/SpringContextTest.java | 0 .../filters}/FilteredWebClientUnitTest.java | 8 +- .../filters/PlayerHandlerIntegrationTest.java | 0 .../UserControllerIntegrationTest.java | 0 .../README.md | 0 .../pom.xml | 4 +- .../reactive/oauth/SecurityConfig.java | 0 .../Spring5ReactiveOauthApplication.java | 0 .../reactive/oauth/web/MainController.java | 0 .../baeldung/reactive/oauth/web/dto/Foo.java | 0 .../OauthClientApplication.java | 0 .../configuration/WebClientConfig.java | 0 .../configuration/WebSecurityConfig.java | 0 .../web/ClientRestController.java | 0 .../OauthClientLoginApplication.java | 0 .../configuration/WebClientConfig.java | 0 .../configuration/WebSecurityConfig.java | 0 .../web/ClientRestController.java | 0 .../ClientCredentialsOauthApplication.java | 0 .../configuration/WebClientConfig.java | 0 .../service/WebClientChonJob.java | 0 .../ManualRequestApplication.java | 0 .../configure/WebClientConfig.java | 0 .../configure/WebSecurityConfig.java | 0 .../web/ManualOauthRequestController.java | 0 .../src/main/resources/application.yml | 0 .../main/resources/default-application.yml | 0 ...nt-auth-code-client-application.properties | 0 ...ent-auth-code-login-application.properties | 0 ...t-credentials-oauth-application.properties | 0 ...anual-request-oauth-application.properties | 0 .../Spring5ReactiveOauthIntegrationTest.java | 0 .../OAuth2ClientCredentialsLiveTest.java | 0 .../OAuth2ManualRequestLiveTest.java | 0 .../webclient/utils/ListAppender.java | 0 .../src/test/resources/logback-test.xml | 0 .../.gitignore | 0 .../README.md | 0 .../pom.xml | 10 +- .../DownstreamServiceHealthIndicator.java | 0 .../reactive/actuator/FeaturesEndpoint.java | 0 .../actuator/InfoWebEndpointExtension.java | 0 .../actuator/Spring5ReactiveApplication.java | 0 .../reactive/actuator/WebSecurityConfig.java | 0 .../authresolver/AuthResolverApplication.java | 0 .../authresolver/AuthResolverController.java | 0 .../authresolver/CustomWebSecurityConfig.java | 0 .../CorsOnAnnotatedElementsApplication.java | 0 .../controllers/CorsOnClassController.java | 0 .../controllers/CorsOnMethodsController.java | 0 .../global/CorsGlobalConfigApplication.java | 0 .../config/CorsGlobalConfiguration.java | 0 .../FurtherCorsConfigsController.java | 0 .../controllers/RegularRestController.java | 0 .../handlers/CorsGlobalFunctionalHandler.java | 0 .../routers/CorsRouterFunctions.java | 0 .../webfilter/CorsWebFilterApplication.java | 0 .../webfilter/config/CorsWebFilterConfig.java | 0 .../FurtherCorsConfigsController.java | 0 .../controllers/RegularRestController.java | 0 .../handlers/CorsWithWebFilterHandler.java | 0 .../CorsWithWebFilterRouterFunctions.java | 0 .../java/com/baeldung/webflux/Employee.java | 0 .../com/baeldung/webflux/EmployeeConfig.java | 0 .../webflux/EmployeeCreationEvent.java | 0 .../webflux/EmployeeWebSecurityConfig.java | 0 .../webflux/EmployeeWebSocketClient.java | 0 .../webflux/EmployeeWebSocketHandler.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/files/hello.txt | 0 .../src/main/resources/files/test/test.txt | 0 .../src/main/resources/logback.xml | 0 .../resources/static/client-websocket.html | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../java/com/baeldung/SpringContextTest.java | 0 .../actuator/ActuatorInfoIntegrationTest.java | 0 .../AuthResolverIntegrationTest.java | 0 .../cors/CorsOnAnnotatedElementsLiveTest.java | 0 .../cors/CorsOnGlobalConfigLiveTest.java | 0 .../cors/CorsOnWebFilterLiveTest.java | 0 .../src/test/resources/baeldung-weekly.png | Bin .../spring-reactive-webflux/README.md | 23 +++ .../spring-reactive-webflux/pom.xml | 112 +++++++++++ .../reactive/concurrency/Application.java | 0 .../reactive/concurrency/Controller.java | 0 .../baeldung/reactive/concurrency/Person.java | 0 .../concurrency/PersonRepository.java | 0 .../ConsumerDebuggingApplication.java | 0 .../ReactiveConfigsToggleRestController.java | 0 .../debugging/consumer/cronjobs/CronJobs.java | 0 .../debugging/consumer/model/Foo.java | 0 .../debugging/consumer/model/FooDto.java | 0 .../consumer/service/FooNameHelper.java | 0 .../consumer/service/FooQuantityHelper.java | 0 .../consumer/service/FooReporter.java | 0 .../consumer/service/FooService.java | 0 .../server/ServerDebuggingApplication.java | 0 .../server/handlers/ServerHandler.java | 0 .../reactive/debugging/server/model/Foo.java | 0 .../server/routers/ServerRouter.java | 0 .../reactive/security/GreetingController.java | 0 .../reactive/security/GreetingService.java | 0 .../reactive/security/SecurityConfig.java | 0 .../security/SpringSecurity6Application.java | 0 .../com/baeldung/reactive/webclient/Foo.java | 0 .../baeldung/reactive/webclient/Tweet.java | 0 .../TweetsSlowServiceController.java | 0 .../webclient/WebClientApplication.java | 0 .../webclient/WebClientController.java | 0 .../reactive/webclient/WebController.java | 0 .../SpringWebClientRequestsApp.java | 0 .../baeldung/reactive/webflux/Employee.java | 0 .../reactive/webflux/EmployeeRepository.java | 0 .../annotation/EmployeeController.java | 0 .../annotation/EmployeeSpringApplication.java | 0 .../webflux/annotation/EmployeeWebClient.java | 0 .../annotation/EmployeeWebSecurityConfig.java | 0 .../functional/EmployeeFunctionalConfig.java | 0 .../EmployeeSpringFunctionalApplication.java | 0 .../ConsumerFooServiceIntegrationTest.java | 0 .../consumer/ConsumerFooServiceLiveTest.java | 0 .../consumer/utils/ListAppender.java | 0 .../introduction/ReactorIntegrationTest.java | 0 .../security/SecurityIntegrationTest.java | 0 .../reactive/webclient/SpringContextTest.java | 0 .../webclient/WebClientIntegrationTest.java | 0 .../WebControllerIntegrationTest.java | 0 .../WebTestClientIntegrationTest.java | 0 ...bClientRequestsWithParametersUnitTest.java | 0 .../EmployeeControllerIntegrationTest.java | 0 ...ployeeSpringFunctionalIntegrationTest.java | 0 .../src/test/resources/logback-test.xml | 0 .../.gitignore | 0 .../spring-reactive/README.md | 30 +-- .../spring-reactive/pom.xml | 177 ++++++++++++------ .../src/main/assets/index.html | 0 .../java/com/baeldung/functional/Actor.java | 0 .../com/baeldung/functional/FormHandler.java | 0 .../FunctionalSpringBootApplication.java | 0 .../functional/FunctionalWebApplication.java | 0 .../functional/IndexRewriteFilter.java | 0 .../com/baeldung/functional/RootServlet.java | 0 .../reactive/Spring5ReactiveApplication.java | 0 .../controller/FooReactiveController.java | 0 .../controller/PathPatternController.java | 0 .../java/com/baeldung/reactive/model/Foo.java | 0 .../controllers/ResponseHeaderController.java | 0 .../filter/AddResponseHeaderWebFilter.java | 0 .../handlers/ResponseHeaderHandler.java | 0 .../ResponseHeadersRouterFunctions.java | 0 .../com/baeldung/reactive/urlmatch/Actor.java | 0 ...Spring5URLPatternUsingRouterFunctions.java | 0 .../reactive/urlmatch/FormHandler.java | 0 .../urlmatch/FunctionalWebApplication.java | 0 .../reactive/urlmatch/IndexRewriteFilter.java | 0 .../com/baeldung/reactive/util/CpuUtils.java | 0 .../com/baeldung/websession/Application.java | 0 .../websession/configuration/RedisConfig.java | 0 .../configuration/SessionConfig.java | 0 .../configuration/WebFluxConfig.java | 0 .../configuration/WebFluxSecurityConfig.java | 0 .../controller/SessionController.java | 0 .../websession/transfer/CustomResponse.java | 0 .../java/com/baeldung/websocket/Event.java | 0 .../ReactiveJavaClientWebSocket.java | 0 .../ReactiveWebSocketApplication.java | 0 .../ReactiveWebSocketConfiguration.java | 0 .../websocket/ReactiveWebSocketHandler.java | 0 .../websocket/WebSocketController.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/files/hello.txt | 0 .../src/main/resources/files/test/test.txt | 0 .../src/main/resources/logback.xml | 0 .../main/resources/resources/test/test.txt | 0 .../resources/static/client-websocket.html | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../java/com/baeldung/SpringContextTest.java | 0 ...nctionalWebApplicationIntegrationTest.java | 0 .../com/baeldung/reactive/FluxUnitTest.java | 0 .../ResponseHeaderLiveTest.java | 0 ...rnUsingRouterFunctionsIntegrationTest.java | 0 ...ernsUsingHandlerMethodIntegrationTest.java | 0 .../src/test/resources/baeldung-weekly.png | Bin .../spring-reactor/pom.xml | 1 - 354 files changed, 377 insertions(+), 371 deletions(-) delete mode 100644 spring-reactive-modules/spring-5-reactive/README.md delete mode 100644 spring-reactive-modules/spring-5-reactive/pom.xml rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/.gitignore (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/README.md (91%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/pom.xml (98%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/reactive/serversentevents/consumer/controller/ClientController.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/reactive/serversentevents/server/ServerSSEApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/reactive/serversentevents/server/controllers/ServerController.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/staticcontent/StaticContentApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/validations/functional/handlers/AbstractValidationHandler.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/validations/functional/handlers/FunctionalHandler.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/validations/functional/handlers/impl/AnnotatedRequestEntityValidationHandler.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/validations/functional/handlers/impl/CustomRequestEntityValidationHandler.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/validations/functional/handlers/impl/OtherEntityValidationHandler.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/validations/functional/model/CustomRequestEntity.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/validations/functional/model/OtherEntity.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/validations/functional/routers/ValidationsRouters.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/validations/functional/validators/CustomRequestEntityValidator.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/java/com/baeldung/validations/functional/validators/OtherEntityValidator.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/main/resources/application-assets-custom-location.properties (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/test/java/com/baeldung/staticcontent/StaticContentCustomLocationIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/test/java/com/baeldung/staticcontent/StaticContentDefaultLocationIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/test/java/com/baeldung/stepverifier/PostExecutionUnitTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/test/java/com/baeldung/stepverifier/StepByStepUnitTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/test/java/com/baeldung/stepverifier/TestingTestPublisherUnitTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/test/java/com/baeldung/stepverifier/TimeBasedUnitTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/test/java/com/baeldung/validations/functional/FunctionalEndpointValidationsLiveTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/test/resources/assets/index.html (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/test/resources/img/example-image.png (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/test/resources/logback-test.xml (100%) rename spring-reactive-modules/{spring-5-reactive-2 => spring-reactive-2}/src/test/resources/public/index.html (100%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-3}/.gitignore (100%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-3}/README.md (72%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-3}/pom.xml (98%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-3}/src/main/java/com/baeldung/databuffer/DataBufferToInputStream.java (100%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-3}/src/main/java/com/baeldung/webflux/logging/WebFluxLoggingExample.java (100%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-3}/src/main/resources/application.properties (100%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-3}/src/test/java/com/baeldung/cancelflux/CancelFluxUnitTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-3}/src/test/java/com/baeldung/databuffer/DataBufferToInputStreamUnitTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-3}/src/test/resources/logback-test.xml (100%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-3}/src/test/resources/user-response.json (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/README.md (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/pom.xml (94%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/java/com/baeldung/limitrequests/LimitRequestsApp.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/java/com/baeldung/limitrequests/client/DelayElements.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/java/com/baeldung/limitrequests/client/GuavaRateLimit.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/java/com/baeldung/limitrequests/client/LimitConcurrency.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/java/com/baeldung/limitrequests/client/Resilience4jRateLimit.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/java/com/baeldung/limitrequests/client/ZipWithInterval.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/java/com/baeldung/limitrequests/client/utils/Client.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/java/com/baeldung/limitrequests/client/utils/RandomConsumer.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/java/com/baeldung/limitrequests/server/Concurrency.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/java/com/baeldung/limitrequests/server/RandomController.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/java/com/baeldung/streamlargefile/StreamLargeFileApp.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/java/com/baeldung/streamlargefile/client/LargeFileDownloadWebClient.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/java/com/baeldung/streamlargefile/client/LimitedFileDownloadWebClient.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/java/com/baeldung/streamlargefile/server/LargeFileController.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/resources/application.properties (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/resources/logback.xml (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/resources/streamlargefile/generate-sample-files.sh (100%) mode change 100755 => 100644 rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/main/resources/streamlargefile/run.sh (100%) mode change 100755 => 100644 rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/test/java/com/baeldung/limitrequests/RandomControllerLiveTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/test/java/com/baeldung/streamlargefile/LargeFileControllerLiveTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-client-2 => spring-reactive-client-2}/src/test/resources/logback-test.xml (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/.gitignore (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/README.md (89%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/pom.xml (93%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/reactive/controller/UploadController.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/reactive/enums/Role.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/reactive/exception/ServiceException.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/reactive/model/Employee.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/reactive/model/Foo.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/reactive/service/EmployeeService.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/reactive/service/ReactiveUploadService.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/reactive/webclient/simultaneous/Client.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/reactive/webclient/simultaneous/Item.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/reactive/webclient/simultaneous/User.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/reactive/webclient/simultaneous/UserWithItem.java (100%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-client}/src/main/java/com/baeldung/webclient/Product.java (100%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-client}/src/main/java/com/baeldung/webclient/ProductsFeignClient.java (100%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-client}/src/main/java/com/baeldung/webclient/ProductsSlowServiceController.java (100%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-client}/src/main/java/com/baeldung/webclient/WebClientApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-client}/src/main/java/com/baeldung/webclient/WebController.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/webclient/json/model/Book.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/webclient/json/model/Reader.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/webclient/status/WebClientStatusCodeHandler.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/webclient/status/exception/CustomBadRequestException.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/webclient/status/exception/CustomServerErrorException.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/java/com/baeldung/webclient/timeout/WebClientTimeoutProvider.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/resources/application.properties (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/resources/logback.xml (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/main/webapp/WEB-INF/web.xml (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/test/java/com/baeldung/reactive/Spring5ReactiveTestApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/test/java/com/baeldung/reactive/logging/WebClientLoggingIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/test/java/com/baeldung/reactive/logging/filters/LogFilters.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/test/java/com/baeldung/reactive/logging/jetty/RequestLogEnhancer.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/test/java/com/baeldung/reactive/service/EmployeeServiceIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/test/java/com/baeldung/reactive/service/EmployeeServiceUnitTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/test/java/com/baeldung/reactive/service/ReactiveUploadServiceUnitTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/test/java/com/baeldung/webclient/WebClientStatusCodeHandlerIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-3 => spring-reactive-client}/src/test/java/com/baeldung/webclient/WebControllerIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/test/java/com/baeldung/webclient/timeout/WebClientTimeoutIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-client => spring-reactive-client}/src/test/resources/logback-test.xml (100%) rename spring-reactive-modules/{spring-5-data-reactive-2 => spring-reactive-data-2}/README.md (80%) rename spring-reactive-modules/{spring-5-data-reactive-2 => spring-reactive-data-2}/pom.xml (85%) rename spring-reactive-modules/{spring-5-data-reactive-2 => spring-reactive-data-2}/src/main/java/com/baeldung/pagination/PaginationApplication.java (100%) rename spring-reactive-modules/{spring-5-data-reactive-2 => spring-reactive-data-2}/src/main/java/com/baeldung/pagination/config/CustomWebMvcConfigurationSupport.java (100%) rename spring-reactive-modules/{spring-5-data-reactive-2 => spring-reactive-data-2}/src/main/java/com/baeldung/pagination/config/DatabaseConfig.java (100%) rename spring-reactive-modules/{spring-5-data-reactive-2 => spring-reactive-data-2}/src/main/java/com/baeldung/pagination/controller/ProductPaginationController.java (100%) rename spring-reactive-modules/{spring-5-data-reactive-2 => spring-reactive-data-2}/src/main/java/com/baeldung/pagination/model/Product.java (100%) rename spring-reactive-modules/{spring-5-data-reactive-2 => spring-reactive-data-2}/src/main/java/com/baeldung/pagination/repository/ProductRepository.java (100%) rename spring-reactive-modules/{spring-5-data-reactive-2 => spring-reactive-data-2}/src/main/resources/application.properties (100%) rename spring-reactive-modules/{spring-5-data-reactive-2 => spring-reactive-data-2}/src/main/resources/init.sql (100%) rename spring-reactive-modules/{spring-5-data-reactive-2 => spring-reactive-data-2}/src/test/java/com/baeldung/pagination/controller/ProductPaginationControllerIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-reactive-data}/README.md (77%) rename spring-reactive-modules/{spring-5-data-reactive => spring-reactive-data}/pom.xml (96%) rename spring-reactive-modules/{spring-5-data-reactive => spring-reactive-data}/src/main/java/com/baeldung/r2dbc/R2dbcApplication.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-reactive-data}/src/main/java/com/baeldung/r2dbc/configuration/R2DBCConfiguration.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-reactive-data}/src/main/java/com/baeldung/r2dbc/model/Player.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-reactive-data}/src/main/java/com/baeldung/r2dbc/repository/PlayerRepository.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-reactive-data}/src/main/resources/logback.xml (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-reactive-data}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-reactive-modules/{spring-5-data-reactive => spring-reactive-data}/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive/src/main/java/com/baeldung => spring-reactive-exceptions/src/main/java/com/baeldung/spring}/reactive/errorhandling/ErrorHandlingApplication.java (93%) rename spring-reactive-modules/{spring-reactive/src/main/java/com/baeldung => spring-reactive-exceptions/src/main/java/com/baeldung/spring}/reactive/errorhandling/GlobalErrorAttributes.java (93%) rename spring-reactive-modules/{spring-reactive/src/main/java/com/baeldung => spring-reactive-exceptions/src/main/java/com/baeldung/spring}/reactive/errorhandling/GlobalErrorWebExceptionHandler.java (92%) rename spring-reactive-modules/{spring-reactive/src/main/java/com/baeldung => spring-reactive-exceptions/src/main/java/com/baeldung/spring}/reactive/errorhandling/Handler.java (97%) rename spring-reactive-modules/{spring-reactive/src/main/java/com/baeldung => spring-reactive-exceptions/src/main/java/com/baeldung/spring}/reactive/errorhandling/NameRequiredException.java (85%) rename spring-reactive-modules/{spring-reactive/src/main/java/com/baeldung => spring-reactive-exceptions/src/main/java/com/baeldung/spring}/reactive/errorhandling/Router.java (96%) rename spring-reactive-modules/{spring-reactive/src/test/java/com/baeldung => spring-reactive-exceptions/src/test/java/com/baeldung/spring}/reactive/errorhandling/ErrorHandlingIntegrationTest.java (98%) rename spring-reactive-modules/{spring-5-reactive-filters => spring-reactive-filters}/.gitignore (100%) rename spring-reactive-modules/{spring-5-reactive-filters => spring-reactive-filters}/README.md (76%) rename spring-reactive-modules/{spring-5-reactive-filters => spring-reactive-filters}/pom.xml (81%) rename spring-reactive-modules/{spring-5-reactive-filters => spring-reactive-filters}/src/main/java/com/baeldung/reactive/Spring5ReactiveFiltersApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-filters => spring-reactive-filters}/src/main/java/com/baeldung/reactive/filters/ExampleHandlerFilterFunction.java (100%) rename spring-reactive-modules/{spring-5-reactive-filters => spring-reactive-filters}/src/main/java/com/baeldung/reactive/filters/ExampleWebFilter.java (100%) rename spring-reactive-modules/{spring-5-reactive-filters => spring-reactive-filters}/src/main/java/com/baeldung/reactive/filters/PlayerHandler.java (100%) rename spring-reactive-modules/{spring-5-reactive-filters => spring-reactive-filters}/src/main/java/com/baeldung/reactive/filters/PlayerRouter.java (100%) rename spring-reactive-modules/{spring-5-reactive-filters => spring-reactive-filters}/src/main/java/com/baeldung/reactive/filters/UserController.java (100%) rename spring-reactive-modules/{spring-5-reactive-client/src/main/java/com/baeldung/webclient/filter => spring-reactive-filters/src/main/java/com/baeldung/reactive/filters}/WebClientFilters.java (98%) rename spring-reactive-modules/{spring-5-reactive-filters => spring-reactive-filters}/src/main/resources/application.properties (100%) rename spring-reactive-modules/{spring-5-reactive-filters => spring-reactive-filters}/src/main/resources/logback.xml (100%) rename spring-reactive-modules/{spring-5-reactive-filters => spring-reactive-filters}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-client/src/test/java/com/baeldung/webclient/filter => spring-reactive-filters/src/test/java/com/baeldung/reactive/filters}/FilteredWebClientUnitTest.java (95%) rename spring-reactive-modules/{spring-5-reactive-filters => spring-reactive-filters}/src/test/java/com/baeldung/reactive/filters/PlayerHandlerIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-filters => spring-reactive-filters}/src/test/java/com/baeldung/reactive/filters/UserControllerIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/README.md (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/pom.xml (96%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/reactive/oauth/SecurityConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/reactive/oauth/web/MainController.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/reactive/oauth/web/dto/Foo.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/authorizationcodeclient/OauthClientApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebClientConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebSecurityConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/authorizationcodeclient/web/ClientRestController.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/authorizationcodelogin/OauthClientLoginApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebClientConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebSecurityConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/authorizationcodelogin/web/ClientRestController.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/clientcredentials/ClientCredentialsOauthApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/clientcredentials/configuration/WebClientConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/clientcredentials/service/WebClientChonJob.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/manualrequest/ManualRequestApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/manualrequest/configure/WebClientConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/manualrequest/configure/WebSecurityConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/java/com/baeldung/webclient/manualrequest/web/ManualOauthRequestController.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/resources/application.yml (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/resources/default-application.yml (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/resources/webclient-auth-code-client-application.properties (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/resources/webclient-auth-code-login-application.properties (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/resources/webclient-client-credentials-oauth-application.properties (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/main/resources/webclient-manual-request-oauth-application.properties (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/test/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/test/java/com/baeldung/webclient/clientcredentials/OAuth2ClientCredentialsLiveTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/test/java/com/baeldung/webclient/manualrequest/OAuth2ManualRequestLiveTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/test/java/com/baeldung/webclient/utils/ListAppender.java (100%) rename spring-reactive-modules/{spring-5-reactive-oauth => spring-reactive-oauth}/src/test/resources/logback-test.xml (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/.gitignore (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/README.md (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/pom.xml (93%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/actuator/DownstreamServiceHealthIndicator.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/actuator/FeaturesEndpoint.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/actuator/InfoWebEndpointExtension.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/actuator/Spring5ReactiveApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/actuator/WebSecurityConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/authresolver/AuthResolverApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/authresolver/AuthResolverController.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/authresolver/CustomWebSecurityConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/annotated/CorsOnAnnotatedElementsApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnClassController.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnMethodsController.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/global/CorsGlobalConfigApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/global/config/CorsGlobalConfiguration.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/global/controllers/FurtherCorsConfigsController.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/global/controllers/RegularRestController.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/global/functional/handlers/CorsGlobalFunctionalHandler.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/global/functional/routers/CorsRouterFunctions.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/webfilter/CorsWebFilterApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/webfilter/config/CorsWebFilterConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/FurtherCorsConfigsController.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/RegularRestController.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/webfilter/functional/handlers/CorsWithWebFilterHandler.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/reactive/cors/webfilter/functional/routers/CorsWithWebFilterRouterFunctions.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/webflux/Employee.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/webflux/EmployeeConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/webflux/EmployeeCreationEvent.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/webflux/EmployeeWebSecurityConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/webflux/EmployeeWebSocketClient.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/java/com/baeldung/webflux/EmployeeWebSocketHandler.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/resources/application.properties (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/resources/files/hello.txt (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/resources/files/test/test.txt (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/resources/logback.xml (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/resources/static/client-websocket.html (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/main/webapp/WEB-INF/web.xml (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/test/java/com/baeldung/reactive/actuator/ActuatorInfoIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/test/java/com/baeldung/reactive/authresolver/AuthResolverIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java (100%) rename spring-reactive-modules/{spring-5-reactive-security => spring-reactive-security}/src/test/resources/baeldung-weekly.png (100%) create mode 100644 spring-reactive-modules/spring-reactive-webflux/README.md create mode 100644 spring-reactive-modules/spring-reactive-webflux/pom.xml rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/concurrency/Application.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/concurrency/Controller.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/concurrency/Person.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/concurrency/PersonRepository.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/debugging/consumer/ConsumerDebuggingApplication.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/debugging/consumer/controllers/ReactiveConfigsToggleRestController.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/debugging/consumer/cronjobs/CronJobs.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/debugging/consumer/model/Foo.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/debugging/consumer/model/FooDto.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooNameHelper.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooQuantityHelper.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooReporter.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooService.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/debugging/server/ServerDebuggingApplication.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/debugging/server/handlers/ServerHandler.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/debugging/server/model/Foo.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/debugging/server/routers/ServerRouter.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/security/GreetingController.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/security/GreetingService.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/security/SecurityConfig.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/security/SpringSecurity6Application.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webclient/Foo.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webclient/Tweet.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webclient/TweetsSlowServiceController.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webclient/WebClientApplication.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webclient/WebClientController.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webclient/WebController.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webclientrequests/SpringWebClientRequestsApp.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webflux/Employee.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webflux/EmployeeRepository.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeController.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeSpringApplication.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebClient.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebSecurityConfig.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeFunctionalConfig.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalApplication.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceLiveTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/test/java/com/baeldung/reactive/debugging/consumer/utils/ListAppender.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/test/java/com/baeldung/reactive/introduction/ReactorIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/test/java/com/baeldung/reactive/security/SecurityIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/test/java/com/baeldung/reactive/webclient/SpringContextTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/test/java/com/baeldung/reactive/webclient/WebClientIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/test/java/com/baeldung/reactive/webclient/WebControllerIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/test/java/com/baeldung/reactive/webclient/WebTestClientIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/test/java/com/baeldung/reactive/webclientrequests/WebClientRequestsWithParametersUnitTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/test/java/com/baeldung/reactive/webflux/annotation/EmployeeControllerIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/test/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-reactive-webflux}/src/test/resources/logback-test.xml (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/.gitignore (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/assets/index.html (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/functional/Actor.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/functional/FormHandler.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/functional/FunctionalWebApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/functional/IndexRewriteFilter.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/functional/RootServlet.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/reactive/controller/PathPatternController.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/reactive/model/Foo.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/reactive/responseheaders/controllers/ResponseHeaderController.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/reactive/responseheaders/filter/AddResponseHeaderWebFilter.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/reactive/responseheaders/functional/handlers/ResponseHeaderHandler.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/reactive/responseheaders/functional/routers/ResponseHeadersRouterFunctions.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/reactive/urlmatch/Actor.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/reactive/urlmatch/FunctionalWebApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/reactive/urlmatch/IndexRewriteFilter.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/reactive/util/CpuUtils.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/websession/Application.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/websession/configuration/RedisConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/websession/configuration/SessionConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/websession/configuration/WebFluxConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/websession/configuration/WebFluxSecurityConfig.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/websession/controller/SessionController.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/websession/transfer/CustomResponse.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/websocket/Event.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/websocket/ReactiveJavaClientWebSocket.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/websocket/ReactiveWebSocketApplication.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/websocket/ReactiveWebSocketConfiguration.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/websocket/ReactiveWebSocketHandler.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/java/com/baeldung/websocket/WebSocketController.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/resources/application.properties (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/resources/files/hello.txt (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/resources/files/test/test.txt (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/resources/logback.xml (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/resources/resources/test/test.txt (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/resources/static/client-websocket.html (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/main/webapp/WEB-INF/web.xml (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/test/java/com/baeldung/reactive/FluxUnitTest.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/test/java/com/baeldung/reactive/responseheaders/ResponseHeaderLiveTest.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java (100%) rename spring-reactive-modules/{spring-5-reactive => spring-reactive}/src/test/resources/baeldung-weekly.png (100%) diff --git a/spring-reactive-modules/pom.xml b/spring-reactive-modules/pom.xml index 309687f011..efae864b46 100644 --- a/spring-reactive-modules/pom.xml +++ b/spring-reactive-modules/pom.xml @@ -17,18 +17,18 @@ - spring-5-data-reactive - spring-5-data-reactive-2 - spring-5-reactive - spring-5-reactive-2 - spring-5-reactive-3 - spring-5-reactive-client - spring-5-reactive-client-2 - spring-5-reactive-filters - spring-5-reactive-oauth - spring-5-reactive-security - spring-data-couchbase + spring-reactive-data + spring-reactive-data-2 spring-reactive + spring-reactive-2 + spring-reactive-3 + spring-reactive-client + spring-reactive-client-2 + spring-reactive-filters + spring-reactive-oauth + spring-reactive-security + spring-data-couchbase + spring-reactive-webflux spring-reactive-exceptions spring-reactor spring-webflux-amqp diff --git a/spring-reactive-modules/spring-5-reactive/README.md b/spring-reactive-modules/spring-5-reactive/README.md deleted file mode 100644 index f3148fe696..0000000000 --- a/spring-reactive-modules/spring-5-reactive/README.md +++ /dev/null @@ -1,14 +0,0 @@ -## Spring 5 Reactive Project - -This module contains articles about reactive Spring 5 - -### The Course -The "REST With Spring" Classes: https://bit.ly/restwithspring - -### Relevant Articles - -- [Exploring the Spring 5 WebFlux URL Matching](https://www.baeldung.com/spring-5-mvc-url-matching) -- [Reactive WebSockets with Spring 5](https://www.baeldung.com/spring-5-reactive-websockets) -- [How to Set a Header on a Response with Spring 5](https://www.baeldung.com/spring-response-header) -- [A Guide to Spring Session Reactive Support: WebSession](https://www.baeldung.com/spring-session-reactive) -- More articles: [[next -->]](../spring-5-reactive-2) diff --git a/spring-reactive-modules/spring-5-reactive/pom.xml b/spring-reactive-modules/spring-5-reactive/pom.xml deleted file mode 100644 index 212281b6f9..0000000000 --- a/spring-reactive-modules/spring-5-reactive/pom.xml +++ /dev/null @@ -1,165 +0,0 @@ - - - 4.0.0 - spring-5-reactive - 0.0.1-SNAPSHOT - spring-5-reactive - jar - spring 5 sample project about new features - - - com.baeldung.spring.reactive - spring-reactive-modules - 1.0.0-SNAPSHOT - - - - - org.springframework.boot - spring-boot-starter-validation - - - org.springframework.boot - spring-boot-starter-tomcat - - - org.springframework.boot - spring-boot-starter-integration - - - org.springframework.boot - spring-boot-starter-websocket - - - javax.json.bind - javax.json.bind-api - - - org.projectlombok - lombok - compile - - - org.apache.geronimo.specs - geronimo-json_1.1_spec - ${geronimo-json_1.1_spec.version} - - - org.apache.johnzon - johnzon-jsonb - - - - org.apache.commons - commons-lang3 - - - - org.springframework.boot - spring-boot-devtools - runtime - - - org.springframework - spring-test - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.security - spring-security-test - test - - - io.projectreactor - reactor-test - test - - - - org.springframework.boot - spring-boot-starter-webflux - - - org.springframework.boot - spring-boot-starter-data-redis - - - org.springframework.boot - spring-boot-starter-security - - - org.springframework.session - spring-session-core - - - org.springframework.session - spring-session-data-redis - - - org.apache.commons - commons-collections4 - ${commons-collections4.version} - test - - - io.reactivex.rxjava2 - rxjava - - - org.apache.httpcomponents - httpclient - - - io.netty - netty-all - - - - - - - maven-resources-plugin - 3.0.1 - - - copy-resources - validate - - copy-resources - - - - - src/main/assets - true - - - ${basedir}/target/classes/assets - - - - - - org.springframework.boot - spring-boot-maven-plugin - - com.baeldung.reactive.Spring5ReactiveApplication - JAR - - - - - - - 1.1.3 - 1.0 - 1.0 - - - \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/pom.xml b/spring-reactive-modules/spring-data-couchbase/pom.xml index 68ddd1cefa..d7b36f97fa 100644 --- a/spring-reactive-modules/spring-data-couchbase/pom.xml +++ b/spring-reactive-modules/spring-data-couchbase/pom.xml @@ -1,7 +1,7 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-data-couchbase spring-data-couchbase diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java index 4e5bf9d5dc..0ca7c9a8d1 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java @@ -10,4 +10,4 @@ public class ReactiveCouchbaseApplication { public static void main(String[] args) { SpringApplication.run(ReactiveCouchbaseApplication.class, args); } -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java index 81f19eebd6..cc9540eecb 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java @@ -40,4 +40,4 @@ public class CouchbaseProperties { public int getPort() { return port; } -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java index 059bd36cae..7ba12db2c6 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java @@ -12,4 +12,4 @@ public class N1QLReactiveCouchbaseConfiguration extends ReactiveCouchbaseConfigu public N1QLReactiveCouchbaseConfiguration(CouchbaseProperties couchbaseProperties) { super(couchbaseProperties); } -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java index a51b19ee22..1816082f7c 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java @@ -45,4 +45,4 @@ public abstract class ReactiveCouchbaseConfiguration extends AbstractReactiveCou public IndexManager couchbaseIndexManager() { return new IndexManager(true, true, false); } -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java index 9b4d9b0319..578a03ae19 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java @@ -10,4 +10,4 @@ public class ViewReactiveCouchbaseConfiguration extends ReactiveCouchbaseConfigu public ViewReactiveCouchbaseConfiguration(CouchbaseProperties couchbaseProperties) { super(couchbaseProperties); } -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/Person.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/Person.java index 285de34df8..5a1b1eec18 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/Person.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/Person.java @@ -40,4 +40,4 @@ public class Person { public int hashCode() { return Objects.hash(id, firstName); } -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java index 6f73a77ceb..e78316e218 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java @@ -13,4 +13,4 @@ import java.util.UUID; public interface N1QLPersonRepository extends ReactiveCrudRepository { Flux findAllByFirstName(final String firstName); -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java index 57dd149425..1225ed914a 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java @@ -10,4 +10,4 @@ import java.util.UUID; @Repository @N1qlPrimaryIndexed public interface N1QLSortingPersonRepository extends ReactiveSortingRepository { -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java index 06c47c2393..4b3f0a7f1c 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java @@ -17,4 +17,4 @@ public interface ViewPersonRepository extends ReactiveCrudRepository findByFirstName(String firstName); -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java index 2a09fce4b0..082ad5061b 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java +++ b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java @@ -1,16 +1,18 @@ package com.baeldung.couchbase.domain.repository; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.Collections; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.springframework.boot.test.context.TestConfiguration; + import com.baeldung.couchbase.configuration.CouchbaseProperties; import com.couchbase.mock.Bucket; import com.couchbase.mock.BucketConfiguration; import com.couchbase.mock.CouchbaseMock; -import org.springframework.boot.test.context.TestConfiguration; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.util.Collections; @TestConfiguration public class CouchbaseMockConfiguration { diff --git a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java index c8dbbf429e..51bca948c0 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java +++ b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java @@ -1,16 +1,19 @@ package com.baeldung.couchbase.domain.repository.n1ql; -import com.baeldung.couchbase.domain.Person; +import java.util.UUID; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.couchbase.domain.Person; +import com.baeldung.couchbase.domain.repository.n1ql.N1QLPersonRepository; + import reactor.core.publisher.Flux; import reactor.test.StepVerifier; -import java.util.UUID; - @RunWith(SpringRunner.class) @SpringBootTest(properties = {"spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration"}) public class N1QLPersonRepositoryLiveTest { diff --git a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java index 8c6ce137f1..dbc353a94b 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java +++ b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java @@ -1,17 +1,20 @@ package com.baeldung.couchbase.domain.repository.n1ql; -import com.baeldung.couchbase.domain.Person; +import java.util.UUID; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Sort; import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.couchbase.domain.Person; +import com.baeldung.couchbase.domain.repository.n1ql.N1QLSortingPersonRepository; + import reactor.core.publisher.Flux; import reactor.test.StepVerifier; -import java.util.UUID; - @RunWith(SpringRunner.class) @SpringBootTest(properties = {"spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration"}) public class N1QLSortingPersonRepositoryLiveTest { diff --git a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java index 15688e1b80..038d4dec31 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java +++ b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java @@ -1,21 +1,22 @@ package com.baeldung.couchbase.domain.repository.view; +import java.util.UUID; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + import com.baeldung.couchbase.configuration.CouchbaseProperties; import com.baeldung.couchbase.configuration.ViewReactiveCouchbaseConfiguration; import com.baeldung.couchbase.domain.Person; import com.baeldung.couchbase.domain.repository.CouchbaseMockConfiguration; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; + import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.util.UUID; - @RunWith(SpringRunner.class) @SpringBootTest(properties = { "spring.couchbase.port=10010", "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration" }, classes = { CouchbaseMockConfiguration.class, ViewReactiveCouchbaseConfiguration.class, CouchbaseProperties.class }) diff --git a/spring-reactive-modules/spring-5-reactive-2/.gitignore b/spring-reactive-modules/spring-reactive-2/.gitignore similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/.gitignore rename to spring-reactive-modules/spring-reactive-2/.gitignore diff --git a/spring-reactive-modules/spring-5-reactive-2/README.md b/spring-reactive-modules/spring-reactive-2/README.md similarity index 91% rename from spring-reactive-modules/spring-5-reactive-2/README.md rename to spring-reactive-modules/spring-reactive-2/README.md index 1cd3bf46c6..a5df5187bf 100644 --- a/spring-reactive-modules/spring-5-reactive-2/README.md +++ b/spring-reactive-modules/spring-reactive-2/README.md @@ -1,6 +1,6 @@ ## Spring 5 Reactive Project -This module contains articles about reactive Spring 5. +This module contains articles about reactive Spring Boot. - [Validation for Functional Endpoints in Spring 5](https://www.baeldung.com/spring-functional-endpoints-validation) - [Testing Reactive Streams Using StepVerifier and TestPublisher](https://www.baeldung.com/reactive-streams-step-verifier-test-publisher) diff --git a/spring-reactive-modules/spring-5-reactive-2/pom.xml b/spring-reactive-modules/spring-reactive-2/pom.xml similarity index 98% rename from spring-reactive-modules/spring-5-reactive-2/pom.xml rename to spring-reactive-modules/spring-reactive-2/pom.xml index 41c434fb92..ba40f3b48a 100644 --- a/spring-reactive-modules/spring-5-reactive-2/pom.xml +++ b/spring-reactive-modules/spring-reactive-2/pom.xml @@ -3,7 +3,7 @@ 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"> 4.0.0 - spring-5-reactive-2 + spring-reactive-2 0.0.1-SNAPSHOT spring-5-reactive-2 jar diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/controller/ClientController.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/controller/ClientController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/controller/ClientController.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/controller/ClientController.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/ServerSSEApplication.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/ServerSSEApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/ServerSSEApplication.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/ServerSSEApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/controllers/ServerController.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/controllers/ServerController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/controllers/ServerController.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/controllers/ServerController.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentApplication.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentApplication.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/AbstractValidationHandler.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/AbstractValidationHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/AbstractValidationHandler.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/AbstractValidationHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/FunctionalHandler.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/FunctionalHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/FunctionalHandler.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/FunctionalHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/AnnotatedRequestEntityValidationHandler.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/AnnotatedRequestEntityValidationHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/AnnotatedRequestEntityValidationHandler.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/AnnotatedRequestEntityValidationHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/CustomRequestEntityValidationHandler.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/CustomRequestEntityValidationHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/CustomRequestEntityValidationHandler.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/CustomRequestEntityValidationHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/OtherEntityValidationHandler.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/OtherEntityValidationHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/OtherEntityValidationHandler.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/OtherEntityValidationHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/model/CustomRequestEntity.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/CustomRequestEntity.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/model/CustomRequestEntity.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/CustomRequestEntity.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/model/OtherEntity.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/OtherEntity.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/model/OtherEntity.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/OtherEntity.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/routers/ValidationsRouters.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/routers/ValidationsRouters.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/routers/ValidationsRouters.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/routers/ValidationsRouters.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/validators/CustomRequestEntityValidator.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/validators/CustomRequestEntityValidator.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/validators/CustomRequestEntityValidator.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/validators/CustomRequestEntityValidator.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/validators/OtherEntityValidator.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/validators/OtherEntityValidator.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/validators/OtherEntityValidator.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/validators/OtherEntityValidator.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/resources/application-assets-custom-location.properties b/spring-reactive-modules/spring-reactive-2/src/main/resources/application-assets-custom-location.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/resources/application-assets-custom-location.properties rename to spring-reactive-modules/spring-reactive-2/src/main/resources/application-assets-custom-location.properties diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentCustomLocationIntegrationTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentCustomLocationIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentCustomLocationIntegrationTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentCustomLocationIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentDefaultLocationIntegrationTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentDefaultLocationIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentDefaultLocationIntegrationTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentDefaultLocationIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/PostExecutionUnitTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/PostExecutionUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/PostExecutionUnitTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/PostExecutionUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/StepByStepUnitTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/StepByStepUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/StepByStepUnitTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/StepByStepUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/TestingTestPublisherUnitTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/TestingTestPublisherUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/TestingTestPublisherUnitTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/TestingTestPublisherUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/TimeBasedUnitTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/TimeBasedUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/TimeBasedUnitTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/TimeBasedUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/validations/functional/FunctionalEndpointValidationsLiveTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/validations/functional/FunctionalEndpointValidationsLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/validations/functional/FunctionalEndpointValidationsLiveTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/validations/functional/FunctionalEndpointValidationsLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/resources/assets/index.html b/spring-reactive-modules/spring-reactive-2/src/test/resources/assets/index.html similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/resources/assets/index.html rename to spring-reactive-modules/spring-reactive-2/src/test/resources/assets/index.html diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/resources/img/example-image.png b/spring-reactive-modules/spring-reactive-2/src/test/resources/img/example-image.png similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/resources/img/example-image.png rename to spring-reactive-modules/spring-reactive-2/src/test/resources/img/example-image.png diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/resources/logback-test.xml b/spring-reactive-modules/spring-reactive-2/src/test/resources/logback-test.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/resources/logback-test.xml rename to spring-reactive-modules/spring-reactive-2/src/test/resources/logback-test.xml diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/resources/public/index.html b/spring-reactive-modules/spring-reactive-2/src/test/resources/public/index.html similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/resources/public/index.html rename to spring-reactive-modules/spring-reactive-2/src/test/resources/public/index.html diff --git a/spring-reactive-modules/spring-5-reactive-3/.gitignore b/spring-reactive-modules/spring-reactive-3/.gitignore similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/.gitignore rename to spring-reactive-modules/spring-reactive-3/.gitignore diff --git a/spring-reactive-modules/spring-5-reactive-3/README.md b/spring-reactive-modules/spring-reactive-3/README.md similarity index 72% rename from spring-reactive-modules/spring-5-reactive-3/README.md rename to spring-reactive-modules/spring-reactive-3/README.md index 38036f929b..640a60d63d 100644 --- a/spring-reactive-modules/spring-5-reactive-3/README.md +++ b/spring-reactive-modules/spring-reactive-3/README.md @@ -1,9 +1,8 @@ ## Spring 5 Reactive Project -This module contains articles about reactive Spring 5. +This module contains articles about reactive Spring Boot. - [Logging a Reactive Sequence](https://www.baeldung.com/spring-reactive-sequence-logging) - [Reading Flux Into a Single InputStream Using Spring Reactive WebClient](https://www.baeldung.com/spring-reactive-read-flux-into-inputstream) -- [Spring Boot FeignClient vs. WebClient](https://www.baeldung.com/spring-boot-feignclient-vs-webclient) - [Cancel an Ongoing Flux in Spring WebFlux](https://www.baeldung.com/spring-webflux-cancel-flux) - More articles: [[<-- prev]](../spring-5-reactive-2) diff --git a/spring-reactive-modules/spring-5-reactive-3/pom.xml b/spring-reactive-modules/spring-reactive-3/pom.xml similarity index 98% rename from spring-reactive-modules/spring-5-reactive-3/pom.xml rename to spring-reactive-modules/spring-reactive-3/pom.xml index d33b63e921..7672fa29f3 100644 --- a/spring-reactive-modules/spring-5-reactive-3/pom.xml +++ b/spring-reactive-modules/spring-reactive-3/pom.xml @@ -3,7 +3,7 @@ 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"> 4.0.0 - spring-5-reactive-3 + spring-reactive-3 0.0.1-SNAPSHOT spring-5-reactive-3 jar diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/databuffer/DataBufferToInputStream.java b/spring-reactive-modules/spring-reactive-3/src/main/java/com/baeldung/databuffer/DataBufferToInputStream.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/databuffer/DataBufferToInputStream.java rename to spring-reactive-modules/spring-reactive-3/src/main/java/com/baeldung/databuffer/DataBufferToInputStream.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webflux/logging/WebFluxLoggingExample.java b/spring-reactive-modules/spring-reactive-3/src/main/java/com/baeldung/webflux/logging/WebFluxLoggingExample.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webflux/logging/WebFluxLoggingExample.java rename to spring-reactive-modules/spring-reactive-3/src/main/java/com/baeldung/webflux/logging/WebFluxLoggingExample.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/resources/application.properties b/spring-reactive-modules/spring-reactive-3/src/main/resources/application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/resources/application.properties rename to spring-reactive-modules/spring-reactive-3/src/main/resources/application.properties diff --git a/spring-reactive-modules/spring-5-reactive-3/src/test/java/com/baeldung/cancelflux/CancelFluxUnitTest.java b/spring-reactive-modules/spring-reactive-3/src/test/java/com/baeldung/cancelflux/CancelFluxUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/test/java/com/baeldung/cancelflux/CancelFluxUnitTest.java rename to spring-reactive-modules/spring-reactive-3/src/test/java/com/baeldung/cancelflux/CancelFluxUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/test/java/com/baeldung/databuffer/DataBufferToInputStreamUnitTest.java b/spring-reactive-modules/spring-reactive-3/src/test/java/com/baeldung/databuffer/DataBufferToInputStreamUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/test/java/com/baeldung/databuffer/DataBufferToInputStreamUnitTest.java rename to spring-reactive-modules/spring-reactive-3/src/test/java/com/baeldung/databuffer/DataBufferToInputStreamUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/test/resources/logback-test.xml b/spring-reactive-modules/spring-reactive-3/src/test/resources/logback-test.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/test/resources/logback-test.xml rename to spring-reactive-modules/spring-reactive-3/src/test/resources/logback-test.xml diff --git a/spring-reactive-modules/spring-5-reactive-3/src/test/resources/user-response.json b/spring-reactive-modules/spring-reactive-3/src/test/resources/user-response.json similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/test/resources/user-response.json rename to spring-reactive-modules/spring-reactive-3/src/test/resources/user-response.json diff --git a/spring-reactive-modules/spring-5-reactive-client-2/README.md b/spring-reactive-modules/spring-reactive-client-2/README.md similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/README.md rename to spring-reactive-modules/spring-reactive-client-2/README.md diff --git a/spring-reactive-modules/spring-5-reactive-client-2/pom.xml b/spring-reactive-modules/spring-reactive-client-2/pom.xml similarity index 94% rename from spring-reactive-modules/spring-5-reactive-client-2/pom.xml rename to spring-reactive-modules/spring-reactive-client-2/pom.xml index e86134badc..5d5f3ebc2e 100644 --- a/spring-reactive-modules/spring-5-reactive-client-2/pom.xml +++ b/spring-reactive-modules/spring-reactive-client-2/pom.xml @@ -3,10 +3,10 @@ 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"> 4.0.0 - spring-5-reactive-client-2 - spring-5-reactive-client-2 + spring-reactive-client-2 + spring-reactive-client-2 jar - spring 5 sample project about new features + spring boot sample project about new features com.baeldung.spring.reactive @@ -93,10 +93,6 @@ org.apache.maven.plugins maven-compiler-plugin - - 1.8 - 1.8 - diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/LimitRequestsApp.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/LimitRequestsApp.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/LimitRequestsApp.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/LimitRequestsApp.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/DelayElements.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/DelayElements.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/DelayElements.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/DelayElements.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/GuavaRateLimit.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/GuavaRateLimit.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/GuavaRateLimit.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/GuavaRateLimit.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/LimitConcurrency.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/LimitConcurrency.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/LimitConcurrency.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/LimitConcurrency.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/Resilience4jRateLimit.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/Resilience4jRateLimit.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/Resilience4jRateLimit.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/Resilience4jRateLimit.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/ZipWithInterval.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/ZipWithInterval.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/ZipWithInterval.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/ZipWithInterval.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/Client.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/Client.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/Client.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/Client.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/RandomConsumer.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/RandomConsumer.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/RandomConsumer.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/RandomConsumer.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/Concurrency.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/Concurrency.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/Concurrency.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/Concurrency.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/RandomController.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/RandomController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/RandomController.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/RandomController.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/StreamLargeFileApp.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/StreamLargeFileApp.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/StreamLargeFileApp.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/StreamLargeFileApp.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LargeFileDownloadWebClient.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LargeFileDownloadWebClient.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LargeFileDownloadWebClient.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LargeFileDownloadWebClient.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LimitedFileDownloadWebClient.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LimitedFileDownloadWebClient.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LimitedFileDownloadWebClient.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LimitedFileDownloadWebClient.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/server/LargeFileController.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/server/LargeFileController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/server/LargeFileController.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/server/LargeFileController.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/application.properties b/spring-reactive-modules/spring-reactive-client-2/src/main/resources/application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/application.properties rename to spring-reactive-modules/spring-reactive-client-2/src/main/resources/application.properties diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/logback.xml b/spring-reactive-modules/spring-reactive-client-2/src/main/resources/logback.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/logback.xml rename to spring-reactive-modules/spring-reactive-client-2/src/main/resources/logback.xml diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/streamlargefile/generate-sample-files.sh b/spring-reactive-modules/spring-reactive-client-2/src/main/resources/streamlargefile/generate-sample-files.sh old mode 100755 new mode 100644 similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/streamlargefile/generate-sample-files.sh rename to spring-reactive-modules/spring-reactive-client-2/src/main/resources/streamlargefile/generate-sample-files.sh diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/streamlargefile/run.sh b/spring-reactive-modules/spring-reactive-client-2/src/main/resources/streamlargefile/run.sh old mode 100755 new mode 100644 similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/streamlargefile/run.sh rename to spring-reactive-modules/spring-reactive-client-2/src/main/resources/streamlargefile/run.sh diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/test/java/com/baeldung/limitrequests/RandomControllerLiveTest.java b/spring-reactive-modules/spring-reactive-client-2/src/test/java/com/baeldung/limitrequests/RandomControllerLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/test/java/com/baeldung/limitrequests/RandomControllerLiveTest.java rename to spring-reactive-modules/spring-reactive-client-2/src/test/java/com/baeldung/limitrequests/RandomControllerLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/test/java/com/baeldung/streamlargefile/LargeFileControllerLiveTest.java b/spring-reactive-modules/spring-reactive-client-2/src/test/java/com/baeldung/streamlargefile/LargeFileControllerLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/test/java/com/baeldung/streamlargefile/LargeFileControllerLiveTest.java rename to spring-reactive-modules/spring-reactive-client-2/src/test/java/com/baeldung/streamlargefile/LargeFileControllerLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/test/resources/logback-test.xml b/spring-reactive-modules/spring-reactive-client-2/src/test/resources/logback-test.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/test/resources/logback-test.xml rename to spring-reactive-modules/spring-reactive-client-2/src/test/resources/logback-test.xml diff --git a/spring-reactive-modules/spring-5-reactive-client/.gitignore b/spring-reactive-modules/spring-reactive-client/.gitignore similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/.gitignore rename to spring-reactive-modules/spring-reactive-client/.gitignore diff --git a/spring-reactive-modules/spring-5-reactive-client/README.md b/spring-reactive-modules/spring-reactive-client/README.md similarity index 89% rename from spring-reactive-modules/spring-5-reactive-client/README.md rename to spring-reactive-modules/spring-reactive-client/README.md index f1793070b3..fc67a4f16e 100644 --- a/spring-reactive-modules/spring-5-reactive-client/README.md +++ b/spring-reactive-modules/spring-reactive-client/README.md @@ -9,8 +9,8 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Logging Spring WebClient Calls](https://www.baeldung.com/spring-log-webclient-calls) - [Simultaneous Spring WebClient Calls](https://www.baeldung.com/spring-webclient-simultaneous-calls) - [Mocking a WebClient in Spring](https://www.baeldung.com/spring-mocking-webclient) -- [Spring WebClient Filters](https://www.baeldung.com/spring-webclient-filters) - [Get List of JSON Objects with WebClient](https://www.baeldung.com/spring-webclient-json-list) - [Upload a File with WebClient](https://www.baeldung.com/spring-webclient-upload-file) - [How to Get Response Body When Testing the Status Code in WebFlux WebClient](https://www.baeldung.com/spring-webclient-get-response-body) +- [Spring Boot FeignClient vs. WebClient](https://www.baeldung.com/spring-boot-feignclient-vs-webclient) - More articles: [[next -->]](../spring-5-reactive-client-2) diff --git a/spring-reactive-modules/spring-5-reactive-client/pom.xml b/spring-reactive-modules/spring-reactive-client/pom.xml similarity index 93% rename from spring-reactive-modules/spring-5-reactive-client/pom.xml rename to spring-reactive-modules/spring-reactive-client/pom.xml index a0e5f7794e..94134e5271 100644 --- a/spring-reactive-modules/spring-5-reactive-client/pom.xml +++ b/spring-reactive-modules/spring-reactive-client/pom.xml @@ -3,10 +3,10 @@ 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"> 4.0.0 - spring-5-reactive-client - spring-5-reactive-client + spring-reactive-client + spring-reactive-client jar - spring 5 sample project about new features + spring boot sample project about new features com.baeldung.spring.reactive @@ -32,8 +32,9 @@ spring-boot-starter-webflux - org.springframework.boot - spring-boot-starter-security + org.springframework.cloud + spring-cloud-starter-openfeign + ${spring-cloud-starter-openfeign.version} org.projectreactor @@ -176,13 +177,12 @@ 1.0.1.RELEASE - 1.1.3 - 1.0 1.0 1.1.6 4.0.1 3.5.3 2.26.0 + 3.1.4 \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/controller/UploadController.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/controller/UploadController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/controller/UploadController.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/controller/UploadController.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/enums/Role.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/enums/Role.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/enums/Role.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/enums/Role.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/exception/ServiceException.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/exception/ServiceException.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/exception/ServiceException.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/exception/ServiceException.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/model/Employee.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/model/Employee.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/model/Employee.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/model/Employee.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/model/Foo.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/model/Foo.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/model/Foo.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/model/Foo.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/service/EmployeeService.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/service/EmployeeService.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/service/EmployeeService.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/service/EmployeeService.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/service/ReactiveUploadService.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/service/ReactiveUploadService.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/service/ReactiveUploadService.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/service/ReactiveUploadService.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Client.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Client.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Client.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Client.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Item.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Item.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Item.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Item.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/User.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/User.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/User.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/User.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/UserWithItem.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/UserWithItem.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/UserWithItem.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/UserWithItem.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/Product.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/Product.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/Product.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/Product.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/ProductsFeignClient.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/ProductsFeignClient.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/ProductsFeignClient.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/ProductsFeignClient.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/ProductsSlowServiceController.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/ProductsSlowServiceController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/ProductsSlowServiceController.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/ProductsSlowServiceController.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/WebClientApplication.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/WebClientApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/WebClientApplication.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/WebClientApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/WebController.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/WebController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/WebController.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/WebController.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/status/WebClientStatusCodeHandler.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/status/WebClientStatusCodeHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/status/WebClientStatusCodeHandler.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/status/WebClientStatusCodeHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomBadRequestException.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomBadRequestException.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomBadRequestException.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomBadRequestException.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomServerErrorException.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomServerErrorException.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomServerErrorException.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomServerErrorException.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/timeout/WebClientTimeoutProvider.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/timeout/WebClientTimeoutProvider.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/timeout/WebClientTimeoutProvider.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/timeout/WebClientTimeoutProvider.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/resources/application.properties b/spring-reactive-modules/spring-reactive-client/src/main/resources/application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/resources/application.properties rename to spring-reactive-modules/spring-reactive-client/src/main/resources/application.properties diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/resources/logback.xml b/spring-reactive-modules/spring-reactive-client/src/main/resources/logback.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/resources/logback.xml rename to spring-reactive-modules/spring-reactive-client/src/main/resources/logback.xml diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/webapp/WEB-INF/web.xml b/spring-reactive-modules/spring-reactive-client/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/webapp/WEB-INF/web.xml rename to spring-reactive-modules/spring-reactive-client/src/main/webapp/WEB-INF/web.xml diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/SpringContextTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/SpringContextTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/Spring5ReactiveTestApplication.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/Spring5ReactiveTestApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/Spring5ReactiveTestApplication.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/Spring5ReactiveTestApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/logging/WebClientLoggingIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/WebClientLoggingIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/logging/WebClientLoggingIntegrationTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/WebClientLoggingIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/logging/filters/LogFilters.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/filters/LogFilters.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/logging/filters/LogFilters.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/filters/LogFilters.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/logging/jetty/RequestLogEnhancer.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/jetty/RequestLogEnhancer.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/logging/jetty/RequestLogEnhancer.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/jetty/RequestLogEnhancer.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceIntegrationTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceUnitTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceUnitTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/ReactiveUploadServiceUnitTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/service/ReactiveUploadServiceUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/ReactiveUploadServiceUnitTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/service/ReactiveUploadServiceUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/WebClientStatusCodeHandlerIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/WebClientStatusCodeHandlerIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/WebClientStatusCodeHandlerIntegrationTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/WebClientStatusCodeHandlerIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/test/java/com/baeldung/webclient/WebControllerIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/WebControllerIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/test/java/com/baeldung/webclient/WebControllerIntegrationTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/WebControllerIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/timeout/WebClientTimeoutIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/timeout/WebClientTimeoutIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/timeout/WebClientTimeoutIntegrationTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/timeout/WebClientTimeoutIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/resources/logback-test.xml b/spring-reactive-modules/spring-reactive-client/src/test/resources/logback-test.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/resources/logback-test.xml rename to spring-reactive-modules/spring-reactive-client/src/test/resources/logback-test.xml diff --git a/spring-reactive-modules/spring-5-data-reactive-2/README.md b/spring-reactive-modules/spring-reactive-data-2/README.md similarity index 80% rename from spring-reactive-modules/spring-5-data-reactive-2/README.md rename to spring-reactive-modules/spring-reactive-data-2/README.md index ffc664b8af..c13171cbc6 100644 --- a/spring-reactive-modules/spring-5-data-reactive-2/README.md +++ b/spring-reactive-modules/spring-reactive-data-2/README.md @@ -1,6 +1,6 @@ ## Spring Data Reactive Project -This module contains articles about reactive Spring 5 Data +This module contains articles about reactive Spring Boot Data ### The Course diff --git a/spring-reactive-modules/spring-5-data-reactive-2/pom.xml b/spring-reactive-modules/spring-reactive-data-2/pom.xml similarity index 85% rename from spring-reactive-modules/spring-5-data-reactive-2/pom.xml rename to spring-reactive-modules/spring-reactive-data-2/pom.xml index 3d88e672eb..64ce278973 100644 --- a/spring-reactive-modules/spring-5-data-reactive-2/pom.xml +++ b/spring-reactive-modules/spring-reactive-data-2/pom.xml @@ -3,8 +3,8 @@ 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"> 4.0.0 - spring-5-data-reactive-2 - spring-5-data-reactive-2 + spring-reactive-data-2 + spring-reactive-data-2 jar @@ -14,8 +14,6 @@ - 8 - 8 UTF-8 @@ -56,11 +54,6 @@ lombok true - - org.springframework.boot - spring-boot-starter-test - test - io.projectreactor reactor-test diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/PaginationApplication.java b/spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/PaginationApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/PaginationApplication.java rename to spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/PaginationApplication.java diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/config/CustomWebMvcConfigurationSupport.java b/spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/config/CustomWebMvcConfigurationSupport.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/config/CustomWebMvcConfigurationSupport.java rename to spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/config/CustomWebMvcConfigurationSupport.java diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/config/DatabaseConfig.java b/spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/config/DatabaseConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/config/DatabaseConfig.java rename to spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/config/DatabaseConfig.java diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/controller/ProductPaginationController.java b/spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/controller/ProductPaginationController.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/controller/ProductPaginationController.java rename to spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/controller/ProductPaginationController.java diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/model/Product.java b/spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/model/Product.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/model/Product.java rename to spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/model/Product.java diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/repository/ProductRepository.java b/spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/repository/ProductRepository.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/repository/ProductRepository.java rename to spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/repository/ProductRepository.java diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/resources/application.properties b/spring-reactive-modules/spring-reactive-data-2/src/main/resources/application.properties similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/resources/application.properties rename to spring-reactive-modules/spring-reactive-data-2/src/main/resources/application.properties diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/resources/init.sql b/spring-reactive-modules/spring-reactive-data-2/src/main/resources/init.sql similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/resources/init.sql rename to spring-reactive-modules/spring-reactive-data-2/src/main/resources/init.sql diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/test/java/com/baeldung/pagination/controller/ProductPaginationControllerIntegrationTest.java b/spring-reactive-modules/spring-reactive-data-2/src/test/java/com/baeldung/pagination/controller/ProductPaginationControllerIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/test/java/com/baeldung/pagination/controller/ProductPaginationControllerIntegrationTest.java rename to spring-reactive-modules/spring-reactive-data-2/src/test/java/com/baeldung/pagination/controller/ProductPaginationControllerIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-data-reactive/README.md b/spring-reactive-modules/spring-reactive-data/README.md similarity index 77% rename from spring-reactive-modules/spring-5-data-reactive/README.md rename to spring-reactive-modules/spring-reactive-data/README.md index 3522d9681b..cafd0c502f 100644 --- a/spring-reactive-modules/spring-5-data-reactive/README.md +++ b/spring-reactive-modules/spring-reactive-data/README.md @@ -1,6 +1,6 @@ ## Spring Data Reactive Project -This module contains articles about reactive Spring 5 Data +This module contains articles about reactive Spring Boot Data ### The Course The "REST With Spring" Classes: http://bit.ly/restwithspring diff --git a/spring-reactive-modules/spring-5-data-reactive/pom.xml b/spring-reactive-modules/spring-reactive-data/pom.xml similarity index 96% rename from spring-reactive-modules/spring-5-data-reactive/pom.xml rename to spring-reactive-modules/spring-reactive-data/pom.xml index dc4a5b9bd1..91c4dca6e8 100644 --- a/spring-reactive-modules/spring-5-data-reactive/pom.xml +++ b/spring-reactive-modules/spring-reactive-data/pom.xml @@ -3,8 +3,8 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - spring-5-data-reactive - spring-5-data-reactive + spring-reactive-data + spring-reactive-data jar diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/R2dbcApplication.java b/spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/R2dbcApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/R2dbcApplication.java rename to spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/R2dbcApplication.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/configuration/R2DBCConfiguration.java b/spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/configuration/R2DBCConfiguration.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/configuration/R2DBCConfiguration.java rename to spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/configuration/R2DBCConfiguration.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/model/Player.java b/spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/model/Player.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/model/Player.java rename to spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/model/Player.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/repository/PlayerRepository.java b/spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/repository/PlayerRepository.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/repository/PlayerRepository.java rename to spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/repository/PlayerRepository.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/resources/logback.xml b/spring-reactive-modules/spring-reactive-data/src/main/resources/logback.xml similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/resources/logback.xml rename to spring-reactive-modules/spring-reactive-data/src/main/resources/logback.xml diff --git a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/SpringContextTest.java b/spring-reactive-modules/spring-reactive-data/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/SpringContextTest.java rename to spring-reactive-modules/spring-reactive-data/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java b/spring-reactive-modules/spring-reactive-data/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java rename to spring-reactive-modules/spring-reactive-data/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive-exceptions/README.md b/spring-reactive-modules/spring-reactive-exceptions/README.md index fc1a31b26f..f7e2c8cae0 100644 --- a/spring-reactive-modules/spring-reactive-exceptions/README.md +++ b/spring-reactive-modules/spring-reactive-exceptions/README.md @@ -1,3 +1,4 @@ ## Relevant Articles - [How to Resolve Spring Webflux DataBufferLimitException](https://www.baeldung.com/spring-webflux-databufferlimitexception) - [Custom WebFlux Exceptions in Spring Boot 3](https://www.baeldung.com/spring-boot-custom-webflux-exceptions) +- [Handling Errors in Spring WebFlux](https://www.baeldung.com/spring-webflux-errors) \ No newline at end of file diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/ErrorHandlingApplication.java b/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/ErrorHandlingApplication.java similarity index 93% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/ErrorHandlingApplication.java rename to spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/ErrorHandlingApplication.java index 50579d8721..c34f86febd 100644 --- a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/ErrorHandlingApplication.java +++ b/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/ErrorHandlingApplication.java @@ -1,4 +1,4 @@ -package com.baeldung.reactive.errorhandling; +package com.baeldung.spring.reactive.errorhandling; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorAttributes.java b/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/GlobalErrorAttributes.java similarity index 93% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorAttributes.java rename to spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/GlobalErrorAttributes.java index 3458a175e4..9dce1b3e5b 100644 --- a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorAttributes.java +++ b/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/GlobalErrorAttributes.java @@ -1,4 +1,6 @@ -package com.baeldung.reactive.errorhandling; +package com.baeldung.spring.reactive.errorhandling; + +import java.util.Map; import org.springframework.boot.web.error.ErrorAttributeOptions; import org.springframework.boot.web.reactive.error.DefaultErrorAttributes; @@ -6,8 +8,6 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.server.ServerRequest; -import java.util.Map; - @Component public class GlobalErrorAttributes extends DefaultErrorAttributes { diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java b/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/GlobalErrorWebExceptionHandler.java similarity index 92% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java rename to spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/GlobalErrorWebExceptionHandler.java index 24583308cd..bfd3bba2a1 100644 --- a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java +++ b/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/GlobalErrorWebExceptionHandler.java @@ -1,4 +1,6 @@ -package com.baeldung.reactive.errorhandling; +package com.baeldung.spring.reactive.errorhandling; + +import java.util.Map; import org.springframework.boot.autoconfigure.web.WebProperties; import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler; @@ -16,15 +18,15 @@ import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerRequest; import org.springframework.web.reactive.function.server.ServerResponse; -import reactor.core.publisher.Mono; -import java.util.Map; +import reactor.core.publisher.Mono; @Component @Order(-2) public class GlobalErrorWebExceptionHandler extends AbstractErrorWebExceptionHandler { - public GlobalErrorWebExceptionHandler(GlobalErrorAttributes g, ApplicationContext applicationContext, + public GlobalErrorWebExceptionHandler( + GlobalErrorAttributes g, ApplicationContext applicationContext, ServerCodecConfigurer serverCodecConfigurer) { super(g, new WebProperties.Resources(), applicationContext); super.setMessageWriters(serverCodecConfigurer.getWriters()); diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Handler.java b/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/Handler.java similarity index 97% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Handler.java rename to spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/Handler.java index d49d9b4be2..2956cc1686 100644 --- a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Handler.java +++ b/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/Handler.java @@ -1,10 +1,11 @@ -package com.baeldung.reactive.errorhandling; +package com.baeldung.spring.reactive.errorhandling; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.server.ServerRequest; import org.springframework.web.reactive.function.server.ServerResponse; + import reactor.core.publisher.Mono; @Component diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/NameRequiredException.java b/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/NameRequiredException.java similarity index 85% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/NameRequiredException.java rename to spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/NameRequiredException.java index bdc7771b80..1926d6416a 100644 --- a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/NameRequiredException.java +++ b/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/NameRequiredException.java @@ -1,4 +1,4 @@ -package com.baeldung.reactive.errorhandling; +package com.baeldung.spring.reactive.errorhandling; import org.springframework.http.HttpStatus; import org.springframework.web.server.ResponseStatusException; diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Router.java b/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/Router.java similarity index 96% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Router.java rename to spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/Router.java index 5f130ec035..c65b645f09 100644 --- a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Router.java +++ b/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/Router.java @@ -1,4 +1,8 @@ -package com.baeldung.reactive.errorhandling; +package com.baeldung.spring.reactive.errorhandling; + +import static org.springframework.http.MediaType.TEXT_PLAIN; +import static org.springframework.web.reactive.function.server.RequestPredicates.GET; +import static org.springframework.web.reactive.function.server.RequestPredicates.accept; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; @@ -6,10 +10,6 @@ import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; -import static org.springframework.http.MediaType.TEXT_PLAIN; -import static org.springframework.web.reactive.function.server.RequestPredicates.GET; -import static org.springframework.web.reactive.function.server.RequestPredicates.accept; - @Component public class Router { diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/errorhandling/ErrorHandlingIntegrationTest.java b/spring-reactive-modules/spring-reactive-exceptions/src/test/java/com/baeldung/spring/reactive/errorhandling/ErrorHandlingIntegrationTest.java similarity index 98% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/errorhandling/ErrorHandlingIntegrationTest.java rename to spring-reactive-modules/spring-reactive-exceptions/src/test/java/com/baeldung/spring/reactive/errorhandling/ErrorHandlingIntegrationTest.java index 0068379d61..972eefa5ac 100644 --- a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/errorhandling/ErrorHandlingIntegrationTest.java +++ b/spring-reactive-modules/spring-reactive-exceptions/src/test/java/com/baeldung/spring/reactive/errorhandling/ErrorHandlingIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.reactive.errorhandling; +package com.baeldung.spring.reactive.errorhandling; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-reactive-modules/spring-5-reactive-filters/.gitignore b/spring-reactive-modules/spring-reactive-filters/.gitignore similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/.gitignore rename to spring-reactive-modules/spring-reactive-filters/.gitignore diff --git a/spring-reactive-modules/spring-5-reactive-filters/README.md b/spring-reactive-modules/spring-reactive-filters/README.md similarity index 76% rename from spring-reactive-modules/spring-5-reactive-filters/README.md rename to spring-reactive-modules/spring-reactive-filters/README.md index 815ca35442..9d73eae9ee 100644 --- a/spring-reactive-modules/spring-5-reactive-filters/README.md +++ b/spring-reactive-modules/spring-reactive-filters/README.md @@ -8,3 +8,4 @@ The "REST With Spring" Classes: https://bit.ly/restwithspring ### Relevant Articles - [Spring WebFlux Filters](https://www.baeldung.com/spring-webflux-filters) +- [Spring WebClient Filters](https://www.baeldung.com/spring-webclient-filters) diff --git a/spring-reactive-modules/spring-5-reactive-filters/pom.xml b/spring-reactive-modules/spring-reactive-filters/pom.xml similarity index 81% rename from spring-reactive-modules/spring-5-reactive-filters/pom.xml rename to spring-reactive-modules/spring-reactive-filters/pom.xml index c9503d631a..67f7a11cb4 100644 --- a/spring-reactive-modules/spring-5-reactive-filters/pom.xml +++ b/spring-reactive-modules/spring-reactive-filters/pom.xml @@ -3,11 +3,11 @@ 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"> 4.0.0 - spring-5-reactive-filters + spring-reactive-filters 0.0.1-SNAPSHOT - spring-5-reactive-filters + spring-reactive-filters jar - spring 5 sample project about new features + spring boot sample project about new features com.baeldung.spring.reactive @@ -49,6 +49,12 @@ netty-all test + + com.github.tomakehurst + wiremock-standalone + ${wiremock-standalone.version} + test + @@ -65,4 +71,8 @@ + + 2.26.0 + + \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/Spring5ReactiveFiltersApplication.java b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/Spring5ReactiveFiltersApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/Spring5ReactiveFiltersApplication.java rename to spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/Spring5ReactiveFiltersApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleHandlerFilterFunction.java b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleHandlerFilterFunction.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleHandlerFilterFunction.java rename to spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleHandlerFilterFunction.java diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleWebFilter.java b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleWebFilter.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleWebFilter.java rename to spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleWebFilter.java diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerHandler.java b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerHandler.java rename to spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerRouter.java b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerRouter.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerRouter.java rename to spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerRouter.java diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/UserController.java b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/UserController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/UserController.java rename to spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/UserController.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/filter/WebClientFilters.java b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/WebClientFilters.java similarity index 98% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/filter/WebClientFilters.java rename to spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/WebClientFilters.java index c98caf67b4..34fff3c4cb 100644 --- a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/filter/WebClientFilters.java +++ b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/WebClientFilters.java @@ -1,4 +1,4 @@ -package com.baeldung.webclient.filter; +package com.baeldung.reactive.filters; import java.io.PrintStream; import java.net.URI; diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/resources/application.properties b/spring-reactive-modules/spring-reactive-filters/src/main/resources/application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/resources/application.properties rename to spring-reactive-modules/spring-reactive-filters/src/main/resources/application.properties diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/resources/logback.xml b/spring-reactive-modules/spring-reactive-filters/src/main/resources/logback.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/resources/logback.xml rename to spring-reactive-modules/spring-reactive-filters/src/main/resources/logback.xml diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/test/java/com/baeldung/SpringContextTest.java b/spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/test/java/com/baeldung/SpringContextTest.java rename to spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/filter/FilteredWebClientUnitTest.java b/spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/reactive/filters/FilteredWebClientUnitTest.java similarity index 95% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/filter/FilteredWebClientUnitTest.java rename to spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/reactive/filters/FilteredWebClientUnitTest.java index 675cd03d10..1350db0752 100644 --- a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/filter/FilteredWebClientUnitTest.java +++ b/spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/reactive/filters/FilteredWebClientUnitTest.java @@ -1,8 +1,8 @@ -package com.baeldung.webclient.filter; +package com.baeldung.reactive.filters; -import static com.baeldung.webclient.filter.WebClientFilters.countingFilter; -import static com.baeldung.webclient.filter.WebClientFilters.loggingFilter; -import static com.baeldung.webclient.filter.WebClientFilters.urlModifyingFilter; +import static com.baeldung.reactive.filters.WebClientFilters.countingFilter; +import static com.baeldung.reactive.filters.WebClientFilters.loggingFilter; +import static com.baeldung.reactive.filters.WebClientFilters.urlModifyingFilter; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.containing; import static com.github.tomakehurst.wiremock.client.WireMock.get; diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/test/java/com/baeldung/reactive/filters/PlayerHandlerIntegrationTest.java b/spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/reactive/filters/PlayerHandlerIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/test/java/com/baeldung/reactive/filters/PlayerHandlerIntegrationTest.java rename to spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/reactive/filters/PlayerHandlerIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/test/java/com/baeldung/reactive/filters/UserControllerIntegrationTest.java b/spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/reactive/filters/UserControllerIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/test/java/com/baeldung/reactive/filters/UserControllerIntegrationTest.java rename to spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/reactive/filters/UserControllerIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/README.md b/spring-reactive-modules/spring-reactive-oauth/README.md similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/README.md rename to spring-reactive-modules/spring-reactive-oauth/README.md diff --git a/spring-reactive-modules/spring-5-reactive-oauth/pom.xml b/spring-reactive-modules/spring-reactive-oauth/pom.xml similarity index 96% rename from spring-reactive-modules/spring-5-reactive-oauth/pom.xml rename to spring-reactive-modules/spring-reactive-oauth/pom.xml index 9c237607ba..9d2dbf6126 100644 --- a/spring-reactive-modules/spring-5-reactive-oauth/pom.xml +++ b/spring-reactive-modules/spring-reactive-oauth/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.baeldung.reactive.oauth - spring-5-reactive-oauth + spring-reactive-oauth 1.0.0-SNAPSHOT - spring-5-reactive-oauth + spring-reactive-oauth jar WebFlux and Spring Security OAuth diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/SecurityConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/SecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/SecurityConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/SecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthApplication.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthApplication.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/MainController.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/MainController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/MainController.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/MainController.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/dto/Foo.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/dto/Foo.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/dto/Foo.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/dto/Foo.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/OauthClientApplication.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/OauthClientApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/OauthClientApplication.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/OauthClientApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebClientConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebClientConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebClientConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebClientConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebSecurityConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebSecurityConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebSecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/web/ClientRestController.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/web/ClientRestController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/web/ClientRestController.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/web/ClientRestController.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/OauthClientLoginApplication.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/OauthClientLoginApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/OauthClientLoginApplication.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/OauthClientLoginApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebClientConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebClientConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebClientConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebClientConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebSecurityConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebSecurityConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebSecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/web/ClientRestController.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/web/ClientRestController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/web/ClientRestController.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/web/ClientRestController.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/ClientCredentialsOauthApplication.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/ClientCredentialsOauthApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/ClientCredentialsOauthApplication.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/ClientCredentialsOauthApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/configuration/WebClientConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/configuration/WebClientConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/configuration/WebClientConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/configuration/WebClientConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/service/WebClientChonJob.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/service/WebClientChonJob.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/service/WebClientChonJob.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/service/WebClientChonJob.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/ManualRequestApplication.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/ManualRequestApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/ManualRequestApplication.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/ManualRequestApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebClientConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebClientConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebClientConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebClientConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebSecurityConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebSecurityConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebSecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/web/ManualOauthRequestController.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/web/ManualOauthRequestController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/web/ManualOauthRequestController.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/web/ManualOauthRequestController.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/application.yml b/spring-reactive-modules/spring-reactive-oauth/src/main/resources/application.yml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/application.yml rename to spring-reactive-modules/spring-reactive-oauth/src/main/resources/application.yml diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/default-application.yml b/spring-reactive-modules/spring-reactive-oauth/src/main/resources/default-application.yml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/default-application.yml rename to spring-reactive-modules/spring-reactive-oauth/src/main/resources/default-application.yml diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-auth-code-client-application.properties b/spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-auth-code-client-application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-auth-code-client-application.properties rename to spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-auth-code-client-application.properties diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-auth-code-login-application.properties b/spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-auth-code-login-application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-auth-code-login-application.properties rename to spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-auth-code-login-application.properties diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-client-credentials-oauth-application.properties b/spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-client-credentials-oauth-application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-client-credentials-oauth-application.properties rename to spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-client-credentials-oauth-application.properties diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-manual-request-oauth-application.properties b/spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-manual-request-oauth-application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-manual-request-oauth-application.properties rename to spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-manual-request-oauth-application.properties diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthIntegrationTest.java b/spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthIntegrationTest.java rename to spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/webclient/clientcredentials/OAuth2ClientCredentialsLiveTest.java b/spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/webclient/clientcredentials/OAuth2ClientCredentialsLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/webclient/clientcredentials/OAuth2ClientCredentialsLiveTest.java rename to spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/webclient/clientcredentials/OAuth2ClientCredentialsLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/webclient/manualrequest/OAuth2ManualRequestLiveTest.java b/spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/webclient/manualrequest/OAuth2ManualRequestLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/webclient/manualrequest/OAuth2ManualRequestLiveTest.java rename to spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/webclient/manualrequest/OAuth2ManualRequestLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/webclient/utils/ListAppender.java b/spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/webclient/utils/ListAppender.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/webclient/utils/ListAppender.java rename to spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/webclient/utils/ListAppender.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/test/resources/logback-test.xml b/spring-reactive-modules/spring-reactive-oauth/src/test/resources/logback-test.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/test/resources/logback-test.xml rename to spring-reactive-modules/spring-reactive-oauth/src/test/resources/logback-test.xml diff --git a/spring-reactive-modules/spring-5-reactive-security/.gitignore b/spring-reactive-modules/spring-reactive-security/.gitignore similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/.gitignore rename to spring-reactive-modules/spring-reactive-security/.gitignore diff --git a/spring-reactive-modules/spring-5-reactive-security/README.md b/spring-reactive-modules/spring-reactive-security/README.md similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/README.md rename to spring-reactive-modules/spring-reactive-security/README.md diff --git a/spring-reactive-modules/spring-5-reactive-security/pom.xml b/spring-reactive-modules/spring-reactive-security/pom.xml similarity index 93% rename from spring-reactive-modules/spring-5-reactive-security/pom.xml rename to spring-reactive-modules/spring-reactive-security/pom.xml index e455940d83..8ed976c572 100644 --- a/spring-reactive-modules/spring-5-reactive-security/pom.xml +++ b/spring-reactive-modules/spring-reactive-security/pom.xml @@ -3,11 +3,11 @@ 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"> 4.0.0 - spring-5-reactive-security + spring-reactive-security 0.0.1-SNAPSHOT - spring-5-reactive-security + spring-reactive-security jar - spring 5 security sample project about new features + spring boot security sample project about new features com.baeldung.spring.reactive @@ -66,10 +66,6 @@ spring-boot-devtools runtime - - org.springframework - spring-test - org.springframework.boot spring-boot-starter-test diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/DownstreamServiceHealthIndicator.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/DownstreamServiceHealthIndicator.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/DownstreamServiceHealthIndicator.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/DownstreamServiceHealthIndicator.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/FeaturesEndpoint.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/FeaturesEndpoint.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/FeaturesEndpoint.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/FeaturesEndpoint.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/InfoWebEndpointExtension.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/InfoWebEndpointExtension.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/InfoWebEndpointExtension.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/InfoWebEndpointExtension.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/Spring5ReactiveApplication.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/Spring5ReactiveApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/Spring5ReactiveApplication.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/Spring5ReactiveApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/WebSecurityConfig.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/WebSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/WebSecurityConfig.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/WebSecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverApplication.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverApplication.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverController.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverController.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverController.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/CustomWebSecurityConfig.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/authresolver/CustomWebSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/CustomWebSecurityConfig.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/authresolver/CustomWebSecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/CorsOnAnnotatedElementsApplication.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/CorsOnAnnotatedElementsApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/CorsOnAnnotatedElementsApplication.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/CorsOnAnnotatedElementsApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnClassController.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnClassController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnClassController.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnClassController.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnMethodsController.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnMethodsController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnMethodsController.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnMethodsController.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/CorsGlobalConfigApplication.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/CorsGlobalConfigApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/CorsGlobalConfigApplication.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/CorsGlobalConfigApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/config/CorsGlobalConfiguration.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/config/CorsGlobalConfiguration.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/config/CorsGlobalConfiguration.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/config/CorsGlobalConfiguration.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/FurtherCorsConfigsController.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/FurtherCorsConfigsController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/FurtherCorsConfigsController.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/FurtherCorsConfigsController.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/RegularRestController.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/RegularRestController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/RegularRestController.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/RegularRestController.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/handlers/CorsGlobalFunctionalHandler.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/handlers/CorsGlobalFunctionalHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/handlers/CorsGlobalFunctionalHandler.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/handlers/CorsGlobalFunctionalHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/routers/CorsRouterFunctions.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/routers/CorsRouterFunctions.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/routers/CorsRouterFunctions.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/routers/CorsRouterFunctions.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/CorsWebFilterApplication.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/CorsWebFilterApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/CorsWebFilterApplication.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/CorsWebFilterApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/config/CorsWebFilterConfig.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/config/CorsWebFilterConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/config/CorsWebFilterConfig.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/config/CorsWebFilterConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/FurtherCorsConfigsController.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/FurtherCorsConfigsController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/FurtherCorsConfigsController.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/FurtherCorsConfigsController.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/RegularRestController.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/RegularRestController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/RegularRestController.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/RegularRestController.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/handlers/CorsWithWebFilterHandler.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/handlers/CorsWithWebFilterHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/handlers/CorsWithWebFilterHandler.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/handlers/CorsWithWebFilterHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/routers/CorsWithWebFilterRouterFunctions.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/routers/CorsWithWebFilterRouterFunctions.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/routers/CorsWithWebFilterRouterFunctions.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/routers/CorsWithWebFilterRouterFunctions.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/Employee.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/Employee.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/Employee.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/Employee.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeConfig.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeConfig.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeCreationEvent.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeCreationEvent.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeCreationEvent.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeCreationEvent.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSecurityConfig.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSecurityConfig.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketClient.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketClient.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketClient.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketClient.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketHandler.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketHandler.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/resources/application.properties b/spring-reactive-modules/spring-reactive-security/src/main/resources/application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/resources/application.properties rename to spring-reactive-modules/spring-reactive-security/src/main/resources/application.properties diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/resources/files/hello.txt b/spring-reactive-modules/spring-reactive-security/src/main/resources/files/hello.txt similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/resources/files/hello.txt rename to spring-reactive-modules/spring-reactive-security/src/main/resources/files/hello.txt diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/resources/files/test/test.txt b/spring-reactive-modules/spring-reactive-security/src/main/resources/files/test/test.txt similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/resources/files/test/test.txt rename to spring-reactive-modules/spring-reactive-security/src/main/resources/files/test/test.txt diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/resources/logback.xml b/spring-reactive-modules/spring-reactive-security/src/main/resources/logback.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/resources/logback.xml rename to spring-reactive-modules/spring-reactive-security/src/main/resources/logback.xml diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/resources/static/client-websocket.html b/spring-reactive-modules/spring-reactive-security/src/main/resources/static/client-websocket.html similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/resources/static/client-websocket.html rename to spring-reactive-modules/spring-reactive-security/src/main/resources/static/client-websocket.html diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/webapp/WEB-INF/web.xml b/spring-reactive-modules/spring-reactive-security/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/webapp/WEB-INF/web.xml rename to spring-reactive-modules/spring-reactive-security/src/main/webapp/WEB-INF/web.xml diff --git a/spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/SpringContextTest.java b/spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/SpringContextTest.java rename to spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/actuator/ActuatorInfoIntegrationTest.java b/spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/actuator/ActuatorInfoIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/actuator/ActuatorInfoIntegrationTest.java rename to spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/actuator/ActuatorInfoIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/authresolver/AuthResolverIntegrationTest.java b/spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/authresolver/AuthResolverIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/authresolver/AuthResolverIntegrationTest.java rename to spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/authresolver/AuthResolverIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java b/spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java rename to spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java b/spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java rename to spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java b/spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java rename to spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/test/resources/baeldung-weekly.png b/spring-reactive-modules/spring-reactive-security/src/test/resources/baeldung-weekly.png similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/test/resources/baeldung-weekly.png rename to spring-reactive-modules/spring-reactive-security/src/test/resources/baeldung-weekly.png diff --git a/spring-reactive-modules/spring-reactive-webflux/README.md b/spring-reactive-modules/spring-reactive-webflux/README.md new file mode 100644 index 0000000000..d2b63b2186 --- /dev/null +++ b/spring-reactive-modules/spring-reactive-webflux/README.md @@ -0,0 +1,23 @@ +### Spring Reactive Articles that are also part of the e-book + +This module contains articles about Spring Reactive that are also part of an Ebook. + +## Spring Reactive + +This module contains articles describing reactive processing in Spring. + +## Relevant articles: + +- [Intro To Reactor Core](https://www.baeldung.com/reactor-core) +- [Debugging Reactive Streams in Java](https://www.baeldung.com/spring-debugging-reactive-streams) +- [Guide to Spring 5 WebFlux](https://www.baeldung.com/spring-webflux) +- [Introduction to the Functional Web Framework in Spring 5](https://www.baeldung.com/spring-5-functional-web) +- [Spring 5 WebClient](https://www.baeldung.com/spring-5-webclient) +- [Spring WebClient vs. RestTemplate](https://www.baeldung.com/spring-webclient-resttemplate) +- [Spring WebClient Requests with Parameters](https://www.baeldung.com/webflux-webclient-parameters) +- [Spring Security 5 for Reactive Applications](https://www.baeldung.com/spring-security-5-reactive) +- [Concurrency in Spring WebFlux](https://www.baeldung.com/spring-webflux-concurrency) + +### NOTE: + +Since this is a module tied to an e-book, it should **not** be moved or used to store the code for any further article. diff --git a/spring-reactive-modules/spring-reactive-webflux/pom.xml b/spring-reactive-modules/spring-reactive-webflux/pom.xml new file mode 100644 index 0000000000..cecaeff20c --- /dev/null +++ b/spring-reactive-modules/spring-reactive-webflux/pom.xml @@ -0,0 +1,112 @@ + + + 4.0.0 + spring-reactive-webflux + + + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 + + + + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-security + + + io.reactivex.rxjava2 + rxjava + ${rxjava.version} + + + io.projectreactor.kafka + reactor-kafka + ${reactor-kafka.version} + + + org.springframework.boot + spring-boot-starter-data-mongodb-reactive + + + org.springframework.security + spring-security-test + test + + + io.projectreactor + reactor-test + ${reactor.version} + test + + + org.projectlombok + lombok + + + + + + integration-lite-first + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${project.basedir}/src/test/resources/logback-test.xml + + + + + + + + integration-lite-second + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${project.basedir}/src/test/resources/logback-test.xml + + + + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + + 3.4.16 + 1.3.10 + 2.2.21 + + + \ No newline at end of file diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/Application.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/Application.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/Application.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/Application.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/Controller.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/Controller.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/Controller.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/Controller.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/Person.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/Person.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/Person.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/Person.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/PersonRepository.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/PersonRepository.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/PersonRepository.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/PersonRepository.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/ConsumerDebuggingApplication.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/ConsumerDebuggingApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/ConsumerDebuggingApplication.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/ConsumerDebuggingApplication.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/controllers/ReactiveConfigsToggleRestController.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/controllers/ReactiveConfigsToggleRestController.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/controllers/ReactiveConfigsToggleRestController.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/controllers/ReactiveConfigsToggleRestController.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/cronjobs/CronJobs.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/cronjobs/CronJobs.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/cronjobs/CronJobs.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/cronjobs/CronJobs.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/model/Foo.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/model/Foo.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/model/Foo.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/model/Foo.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/model/FooDto.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/model/FooDto.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/model/FooDto.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/model/FooDto.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooNameHelper.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooNameHelper.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooNameHelper.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooNameHelper.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooQuantityHelper.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooQuantityHelper.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooQuantityHelper.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooQuantityHelper.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooReporter.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooReporter.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooReporter.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooReporter.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooService.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooService.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooService.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooService.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/ServerDebuggingApplication.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/ServerDebuggingApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/ServerDebuggingApplication.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/ServerDebuggingApplication.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/handlers/ServerHandler.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/handlers/ServerHandler.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/handlers/ServerHandler.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/handlers/ServerHandler.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/model/Foo.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/model/Foo.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/model/Foo.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/model/Foo.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/routers/ServerRouter.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/routers/ServerRouter.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/routers/ServerRouter.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/routers/ServerRouter.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/GreetingController.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/GreetingController.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/GreetingController.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/GreetingController.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/GreetingService.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/GreetingService.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/GreetingService.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/GreetingService.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/SecurityConfig.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/SecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/SecurityConfig.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/SecurityConfig.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/SpringSecurity6Application.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/SpringSecurity6Application.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/SpringSecurity6Application.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/SpringSecurity6Application.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/Foo.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/Foo.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/Foo.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/Foo.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/Tweet.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/Tweet.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/Tweet.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/Tweet.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/TweetsSlowServiceController.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/TweetsSlowServiceController.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/TweetsSlowServiceController.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/TweetsSlowServiceController.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/WebClientApplication.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/WebClientApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/WebClientApplication.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/WebClientApplication.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/WebClientController.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/WebClientController.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/WebClientController.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/WebClientController.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/WebController.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/WebController.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/WebController.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/WebController.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclientrequests/SpringWebClientRequestsApp.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclientrequests/SpringWebClientRequestsApp.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclientrequests/SpringWebClientRequestsApp.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclientrequests/SpringWebClientRequestsApp.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/Employee.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/Employee.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/Employee.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/Employee.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/EmployeeRepository.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/EmployeeRepository.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/EmployeeRepository.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/EmployeeRepository.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeController.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeController.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeController.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeController.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeSpringApplication.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeSpringApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeSpringApplication.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeSpringApplication.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebClient.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebClient.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebClient.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebClient.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebSecurityConfig.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebSecurityConfig.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebSecurityConfig.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeFunctionalConfig.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeFunctionalConfig.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeFunctionalConfig.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeFunctionalConfig.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalApplication.java b/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalApplication.java rename to spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalApplication.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceIntegrationTest.java b/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceIntegrationTest.java rename to spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceLiveTest.java b/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceLiveTest.java rename to spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceLiveTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/debugging/consumer/utils/ListAppender.java b/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/debugging/consumer/utils/ListAppender.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/debugging/consumer/utils/ListAppender.java rename to spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/debugging/consumer/utils/ListAppender.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/introduction/ReactorIntegrationTest.java b/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/introduction/ReactorIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/introduction/ReactorIntegrationTest.java rename to spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/introduction/ReactorIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/security/SecurityIntegrationTest.java b/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/security/SecurityIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/security/SecurityIntegrationTest.java rename to spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/security/SecurityIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/SpringContextTest.java b/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/SpringContextTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/SpringContextTest.java rename to spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/SpringContextTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebClientIntegrationTest.java b/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/WebClientIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebClientIntegrationTest.java rename to spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/WebClientIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebControllerIntegrationTest.java b/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/WebControllerIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebControllerIntegrationTest.java rename to spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/WebControllerIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebTestClientIntegrationTest.java b/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/WebTestClientIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebTestClientIntegrationTest.java rename to spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/WebTestClientIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclientrequests/WebClientRequestsWithParametersUnitTest.java b/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclientrequests/WebClientRequestsWithParametersUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclientrequests/WebClientRequestsWithParametersUnitTest.java rename to spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclientrequests/WebClientRequestsWithParametersUnitTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webflux/annotation/EmployeeControllerIntegrationTest.java b/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webflux/annotation/EmployeeControllerIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webflux/annotation/EmployeeControllerIntegrationTest.java rename to spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webflux/annotation/EmployeeControllerIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalIntegrationTest.java b/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalIntegrationTest.java rename to spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/resources/logback-test.xml b/spring-reactive-modules/spring-reactive-webflux/src/test/resources/logback-test.xml similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/resources/logback-test.xml rename to spring-reactive-modules/spring-reactive-webflux/src/test/resources/logback-test.xml diff --git a/spring-reactive-modules/spring-5-reactive/.gitignore b/spring-reactive-modules/spring-reactive/.gitignore similarity index 100% rename from spring-reactive-modules/spring-5-reactive/.gitignore rename to spring-reactive-modules/spring-reactive/.gitignore diff --git a/spring-reactive-modules/spring-reactive/README.md b/spring-reactive-modules/spring-reactive/README.md index 7dfc7b2952..f3148fe696 100644 --- a/spring-reactive-modules/spring-reactive/README.md +++ b/spring-reactive-modules/spring-reactive/README.md @@ -1,24 +1,14 @@ -### Spring Reactive Articles that are also part of the e-book +## Spring 5 Reactive Project -This module contains articles about Spring Reactive that are also part of an Ebook. +This module contains articles about reactive Spring 5 -## Spring Reactive +### The Course +The "REST With Spring" Classes: https://bit.ly/restwithspring -This module contains articles describing reactive processing in Spring. +### Relevant Articles -## Relevant articles: - -- [Intro To Reactor Core](https://www.baeldung.com/reactor-core) -- [Debugging Reactive Streams in Java](https://www.baeldung.com/spring-debugging-reactive-streams) -- [Guide to Spring 5 WebFlux](https://www.baeldung.com/spring-webflux) -- [Introduction to the Functional Web Framework in Spring 5](https://www.baeldung.com/spring-5-functional-web) -- [Spring 5 WebClient](https://www.baeldung.com/spring-5-webclient) -- [Spring WebClient vs. RestTemplate](https://www.baeldung.com/spring-webclient-resttemplate) -- [Spring WebClient Requests with Parameters](https://www.baeldung.com/webflux-webclient-parameters) -- [Handling Errors in Spring WebFlux](https://www.baeldung.com/spring-webflux-errors) -- [Spring Security 5 for Reactive Applications](https://www.baeldung.com/spring-security-5-reactive) -- [Concurrency in Spring WebFlux](https://www.baeldung.com/spring-webflux-concurrency) - -### NOTE: - -Since this is a module tied to an e-book, it should **not** be moved or used to store the code for any further article. +- [Exploring the Spring 5 WebFlux URL Matching](https://www.baeldung.com/spring-5-mvc-url-matching) +- [Reactive WebSockets with Spring 5](https://www.baeldung.com/spring-5-reactive-websockets) +- [How to Set a Header on a Response with Spring 5](https://www.baeldung.com/spring-response-header) +- [A Guide to Spring Session Reactive Support: WebSession](https://www.baeldung.com/spring-session-reactive) +- More articles: [[next -->]](../spring-5-reactive-2) diff --git a/spring-reactive-modules/spring-reactive/pom.xml b/spring-reactive-modules/spring-reactive/pom.xml index f19809e302..f843e04c7b 100644 --- a/spring-reactive-modules/spring-reactive/pom.xml +++ b/spring-reactive-modules/spring-reactive/pom.xml @@ -4,40 +4,71 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-reactive + 0.0.1-SNAPSHOT + spring-5-reactive + jar + spring 5 sample project about new features - com.baeldung - parent-boot-3 - 0.0.1-SNAPSHOT - ../../parent-boot-3 + com.baeldung.spring.reactive + spring-reactive-modules + 1.0.0-SNAPSHOT - - org.springframework.boot - spring-boot-starter-webflux - org.springframework.boot spring-boot-starter-validation org.springframework.boot - spring-boot-starter-security - - - io.reactivex.rxjava2 - rxjava - ${rxjava.version} - - - io.projectreactor.kafka - reactor-kafka - ${reactor-kafka.version} + spring-boot-starter-tomcat org.springframework.boot - spring-boot-starter-data-mongodb-reactive + spring-boot-starter-integration + + + org.springframework.boot + spring-boot-starter-websocket + + + javax.json.bind + javax.json.bind-api + + + org.projectlombok + lombok + compile + + + org.apache.geronimo.specs + geronimo-json_1.1_spec + ${geronimo-json_1.1_spec.version} + + + org.apache.johnzon + johnzon-jsonb + + + + org.apache.commons + commons-lang3 + + + + org.springframework.boot + spring-boot-devtools + runtime + + + org.springframework + spring-test + + + org.springframework.boot + spring-boot-starter-test + test org.springframework.security @@ -47,66 +78,88 @@ io.projectreactor reactor-test - ${reactor.version} + test + + + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.session + spring-session-core + + + org.springframework.session + spring-session-data-redis + + + org.apache.commons + commons-collections4 + ${commons-collections4.version} test - org.projectlombok - lombok + io.reactivex.rxjava2 + rxjava + + + org.apache.httpcomponents + httpclient + + + io.netty + netty-all - - - integration-lite-first - - - - org.apache.maven.plugins - maven-surefire-plugin - - - ${project.basedir}/src/test/resources/logback-test.xml - - - - - - - - integration-lite-second - - - - org.apache.maven.plugins - maven-surefire-plugin - - - ${project.basedir}/src/test/resources/logback-test.xml - - - - - - - - + + maven-resources-plugin + 3.0.1 + + + copy-resources + validate + + copy-resources + + + + + src/main/assets + true + + + ${basedir}/target/classes/assets + + + + org.springframework.boot spring-boot-maven-plugin - true + com.baeldung.reactive.Spring5ReactiveApplication + JAR - 3.4.16 - 1.3.10 - 2.2.21 + 1.1.3 + 1.0 + 1.0 \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-reactive/src/main/assets/index.html b/spring-reactive-modules/spring-reactive/src/main/assets/index.html similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/assets/index.html rename to spring-reactive-modules/spring-reactive/src/main/assets/index.html diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/Actor.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/Actor.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/Actor.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/Actor.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/FormHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/FormHandler.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/RootServlet.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/RootServlet.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/PathPatternController.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/controller/PathPatternController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/PathPatternController.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/controller/PathPatternController.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/model/Foo.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/model/Foo.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/model/Foo.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/model/Foo.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/controllers/ResponseHeaderController.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/controllers/ResponseHeaderController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/controllers/ResponseHeaderController.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/controllers/ResponseHeaderController.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/filter/AddResponseHeaderWebFilter.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/filter/AddResponseHeaderWebFilter.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/filter/AddResponseHeaderWebFilter.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/filter/AddResponseHeaderWebFilter.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/handlers/ResponseHeaderHandler.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/handlers/ResponseHeaderHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/handlers/ResponseHeaderHandler.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/handlers/ResponseHeaderHandler.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/routers/ResponseHeadersRouterFunctions.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/routers/ResponseHeadersRouterFunctions.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/routers/ResponseHeadersRouterFunctions.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/routers/ResponseHeadersRouterFunctions.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/Actor.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/Actor.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/Actor.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/Actor.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FunctionalWebApplication.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/FunctionalWebApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FunctionalWebApplication.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/FunctionalWebApplication.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/IndexRewriteFilter.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/IndexRewriteFilter.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/IndexRewriteFilter.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/IndexRewriteFilter.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/util/CpuUtils.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/util/CpuUtils.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/util/CpuUtils.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/util/CpuUtils.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/Application.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/Application.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/Application.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/Application.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/RedisConfig.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/RedisConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/RedisConfig.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/RedisConfig.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/SessionConfig.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/SessionConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/SessionConfig.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/SessionConfig.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxConfig.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxConfig.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxConfig.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxSecurityConfig.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxSecurityConfig.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxSecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/controller/SessionController.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/controller/SessionController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/controller/SessionController.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/controller/SessionController.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/transfer/CustomResponse.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/transfer/CustomResponse.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/transfer/CustomResponse.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/transfer/CustomResponse.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/Event.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/Event.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/Event.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/Event.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveJavaClientWebSocket.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveJavaClientWebSocket.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveJavaClientWebSocket.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveJavaClientWebSocket.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketApplication.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketApplication.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketApplication.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketConfiguration.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketConfiguration.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketConfiguration.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketConfiguration.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketHandler.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketHandler.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketHandler.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/WebSocketController.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/WebSocketController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/WebSocketController.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/WebSocketController.java diff --git a/spring-reactive-modules/spring-5-reactive/src/main/resources/application.properties b/spring-reactive-modules/spring-reactive/src/main/resources/application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/resources/application.properties rename to spring-reactive-modules/spring-reactive/src/main/resources/application.properties diff --git a/spring-reactive-modules/spring-5-reactive/src/main/resources/files/hello.txt b/spring-reactive-modules/spring-reactive/src/main/resources/files/hello.txt similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/resources/files/hello.txt rename to spring-reactive-modules/spring-reactive/src/main/resources/files/hello.txt diff --git a/spring-reactive-modules/spring-5-reactive/src/main/resources/files/test/test.txt b/spring-reactive-modules/spring-reactive/src/main/resources/files/test/test.txt similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/resources/files/test/test.txt rename to spring-reactive-modules/spring-reactive/src/main/resources/files/test/test.txt diff --git a/spring-reactive-modules/spring-5-reactive/src/main/resources/logback.xml b/spring-reactive-modules/spring-reactive/src/main/resources/logback.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/resources/logback.xml rename to spring-reactive-modules/spring-reactive/src/main/resources/logback.xml diff --git a/spring-reactive-modules/spring-5-reactive/src/main/resources/resources/test/test.txt b/spring-reactive-modules/spring-reactive/src/main/resources/resources/test/test.txt similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/resources/resources/test/test.txt rename to spring-reactive-modules/spring-reactive/src/main/resources/resources/test/test.txt diff --git a/spring-reactive-modules/spring-5-reactive/src/main/resources/static/client-websocket.html b/spring-reactive-modules/spring-reactive/src/main/resources/static/client-websocket.html similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/resources/static/client-websocket.html rename to spring-reactive-modules/spring-reactive/src/main/resources/static/client-websocket.html diff --git a/spring-reactive-modules/spring-5-reactive/src/main/webapp/WEB-INF/web.xml b/spring-reactive-modules/spring-reactive/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/webapp/WEB-INF/web.xml rename to spring-reactive-modules/spring-reactive/src/main/webapp/WEB-INF/web.xml diff --git a/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/SpringContextTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/SpringContextTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/responseheaders/ResponseHeaderLiveTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/responseheaders/ResponseHeaderLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/responseheaders/ResponseHeaderLiveTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/responseheaders/ResponseHeaderLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive/src/test/resources/baeldung-weekly.png b/spring-reactive-modules/spring-reactive/src/test/resources/baeldung-weekly.png similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/test/resources/baeldung-weekly.png rename to spring-reactive-modules/spring-reactive/src/test/resources/baeldung-weekly.png diff --git a/spring-reactive-modules/spring-reactor/pom.xml b/spring-reactive-modules/spring-reactor/pom.xml index 22eaa898bd..c2635765f0 100644 --- a/spring-reactive-modules/spring-reactor/pom.xml +++ b/spring-reactive-modules/spring-reactor/pom.xml @@ -37,7 +37,6 @@ - 2.0.2.RELEASE 2.0.8.RELEASE From e1ef148a3756bde4587d27b0497788a2373c646c Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Mon, 25 Sep 2023 06:54:17 +0300 Subject: [PATCH 075/193] [JAVA-19576] Initial commit (#14756) * [JAVA-19576] Initial commit * [JAVA-19576] Clean up * [JAVA-19576] Clean up * [JAVA-19576] Clean up --- persistence-modules/pom.xml | 1 + .../spring-hibernate-5/README.md | 3 - .../hibernate/bootstrap/HibernateXMLConf.java | 24 ---- .../DynamicUpdateIntegrationTest.java | 44 ------- .../spring-hibernate-6/.gitignore | 13 +++ .../spring-hibernate-6/README.md | 9 ++ .../spring-hibernate-6/pom.xml | 109 ++++++++++++++++++ .../hibernate/bootstrap/BarHibernateDAO.java | 0 .../hibernate/bootstrap/HibernateConf.java | 0 .../hibernate/bootstrap/HibernateXMLConf.java | 12 ++ .../hibernate/bootstrap/model/TestEntity.java | 4 +- .../dynamicupdate/AccountRepository.java | 0 .../dynamicupdate/DynamicUpdateConfig.java | 2 +- .../dynamicupdate/model/Account.java | 6 +- .../com/baeldung/persistence/dao/IFooDao.java | 8 ++ .../persistence/dao/common/AbstractDao.java | 14 +++ .../dao/common/AbstractHibernateDao.java | 59 ++++++++++ .../persistence/dao/common/IOperations.java | 20 ++++ .../persistence/dao/impl/FooHibernateDao.java | 19 +++ .../com/baeldung/persistence/model/Foo.java | 73 ++++++++++++ .../baeldung/spring/PersistenceConfig.java | 82 +++++++++++++ .../baeldung/spring/PersistenceXmlConfig.java | 14 +++ .../src/main/resources/hibernate6Config.xml | 34 ++++++ .../resources/hibernate6Configuration.xml | 30 +++++ .../src/main/resources/logback.xml | 19 +++ .../main/resources/persistence-h2.properties | 22 ++++ .../resources/persistence-jndi.properties | 8 ++ .../resources/persistence-mysql.properties | 13 +++ .../java/com/baeldung/SpringContextTest.java | 19 +++ .../HibernateBootstrapIntegrationTest.java | 49 ++++---- .../HibernateXMLBootstrapIntegrationTest.java | 17 +-- .../DynamicUpdateIntegrationTest.java | 52 +++++++++ .../common/HibernateDaoIntegrationTest.java | 46 ++++++++ 33 files changed, 717 insertions(+), 108 deletions(-) delete mode 100644 persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/HibernateXMLConf.java delete mode 100644 persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateIntegrationTest.java create mode 100644 persistence-modules/spring-hibernate-6/.gitignore create mode 100644 persistence-modules/spring-hibernate-6/README.md create mode 100644 persistence-modules/spring-hibernate-6/pom.xml rename persistence-modules/{spring-hibernate-5 => spring-hibernate-6}/src/main/java/com/baeldung/hibernate/bootstrap/BarHibernateDAO.java (100%) rename persistence-modules/{spring-hibernate-5 => spring-hibernate-6}/src/main/java/com/baeldung/hibernate/bootstrap/HibernateConf.java (100%) create mode 100644 persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/HibernateXMLConf.java rename persistence-modules/{spring-hibernate-5 => spring-hibernate-6}/src/main/java/com/baeldung/hibernate/bootstrap/model/TestEntity.java (86%) rename persistence-modules/{spring-hibernate-5 => spring-hibernate-6}/src/main/java/com/baeldung/hibernate/dynamicupdate/AccountRepository.java (100%) rename persistence-modules/{spring-hibernate-5 => spring-hibernate-6}/src/main/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateConfig.java (98%) rename persistence-modules/{spring-hibernate-5 => spring-hibernate-6}/src/main/java/com/baeldung/hibernate/dynamicupdate/model/Account.java (94%) create mode 100644 persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/IFooDao.java create mode 100644 persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/AbstractDao.java create mode 100644 persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/AbstractHibernateDao.java create mode 100644 persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/IOperations.java create mode 100644 persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/impl/FooHibernateDao.java create mode 100644 persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/model/Foo.java create mode 100644 persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/spring/PersistenceConfig.java create mode 100644 persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/spring/PersistenceXmlConfig.java create mode 100644 persistence-modules/spring-hibernate-6/src/main/resources/hibernate6Config.xml create mode 100644 persistence-modules/spring-hibernate-6/src/main/resources/hibernate6Configuration.xml create mode 100644 persistence-modules/spring-hibernate-6/src/main/resources/logback.xml create mode 100644 persistence-modules/spring-hibernate-6/src/main/resources/persistence-h2.properties create mode 100644 persistence-modules/spring-hibernate-6/src/main/resources/persistence-jndi.properties create mode 100644 persistence-modules/spring-hibernate-6/src/main/resources/persistence-mysql.properties create mode 100644 persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/SpringContextTest.java rename persistence-modules/{spring-hibernate-5 => spring-hibernate-6}/src/test/java/com/baeldung/hibernate/bootstrap/HibernateBootstrapIntegrationTest.java (79%) rename persistence-modules/{spring-hibernate-5 => spring-hibernate-6}/src/test/java/com/baeldung/hibernate/bootstrap/HibernateXMLBootstrapIntegrationTest.java (65%) create mode 100644 persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateIntegrationTest.java create mode 100644 persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/persistence/dao/common/HibernateDaoIntegrationTest.java diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 73c6b96bba..ec63d5c56e 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -101,6 +101,7 @@ spring-data-shardingsphere + spring-hibernate-6 spring-jpa spring-jpa-2 spring-jdbc diff --git a/persistence-modules/spring-hibernate-5/README.md b/persistence-modules/spring-hibernate-5/README.md index e2344fd585..ce78e5a0df 100644 --- a/persistence-modules/spring-hibernate-5/README.md +++ b/persistence-modules/spring-hibernate-5/README.md @@ -4,10 +4,7 @@ This module contains articles about Hibernate 5 with Spring. ### Relevant articles -- [Programmatic Transactions in the Spring TestContext Framework](https://www.baeldung.com/spring-test-programmatic-transactions) - [Introduction to Hibernate Search](https://www.baeldung.com/hibernate-search) -- [@DynamicUpdate with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-dynamicupdate) - [Hibernate Second-Level Cache](http://www.baeldung.com/hibernate-second-level-cache) - [Deleting Objects with Hibernate](http://www.baeldung.com/delete-with-hibernate) - [Spring, Hibernate and a JNDI Datasource](http://www.baeldung.com/spring-persistence-jpa-jndi-datasource) -- [Bootstrapping Hibernate 5 with Spring](https://www.baeldung.com/hibernate-5-spring) diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/HibernateXMLConf.java b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/HibernateXMLConf.java deleted file mode 100644 index b3e979478f..0000000000 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/HibernateXMLConf.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.hibernate.bootstrap; - -import com.google.common.base.Preconditions; -import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; -import org.springframework.orm.hibernate5.HibernateTransactionManager; -import org.springframework.orm.hibernate5.LocalSessionFactoryBean; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -import javax.sql.DataSource; -import java.util.Properties; - -@Configuration -@EnableTransactionManagement -@ImportResource({ "classpath:hibernate5Configuration.xml" }) -public class HibernateXMLConf { - -} diff --git a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateIntegrationTest.java b/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateIntegrationTest.java deleted file mode 100644 index fc183d1f19..0000000000 --- a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateIntegrationTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.hibernate.dynamicupdate; - -import javax.transaction.Transactional; - -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.annotation.Commit; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.AnnotationConfigContextLoader; - -import com.baeldung.hibernate.dynamicupdate.model.Account; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = DynamicUpdateConfig.class, loader = AnnotationConfigContextLoader.class) -@Transactional -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class DynamicUpdateIntegrationTest { - - private static final Integer ACCOUNT_ID = 1; - - @Autowired - private AccountRepository accountRepository; - - @Test - @Commit - public void testA_whenTestAccountIsSaved_thenSuccess() { - Account account = new Account(ACCOUNT_ID, "account1", "regional", true); - accountRepository.save(account); - } - - @Test - @Commit - // Enable Hibernate's debug logging in logback.xml to see the generated SQL statement. - public void testB_whenAccountNameUpdated_thenSuccess() { - Account account = accountRepository.findOne(ACCOUNT_ID); - account.setName("Test Account"); - accountRepository.save(account); - } - -} diff --git a/persistence-modules/spring-hibernate-6/.gitignore b/persistence-modules/spring-hibernate-6/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/README.md b/persistence-modules/spring-hibernate-6/README.md new file mode 100644 index 0000000000..fad56e32d2 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/README.md @@ -0,0 +1,9 @@ +## Hibernate 5 with Spring + +This module contains articles about Hibernate 6 with Spring. + +### Relevant articles + +- [Programmatic Transactions in the Spring TestContext Framework](https://www.baeldung.com/spring-test-programmatic-transactions) +- [@DynamicUpdate with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-dynamicupdate) +- [Bootstrapping Hibernate 5 with Spring](https://www.baeldung.com/hibernate-5-spring) diff --git a/persistence-modules/spring-hibernate-6/pom.xml b/persistence-modules/spring-hibernate-6/pom.xml new file mode 100644 index 0000000000..a13117e68c --- /dev/null +++ b/persistence-modules/spring-hibernate-6/pom.xml @@ -0,0 +1,109 @@ + + + 4.0.0 + spring-hibernate-6 + 0.1-SNAPSHOT + spring-hibernate-6 + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + + org.springframework + spring-context + ${org.springframework.version} + + + commons-logging + commons-logging + + + + + org.springframework + spring-aspects + ${org.springframework.version} + + + + org.springframework + spring-orm + ${org.springframework.version} + + + org.springframework.data + spring-data-jpa + ${org.springframework.data.version} + + + org.hibernate.orm + hibernate-core + ${hibernate.version} + + + org.apache.tomcat + tomcat-dbcp + ${tomcat-dbcp.version} + + + + + com.google.guava + guava + ${guava.version} + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + test + + + org.springframework + spring-test + ${org.springframework.version} + test + + + org.springframework.security + spring-security-test + ${org.springframework.security.version} + test + + + org.hsqldb + hsqldb + ${hsqldb.version} + + + mysql + mysql-connector-java + ${mysql-connector-java.version} + + + com.h2database + h2 + ${h2.version} + + + + + + 6.0.11 + 3.1.3 + 6.1.3 + + 6.2.8.Final + 8.0.7-dmr + 9.0.80 + + + \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/BarHibernateDAO.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/BarHibernateDAO.java similarity index 100% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/BarHibernateDAO.java rename to persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/BarHibernateDAO.java diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/HibernateConf.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/HibernateConf.java similarity index 100% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/HibernateConf.java rename to persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/HibernateConf.java diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/HibernateXMLConf.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/HibernateXMLConf.java new file mode 100644 index 0000000000..220c18bccf --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/HibernateXMLConf.java @@ -0,0 +1,12 @@ +package com.baeldung.hibernate.bootstrap; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@EnableTransactionManagement +@ImportResource({ "classpath:hibernate6Configuration.xml" }) +public class HibernateXMLConf { + +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/model/TestEntity.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/model/TestEntity.java similarity index 86% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/model/TestEntity.java rename to persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/model/TestEntity.java index cae41db831..d260fed7a1 100644 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/model/TestEntity.java +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/model/TestEntity.java @@ -1,7 +1,7 @@ package com.baeldung.hibernate.bootstrap.model; -import javax.persistence.Entity; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; @Entity public class TestEntity { diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/AccountRepository.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/AccountRepository.java similarity index 100% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/AccountRepository.java rename to persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/AccountRepository.java diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateConfig.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateConfig.java similarity index 98% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateConfig.java rename to persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateConfig.java index 23e28a9e3b..766295f67a 100644 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateConfig.java +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateConfig.java @@ -2,7 +2,7 @@ package com.baeldung.hibernate.dynamicupdate; import java.util.Properties; -import javax.persistence.EntityManagerFactory; +import jakarta.persistence.EntityManagerFactory; import javax.sql.DataSource; import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/model/Account.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/model/Account.java similarity index 94% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/model/Account.java rename to persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/model/Account.java index b3753112fe..808ffe99ee 100644 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/model/Account.java +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/model/Account.java @@ -2,9 +2,9 @@ package com.baeldung.hibernate.dynamicupdate.model; import java.text.MessageFormat; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; import org.hibernate.annotations.DynamicUpdate; diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/IFooDao.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/IFooDao.java new file mode 100644 index 0000000000..0935772dbd --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/IFooDao.java @@ -0,0 +1,8 @@ +package com.baeldung.persistence.dao; + +import com.baeldung.persistence.model.Foo; +import com.baeldung.persistence.dao.common.IOperations; + +public interface IFooDao extends IOperations { + // +} diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/AbstractDao.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/AbstractDao.java new file mode 100644 index 0000000000..5a6c76a93a --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/AbstractDao.java @@ -0,0 +1,14 @@ +package com.baeldung.persistence.dao.common; + +import java.io.Serializable; + +import com.google.common.base.Preconditions; + +public abstract class AbstractDao implements IOperations { + + protected Class clazz; + + protected final void setClazz(final Class clazzToSet) { + clazz = Preconditions.checkNotNull(clazzToSet); + } +} diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/AbstractHibernateDao.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/AbstractHibernateDao.java new file mode 100644 index 0000000000..f34866d883 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/AbstractHibernateDao.java @@ -0,0 +1,59 @@ +package com.baeldung.persistence.dao.common; + +import java.io.Serializable; +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import com.google.common.base.Preconditions; + +@SuppressWarnings("unchecked") +public abstract class AbstractHibernateDao extends AbstractDao implements IOperations { + + @Autowired + protected SessionFactory sessionFactory; + + // API + + @Override + public T findOne(final long id) { + return (T) getCurrentSession().get(clazz, id); + } + + @Override + public List findAll() { + return getCurrentSession().createQuery("from " + clazz.getName()).getResultList(); + } + + @Override + public void create(final T entity) { + Preconditions.checkNotNull(entity); + getCurrentSession().saveOrUpdate(entity); + } + + @Override + public T update(final T entity) { + Preconditions.checkNotNull(entity); + return (T) getCurrentSession().merge(entity); + } + + @Override + public void delete(final T entity) { + Preconditions.checkNotNull(entity); + getCurrentSession().delete(entity); + } + + @Override + public void deleteById(final long entityId) { + final T entity = findOne(entityId); + Preconditions.checkState(entity != null); + delete(entity); + } + + protected Session getCurrentSession() { + return sessionFactory.getCurrentSession(); + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/IOperations.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/IOperations.java new file mode 100644 index 0000000000..4ef99221ab --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/IOperations.java @@ -0,0 +1,20 @@ +package com.baeldung.persistence.dao.common; + +import java.io.Serializable; +import java.util.List; + +public interface IOperations { + + T findOne(final long id); + + List findAll(); + + void create(final T entity); + + T update(final T entity); + + void delete(final T entity); + + void deleteById(final long entityId); + +} diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/impl/FooHibernateDao.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/impl/FooHibernateDao.java new file mode 100644 index 0000000000..5411073360 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/impl/FooHibernateDao.java @@ -0,0 +1,19 @@ +package com.baeldung.persistence.dao.impl; + +import com.baeldung.persistence.dao.common.AbstractHibernateDao; +import com.baeldung.persistence.dao.IFooDao; +import com.baeldung.persistence.model.Foo; +import org.springframework.stereotype.Repository; + +@Repository +public class FooHibernateDao extends AbstractHibernateDao implements IFooDao { + + public FooHibernateDao() { + super(); + + setClazz(Foo.class); + } + + // API + +} diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/model/Foo.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/model/Foo.java new file mode 100644 index 0000000000..c9a541290d --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/model/Foo.java @@ -0,0 +1,73 @@ +package com.baeldung.persistence.model; + +import jakarta.persistence.*; +import java.io.Serializable; + +@Entity +public class Foo implements Serializable{ + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private long id; + + @Column(name = "name") + private String name; + + public Foo() { + super(); + } + + public Foo(final String name) { + super(); + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(final long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final Foo other = (Foo) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("Foo [name=").append(name).append("]"); + return builder.toString(); + } +} diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/spring/PersistenceConfig.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/spring/PersistenceConfig.java new file mode 100644 index 0000000000..04961c3c49 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/spring/PersistenceConfig.java @@ -0,0 +1,82 @@ +package com.baeldung.spring; + +import com.baeldung.persistence.dao.IFooDao; +import com.baeldung.persistence.dao.impl.FooHibernateDao; +import com.google.common.base.Preconditions; +import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; +import org.springframework.orm.hibernate5.HibernateTransactionManager; +import org.springframework.orm.hibernate5.LocalSessionFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.sql.DataSource; +import java.util.Properties; + +@Configuration +@EnableTransactionManagement +@PropertySource({ "classpath:persistence-h2.properties" }) +@ComponentScan({ "com.baeldung.persistence" }) +public class PersistenceConfig { + + @Autowired + private Environment env; + + @Bean + public LocalSessionFactoryBean sessionFactory() { + final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); + sessionFactory.setDataSource(myDataSource()); + sessionFactory.setPackagesToScan(new String[] { "com.baeldung.persistence.model" }); + sessionFactory.setHibernateProperties(hibernateProperties()); + + return sessionFactory; + } + + @Bean + public DataSource myDataSource() { + final BasicDataSource dataSource = new BasicDataSource(); + dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); + dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url"))); + dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); + dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); + + return dataSource; + } + + @Bean + public PlatformTransactionManager hibernateTransactionManager() { + final HibernateTransactionManager transactionManager = new HibernateTransactionManager(); + transactionManager.setSessionFactory(sessionFactory().getObject()); + return transactionManager; + } + + @Bean + public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { + return new PersistenceExceptionTranslationPostProcessor(); + } + + @Bean + public IFooDao fooHibernateDao() { + return new FooHibernateDao(); + } + + private final Properties hibernateProperties() { + final Properties hibernateProperties = new Properties(); + hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); + + hibernateProperties.setProperty("hibernate.show_sql", "false"); + + // Envers properties + hibernateProperties.setProperty("org.hibernate.envers.audit_table_suffix", env.getProperty("envers.audit_table_suffix")); + + return hibernateProperties; + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/spring/PersistenceXmlConfig.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/spring/PersistenceXmlConfig.java new file mode 100644 index 0000000000..14caf5c88c --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/spring/PersistenceXmlConfig.java @@ -0,0 +1,14 @@ +package com.baeldung.spring; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@EnableTransactionManagement +@ComponentScan({ "com.baeldung.persistence.dao", "com.baeldung.persistence.service" }) +@ImportResource({ "classpath:hibernate6Config.xml" }) +public class PersistenceXmlConfig { + +} \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/src/main/resources/hibernate6Config.xml b/persistence-modules/spring-hibernate-6/src/main/resources/hibernate6Config.xml new file mode 100644 index 0000000000..bbb61cb3e0 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/resources/hibernate6Config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + ${hibernate.hbm2ddl.auto} + ${hibernate.dialect} + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/src/main/resources/hibernate6Configuration.xml b/persistence-modules/spring-hibernate-6/src/main/resources/hibernate6Configuration.xml new file mode 100644 index 0000000000..cb6cf0aa5c --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/resources/hibernate6Configuration.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + ${hibernate.hbm2ddl.auto} + ${hibernate.dialect} + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/src/main/resources/logback.xml b/persistence-modules/spring-hibernate-6/src/main/resources/logback.xml new file mode 100644 index 0000000000..ec0dc2469a --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/src/main/resources/persistence-h2.properties b/persistence-modules/spring-hibernate-6/src/main/resources/persistence-h2.properties new file mode 100644 index 0000000000..2ed7022eab --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/resources/persistence-h2.properties @@ -0,0 +1,22 @@ +# jdbc.X +jdbc.driverClassName=org.h2.Driver +jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1 +jdbc.eventGeneratedId=sa +jdbc.user=sa +jdbc.pass= + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=false +hibernate.hbm2ddl.auto=create-drop +hibernate.cache.use_second_level_cache=true +hibernate.cache.use_query_cache=true +hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory + + +# hibernate.search.X +hibernate.search.default.directory_provider = filesystem +hibernate.search.default.indexBase = /data/index/default + +# envers.X +envers.audit_table_suffix=_audit_log diff --git a/persistence-modules/spring-hibernate-6/src/main/resources/persistence-jndi.properties b/persistence-modules/spring-hibernate-6/src/main/resources/persistence-jndi.properties new file mode 100644 index 0000000000..16d750d7f8 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/resources/persistence-jndi.properties @@ -0,0 +1,8 @@ +# jdbc.X +jdbc.url=java:comp/env/jdbc/BaeldungDatabase + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +hibernate.show_sql=false +#hibernate.hbm2ddl.auto=create +hibernate.hbm2ddl.auto=update \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/src/main/resources/persistence-mysql.properties b/persistence-modules/spring-hibernate-6/src/main/resources/persistence-mysql.properties new file mode 100644 index 0000000000..b3cfd31f46 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/resources/persistence-mysql.properties @@ -0,0 +1,13 @@ +# jdbc.X +jdbc.driverClassName=com.mysql.cj.jdbc.Driver +jdbc.url=jdbc:mysql://localhost:3306/spring_hibernate5_01?createDatabaseIfNotExist=true +jdbc.eventGeneratedId=tutorialuser +jdbc.pass=tutorialmy5ql + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +hibernate.show_sql=false +hibernate.hbm2ddl.auto=create-drop + +# envers.X +envers.audit_table_suffix=_audit_log diff --git a/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/SpringContextTest.java b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/SpringContextTest.java new file mode 100644 index 0000000000..4ec83cda3e --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/SpringContextTest.java @@ -0,0 +1,19 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +import com.baeldung.spring.PersistenceConfig; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + + } +} diff --git a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/bootstrap/HibernateBootstrapIntegrationTest.java b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/bootstrap/HibernateBootstrapIntegrationTest.java similarity index 79% rename from persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/bootstrap/HibernateBootstrapIntegrationTest.java rename to persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/bootstrap/HibernateBootstrapIntegrationTest.java index c41423643a..31522288b6 100644 --- a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/bootstrap/HibernateBootstrapIntegrationTest.java +++ b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/bootstrap/HibernateBootstrapIntegrationTest.java @@ -1,33 +1,36 @@ package com.baeldung.hibernate.bootstrap; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import com.baeldung.hibernate.bootstrap.model.TestEntity; + + import org.hibernate.Session; import org.hibernate.SessionFactory; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.Commit; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.AnnotationConfigContextLoader; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.transaction.TestTransaction; import org.springframework.transaction.annotation.Transactional; -import static junit.framework.TestCase.assertFalse; -import static junit.framework.TestCase.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { HibernateConf.class }) @Transactional -public class HibernateBootstrapIntegrationTest { +@ContextConfiguration(classes = { HibernateXMLConf.class }) +@ExtendWith(SpringExtension.class) +class HibernateBootstrapIntegrationTest { @Autowired private SessionFactory sessionFactory; @Test - public void whenBootstrapHibernateSession_thenNoException() { + void whenBootstrapHibernateSession_thenNoException() { Session session = sessionFactory.getCurrentSession(); @@ -37,11 +40,11 @@ public class HibernateBootstrapIntegrationTest { TestEntity searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertNotNull(searchEntity); } @Test - public void whenProgrammaticTransactionCommit_thenEntityIsInDatabase() { + void whenProgrammaticTransactionCommit_thenEntityIsInDatabase() { assertTrue(TestTransaction.isActive()); //Save an entity and commit. @@ -53,7 +56,7 @@ public class HibernateBootstrapIntegrationTest { TestEntity searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertTrue(TestTransaction.isFlaggedForRollback()); TestTransaction.flagForCommit(); @@ -72,7 +75,7 @@ public class HibernateBootstrapIntegrationTest { session = sessionFactory.getCurrentSession(); searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertNotNull(searchEntity); session.delete(searchEntity); session.flush(); @@ -88,7 +91,7 @@ public class HibernateBootstrapIntegrationTest { session = sessionFactory.getCurrentSession(); searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertNotNull(searchEntity); session.delete(searchEntity); session.flush(); @@ -108,12 +111,12 @@ public class HibernateBootstrapIntegrationTest { session = sessionFactory.getCurrentSession(); searchEntity = session.find(TestEntity.class, 1); - Assert.assertNull(searchEntity); + assertNull(searchEntity); } @Test @Commit - public void givenTransactionCommitDefault_whenProgrammaticTransactionCommit_thenEntityIsInDatabase() { + void givenTransactionCommitDefault_whenProgrammaticTransactionCommit_thenEntityIsInDatabase() { assertTrue(TestTransaction.isActive()); //Save an entity and commit. @@ -125,7 +128,7 @@ public class HibernateBootstrapIntegrationTest { TestEntity searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertNotNull(searchEntity); assertFalse(TestTransaction.isFlaggedForRollback()); TestTransaction.end(); @@ -143,7 +146,7 @@ public class HibernateBootstrapIntegrationTest { session = sessionFactory.getCurrentSession(); searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertNotNull(searchEntity); session.delete(searchEntity); session.flush(); @@ -160,7 +163,7 @@ public class HibernateBootstrapIntegrationTest { session = sessionFactory.getCurrentSession(); searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertNotNull(searchEntity); session.delete(searchEntity); session.flush(); @@ -179,7 +182,7 @@ public class HibernateBootstrapIntegrationTest { session = sessionFactory.getCurrentSession(); searchEntity = session.find(TestEntity.class, 1); - Assert.assertNull(searchEntity); + assertNull(searchEntity); } } diff --git a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/bootstrap/HibernateXMLBootstrapIntegrationTest.java b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/bootstrap/HibernateXMLBootstrapIntegrationTest.java similarity index 65% rename from persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/bootstrap/HibernateXMLBootstrapIntegrationTest.java rename to persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/bootstrap/HibernateXMLBootstrapIntegrationTest.java index 5b811ad576..153e6736f1 100644 --- a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/bootstrap/HibernateXMLBootstrapIntegrationTest.java +++ b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/bootstrap/HibernateXMLBootstrapIntegrationTest.java @@ -1,26 +1,27 @@ package com.baeldung.hibernate.bootstrap; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import com.baeldung.hibernate.bootstrap.model.TestEntity; import org.hibernate.Session; import org.hibernate.SessionFactory; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { HibernateXMLConf.class }) @Transactional -public class HibernateXMLBootstrapIntegrationTest { +class HibernateXMLBootstrapIntegrationTest { @Autowired private SessionFactory sessionFactory; @Test - public void whenBootstrapHibernateSession_thenNoException() { + void whenBootstrapHibernateSession_thenNoException() { Session session = sessionFactory.getCurrentSession(); @@ -30,7 +31,7 @@ public class HibernateXMLBootstrapIntegrationTest { TestEntity searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertNotNull(searchEntity); } } diff --git a/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateIntegrationTest.java b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateIntegrationTest.java new file mode 100644 index 0000000000..9a52599842 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateIntegrationTest.java @@ -0,0 +1,52 @@ +package com.baeldung.hibernate.dynamicupdate; + +import java.util.Optional; + +import jakarta.transaction.Transactional; + +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.annotation.Commit; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +import com.baeldung.hibernate.dynamicupdate.model.Account; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = { DynamicUpdateConfig.class }, loader = AnnotationConfigContextLoader.class) +@Transactional +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class DynamicUpdateIntegrationTest { + + private static final Integer ACCOUNT_ID = 1; + + @Autowired + private AccountRepository accountRepository; + + @Test + @Commit + @Order(1) + void testA_whenTestAccountIsSaved_thenSuccess() { + Account account = new Account(ACCOUNT_ID, "account1", "regional", true); + accountRepository.save(account); + } + + @Test + @Commit + @Order(2) + // Enable Hibernate's debug logging in logback.xml to see the generated SQL statement. + void testB_whenAccountNameUpdated_thenSuccess() { + Optional account = accountRepository.findById(ACCOUNT_ID); + if(account.isPresent()){ + account.get().setName("Test Account"); + accountRepository.save(account.get()); + } + } + +} diff --git a/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/persistence/dao/common/HibernateDaoIntegrationTest.java b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/persistence/dao/common/HibernateDaoIntegrationTest.java new file mode 100644 index 0000000000..d7069c62c9 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/persistence/dao/common/HibernateDaoIntegrationTest.java @@ -0,0 +1,46 @@ +package com.baeldung.persistence.dao.common; + +import com.baeldung.persistence.model.Foo; +import com.baeldung.spring.PersistenceConfig; +import org.apache.commons.lang3.RandomStringUtils; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) +class HibernateDaoIntegrationTest { + + @Autowired + private SessionFactory sessionFactory; + + private Session session; + + @BeforeEach + public final void before() { + session = sessionFactory.openSession(); + } + + @AfterEach + public final void after() { + session.close(); + } + + @Test + final void whenContextIsBootstrapped_thenNoExceptions() { + // + } + + @Test + final void whenPersistEntity_thenSuccess() { + session.persist(new Foo(RandomStringUtils.randomAlphabetic(5).toUpperCase())); + } + +} From 3263e20dda391e34821c4fd42fe24478f0c1fbde Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Mon, 25 Sep 2023 09:57:14 +0530 Subject: [PATCH 076/193] Update README.md (#14830) --- persistence-modules/spring-hibernate-6/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-hibernate-6/README.md b/persistence-modules/spring-hibernate-6/README.md index fad56e32d2..08fe6216fd 100644 --- a/persistence-modules/spring-hibernate-6/README.md +++ b/persistence-modules/spring-hibernate-6/README.md @@ -1,4 +1,4 @@ -## Hibernate 5 with Spring +## Hibernate 6 with Spring This module contains articles about Hibernate 6 with Spring. From 1efb25df79cafc83aeee6f067c50c530af8b9037 Mon Sep 17 00:00:00 2001 From: Gaetano Piazzolla Date: Tue, 26 Sep 2023 05:41:59 +0200 Subject: [PATCH 077/193] JAVA-21742 | Fixing Quarkus Annotation with new version (#14821) --- quarkus-modules/quarkus/pom.xml | 5 +---- .../java/com/baeldung/quarkus/NativeHelloResourceIT.java | 4 ++-- .../java/com/baeldung/quarkus/NativeLibraryResourceIT.java | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/quarkus-modules/quarkus/pom.xml b/quarkus-modules/quarkus/pom.xml index 99d18579c3..fc3d294beb 100644 --- a/quarkus-modules/quarkus/pom.xml +++ b/quarkus-modules/quarkus/pom.xml @@ -152,11 +152,8 @@ - native-image + image-build - - true - diff --git a/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java b/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java index e6c8a3b8fb..b8567a8609 100644 --- a/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java +++ b/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java @@ -2,9 +2,9 @@ package com.baeldung.quarkus; import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.h2.H2DatabaseTestResource; -import io.quarkus.test.junit.NativeImageTest; +import io.quarkus.test.junit.QuarkusIntegrationTest; -@NativeImageTest +@QuarkusIntegrationTest @QuarkusTestResource(H2DatabaseTestResource.class) public class NativeHelloResourceIT extends HelloResourceUnitTest { diff --git a/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeLibraryResourceIT.java b/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeLibraryResourceIT.java index 0c11fa6fb4..10539d78d7 100644 --- a/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeLibraryResourceIT.java +++ b/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeLibraryResourceIT.java @@ -2,9 +2,9 @@ package com.baeldung.quarkus; import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.h2.H2DatabaseTestResource; -import io.quarkus.test.junit.NativeImageTest; +import io.quarkus.test.junit.QuarkusIntegrationTest; -@NativeImageTest +@QuarkusIntegrationTest @QuarkusTestResource(H2DatabaseTestResource.class) class NativeLibraryResourceIT extends LibraryHttpEndpointIntegrationTest { } From 083cf15f77b45d8aec79f2d2ea5557b48f751ca5 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Tue, 26 Sep 2023 09:05:22 +0330 Subject: [PATCH 078/193] #BAEL-6916: add StandardCharsets --- .../camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java | 3 ++- .../camel/jackson/FruitListJacksonUnmarshalUnitTest.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java index a5981ccb1a..df7a57a984 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java @@ -19,6 +19,7 @@ import org.springframework.test.annotation.DirtiesContext; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; @@ -77,7 +78,7 @@ public class FruitArrayJacksonUnmarshalUnitTest { private String readJsonFromFile(String path) throws URISyntaxException, IOException { URL resource = FruitArrayJacksonUnmarshalUnitTest.class.getResource(path); - return new String(Files.readAllBytes(Paths.get(resource.toURI()))); + return new String(Files.readAllBytes(Paths.get(resource.toURI())), StandardCharsets.UTF_8); } } diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java index b5b0fee2f9..bb31884d11 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java @@ -19,6 +19,7 @@ import org.springframework.context.annotation.Bean; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; @@ -76,7 +77,7 @@ public class FruitListJacksonUnmarshalUnitTest { private String readJsonFromFile(String path) throws URISyntaxException, IOException { URL resource = FruitListJacksonUnmarshalUnitTest.class.getResource(path); - return new String(Files.readAllBytes(Paths.get(resource.toURI()))); + return new String(Files.readAllBytes(Paths.get(resource.toURI())), StandardCharsets.UTF_8); } } From 2bd5ae21de62df694122a342988b39c89b57cd29 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Tue, 26 Sep 2023 09:05:54 +0330 Subject: [PATCH 079/193] #BAEL-6916: add camel-context xml --- .../src/main/resources/camel-context-test.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 messaging-modules/apache-camel/src/main/resources/camel-context-test.xml diff --git a/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml b/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml new file mode 100644 index 0000000000..f6177c69b5 --- /dev/null +++ b/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file From 84efed044f77d8bee9e1f8020d25a6d52590e7ef Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Tue, 26 Sep 2023 09:06:22 +0330 Subject: [PATCH 080/193] #BAEL-6916: add awaitility dependency --- messaging-modules/apache-camel/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/messaging-modules/apache-camel/pom.xml b/messaging-modules/apache-camel/pom.xml index 88c807a86a..8b49ad4893 100644 --- a/messaging-modules/apache-camel/pom.xml +++ b/messaging-modules/apache-camel/pom.xml @@ -41,6 +41,11 @@ org.springframework.boot spring-boot-starter-web + + org.awaitility + awaitility + test + From d05f27429af683552dc6808413ce44886e5f9ed2 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Tue, 26 Sep 2023 09:10:13 +0330 Subject: [PATCH 081/193] #BAEL-6916: change timestamp to date for test assertion --- .../main/java/com/baeldung/camel/apache/file/FileProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java index 5ca8cc9d72..c9537d48de 100644 --- a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java +++ b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java @@ -14,7 +14,7 @@ public class FileProcessor implements Processor { String originalFileName = (String) exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); Date date = new Date(); - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String changedFileName = dateFormat.format(date) + originalFileName; exchange.getIn().setHeader(Exchange.FILE_NAME, changedFileName); } From a4aa3a69b7207f076b55aa6df27dc29b33dc7ee7 Mon Sep 17 00:00:00 2001 From: panos-kakos Date: Tue, 26 Sep 2023 08:42:23 +0300 Subject: [PATCH 082/193] [JAVA-25490] Package renaming --- .../com/baeldung/config/scope/AppConfigFunctionBean.java | 2 +- .../src/main/java/com/baeldung/scope/AppConfig.java | 8 ++++---- .../main/java/com/baeldung/scope/AppProxyScopeConfig.java | 2 +- .../java/com/baeldung/scope/BeanInjectionStarter.java | 2 +- .../SingletonAppContextBean.java | 2 +- .../scope/{singletone => singleton}/SingletonBean.java | 2 +- .../{singletone => singleton}/SingletonFunctionBean.java | 2 +- .../{singletone => singleton}/SingletonLookupBean.java | 2 +- .../SingletonObjectFactoryBean.java | 2 +- .../{singletone => singleton}/SingletonProviderBean.java | 2 +- .../scope/PrototypeBeanInjectionIntegrationTest.java | 7 +++---- .../scope/PrototypeFunctionBeanIntegrationTest.java | 2 +- 12 files changed, 17 insertions(+), 18 deletions(-) rename spring-core/src/main/java/com/baeldung/scope/{singletone => singleton}/SingletonAppContextBean.java (94%) rename spring-core/src/main/java/com/baeldung/scope/{singletone => singleton}/SingletonBean.java (93%) rename spring-core/src/main/java/com/baeldung/scope/{singletone => singleton}/SingletonFunctionBean.java (91%) rename spring-core/src/main/java/com/baeldung/scope/{singletone => singleton}/SingletonLookupBean.java (88%) rename spring-core/src/main/java/com/baeldung/scope/{singletone => singleton}/SingletonObjectFactoryBean.java (91%) rename spring-core/src/main/java/com/baeldung/scope/{singletone => singleton}/SingletonProviderBean.java (90%) diff --git a/spring-core/src/main/java/com/baeldung/config/scope/AppConfigFunctionBean.java b/spring-core/src/main/java/com/baeldung/config/scope/AppConfigFunctionBean.java index a3c5445698..aa526b5403 100644 --- a/spring-core/src/main/java/com/baeldung/config/scope/AppConfigFunctionBean.java +++ b/spring-core/src/main/java/com/baeldung/config/scope/AppConfigFunctionBean.java @@ -7,7 +7,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; import com.baeldung.scope.prototype.PrototypeBean; -import com.baeldung.scope.singletone.SingletonFunctionBean; +import com.baeldung.scope.singleton.SingletonFunctionBean; @Configuration public class AppConfigFunctionBean { diff --git a/spring-core/src/main/java/com/baeldung/scope/AppConfig.java b/spring-core/src/main/java/com/baeldung/scope/AppConfig.java index 33a9c5c21e..2ef775ee4f 100644 --- a/spring-core/src/main/java/com/baeldung/scope/AppConfig.java +++ b/spring-core/src/main/java/com/baeldung/scope/AppConfig.java @@ -1,10 +1,10 @@ package com.baeldung.scope; import com.baeldung.scope.prototype.PrototypeBean; -import com.baeldung.scope.singletone.SingletonAppContextBean; -import com.baeldung.scope.singletone.SingletonBean; -import com.baeldung.scope.singletone.SingletonObjectFactoryBean; -import com.baeldung.scope.singletone.SingletonProviderBean; +import com.baeldung.scope.singleton.SingletonAppContextBean; +import com.baeldung.scope.singleton.SingletonBean; +import com.baeldung.scope.singleton.SingletonObjectFactoryBean; +import com.baeldung.scope.singleton.SingletonProviderBean; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; diff --git a/spring-core/src/main/java/com/baeldung/scope/AppProxyScopeConfig.java b/spring-core/src/main/java/com/baeldung/scope/AppProxyScopeConfig.java index 9f1874375e..0564dfb3c0 100644 --- a/spring-core/src/main/java/com/baeldung/scope/AppProxyScopeConfig.java +++ b/spring-core/src/main/java/com/baeldung/scope/AppProxyScopeConfig.java @@ -1,7 +1,7 @@ package com.baeldung.scope; import com.baeldung.scope.prototype.PrototypeBean; -import com.baeldung.scope.singletone.SingletonBean; +import com.baeldung.scope.singleton.SingletonBean; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.*; diff --git a/spring-core/src/main/java/com/baeldung/scope/BeanInjectionStarter.java b/spring-core/src/main/java/com/baeldung/scope/BeanInjectionStarter.java index 5cf0c9170c..47014aa2d1 100644 --- a/spring-core/src/main/java/com/baeldung/scope/BeanInjectionStarter.java +++ b/spring-core/src/main/java/com/baeldung/scope/BeanInjectionStarter.java @@ -1,7 +1,7 @@ package com.baeldung.scope; import com.baeldung.scope.prototype.PrototypeBean; -import com.baeldung.scope.singletone.SingletonBean; +import com.baeldung.scope.singleton.SingletonBean; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.util.Assert; diff --git a/spring-core/src/main/java/com/baeldung/scope/singletone/SingletonAppContextBean.java b/spring-core/src/main/java/com/baeldung/scope/singleton/SingletonAppContextBean.java similarity index 94% rename from spring-core/src/main/java/com/baeldung/scope/singletone/SingletonAppContextBean.java rename to spring-core/src/main/java/com/baeldung/scope/singleton/SingletonAppContextBean.java index f4d57a0f63..4f5b3274c8 100644 --- a/spring-core/src/main/java/com/baeldung/scope/singletone/SingletonAppContextBean.java +++ b/spring-core/src/main/java/com/baeldung/scope/singleton/SingletonAppContextBean.java @@ -1,4 +1,4 @@ -package com.baeldung.scope.singletone; +package com.baeldung.scope.singleton; import com.baeldung.scope.prototype.PrototypeBean; import org.springframework.beans.BeansException; diff --git a/spring-core/src/main/java/com/baeldung/scope/singletone/SingletonBean.java b/spring-core/src/main/java/com/baeldung/scope/singleton/SingletonBean.java similarity index 93% rename from spring-core/src/main/java/com/baeldung/scope/singletone/SingletonBean.java rename to spring-core/src/main/java/com/baeldung/scope/singleton/SingletonBean.java index 8d3a09b8fd..9c4cea4439 100644 --- a/spring-core/src/main/java/com/baeldung/scope/singletone/SingletonBean.java +++ b/spring-core/src/main/java/com/baeldung/scope/singleton/SingletonBean.java @@ -1,4 +1,4 @@ -package com.baeldung.scope.singletone; +package com.baeldung.scope.singleton; import com.baeldung.scope.prototype.PrototypeBean; import org.apache.log4j.Logger; diff --git a/spring-core/src/main/java/com/baeldung/scope/singletone/SingletonFunctionBean.java b/spring-core/src/main/java/com/baeldung/scope/singleton/SingletonFunctionBean.java similarity index 91% rename from spring-core/src/main/java/com/baeldung/scope/singletone/SingletonFunctionBean.java rename to spring-core/src/main/java/com/baeldung/scope/singleton/SingletonFunctionBean.java index 8cdc56a6fa..2788af1701 100644 --- a/spring-core/src/main/java/com/baeldung/scope/singletone/SingletonFunctionBean.java +++ b/spring-core/src/main/java/com/baeldung/scope/singleton/SingletonFunctionBean.java @@ -1,4 +1,4 @@ -package com.baeldung.scope.singletone; +package com.baeldung.scope.singleton; import java.util.function.Function; diff --git a/spring-core/src/main/java/com/baeldung/scope/singletone/SingletonLookupBean.java b/spring-core/src/main/java/com/baeldung/scope/singleton/SingletonLookupBean.java similarity index 88% rename from spring-core/src/main/java/com/baeldung/scope/singletone/SingletonLookupBean.java rename to spring-core/src/main/java/com/baeldung/scope/singleton/SingletonLookupBean.java index 4c3c9b69da..e5461826ef 100644 --- a/spring-core/src/main/java/com/baeldung/scope/singletone/SingletonLookupBean.java +++ b/spring-core/src/main/java/com/baeldung/scope/singleton/SingletonLookupBean.java @@ -1,4 +1,4 @@ -package com.baeldung.scope.singletone; +package com.baeldung.scope.singleton; import com.baeldung.scope.prototype.PrototypeBean; import org.springframework.beans.factory.annotation.Lookup; diff --git a/spring-core/src/main/java/com/baeldung/scope/singletone/SingletonObjectFactoryBean.java b/spring-core/src/main/java/com/baeldung/scope/singleton/SingletonObjectFactoryBean.java similarity index 91% rename from spring-core/src/main/java/com/baeldung/scope/singletone/SingletonObjectFactoryBean.java rename to spring-core/src/main/java/com/baeldung/scope/singleton/SingletonObjectFactoryBean.java index 55a91f8202..0e70d12e6e 100644 --- a/spring-core/src/main/java/com/baeldung/scope/singletone/SingletonObjectFactoryBean.java +++ b/spring-core/src/main/java/com/baeldung/scope/singleton/SingletonObjectFactoryBean.java @@ -1,4 +1,4 @@ -package com.baeldung.scope.singletone; +package com.baeldung.scope.singleton; import com.baeldung.scope.prototype.PrototypeBean; import org.springframework.beans.factory.ObjectFactory; diff --git a/spring-core/src/main/java/com/baeldung/scope/singletone/SingletonProviderBean.java b/spring-core/src/main/java/com/baeldung/scope/singleton/SingletonProviderBean.java similarity index 90% rename from spring-core/src/main/java/com/baeldung/scope/singletone/SingletonProviderBean.java rename to spring-core/src/main/java/com/baeldung/scope/singleton/SingletonProviderBean.java index 37d0ad9404..01a4a0ff11 100644 --- a/spring-core/src/main/java/com/baeldung/scope/singletone/SingletonProviderBean.java +++ b/spring-core/src/main/java/com/baeldung/scope/singleton/SingletonProviderBean.java @@ -1,4 +1,4 @@ -package com.baeldung.scope.singletone; +package com.baeldung.scope.singleton; import com.baeldung.scope.prototype.PrototypeBean; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-core/src/test/java/com/baeldung/scope/PrototypeBeanInjectionIntegrationTest.java b/spring-core/src/test/java/com/baeldung/scope/PrototypeBeanInjectionIntegrationTest.java index d0c2733765..df04957992 100644 --- a/spring-core/src/test/java/com/baeldung/scope/PrototypeBeanInjectionIntegrationTest.java +++ b/spring-core/src/test/java/com/baeldung/scope/PrototypeBeanInjectionIntegrationTest.java @@ -1,10 +1,9 @@ package com.baeldung.scope; import com.baeldung.scope.prototype.PrototypeBean; -import com.baeldung.scope.singletone.SingletonFunctionBean; -import com.baeldung.scope.singletone.SingletonLookupBean; -import com.baeldung.scope.singletone.SingletonObjectFactoryBean; -import com.baeldung.scope.singletone.SingletonProviderBean; +import com.baeldung.scope.singleton.SingletonLookupBean; +import com.baeldung.scope.singleton.SingletonObjectFactoryBean; +import com.baeldung.scope.singleton.SingletonProviderBean; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-core/src/test/java/com/baeldung/scope/PrototypeFunctionBeanIntegrationTest.java b/spring-core/src/test/java/com/baeldung/scope/PrototypeFunctionBeanIntegrationTest.java index 1e3c652599..dac3461ceb 100644 --- a/spring-core/src/test/java/com/baeldung/scope/PrototypeFunctionBeanIntegrationTest.java +++ b/spring-core/src/test/java/com/baeldung/scope/PrototypeFunctionBeanIntegrationTest.java @@ -11,7 +11,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader; import com.baeldung.config.scope.AppConfigFunctionBean; import com.baeldung.scope.prototype.PrototypeBean; -import com.baeldung.scope.singletone.SingletonFunctionBean; +import com.baeldung.scope.singleton.SingletonFunctionBean; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = AppConfigFunctionBean.class) From fa56411bd38477d3d5827c3a9bd3c17fa10a7e78 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Tue, 26 Sep 2023 09:13:59 +0330 Subject: [PATCH 083/193] #BAEL-6916: add Awaitility instead of Thread.sleep and given when then --- .../FileProcessorIntegrationTest.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java index 5df7543c6f..67273d8a87 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java @@ -4,11 +4,18 @@ import com.baeldung.camel.apache.file.FileProcessor; import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.DefaultCamelContext; +import org.awaitility.Awaitility; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.concurrent.TimeUnit; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; public class FileProcessorIntegrationTest { @@ -50,7 +57,7 @@ public class FileProcessorIntegrationTest { } @Test - public void moveFolderContentJavaDSLTest() throws Exception { + public void givenJavaDSLRoute_whenCamelStart_thenMoveFolderContent() throws Exception { final CamelContext camelContext = new DefaultCamelContext(); camelContext.addRoutes(new RouteBuilder() { @Override @@ -59,16 +66,27 @@ public class FileProcessorIntegrationTest { } }); camelContext.start(); - Thread.sleep(DURATION_MILIS); + verifyFolderContent(); camelContext.stop(); } @Test - public void moveFolderContentSpringDSLTest() throws InterruptedException { -// ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml"); -// ApplicationContext applicationContext = ContextLoader.getCurrentWebApplicationContext(); - Thread.sleep(DURATION_MILIS); - //applicationContext.close(); + public void givenSpringDSLRoute_whenCamelStart_thenMoveFolderContent() throws InterruptedException { + ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml"); + verifyFolderContent(); + applicationContext.close(); } + + private void verifyFolderContent() { + Date date = new Date(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + File destinationFile1 = new File(DESTINATION_FOLDER + "/" + dateFormat.format(date) + "File1.txt"); + File destinationFile2 = new File(DESTINATION_FOLDER + "/" + dateFormat.format(date) + "File2.txt"); + + Awaitility.await().atMost(DURATION_MILIS, TimeUnit.MILLISECONDS).untilAsserted(() -> { + assertThat(destinationFile1.exists()).isTrue(); + assertThat(destinationFile2.exists()).isTrue(); + }); + } } \ No newline at end of file From 36ba51772a4a8354724af451ba70e50c6006b4e8 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Tue, 26 Sep 2023 14:58:58 +0530 Subject: [PATCH 084/193] JAVA-20281 GitHub Issue: Error in kubernetes resource in spring cloud modules (#14532) --- .../travel-agency-service/mongo-deployment.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-guide/travel-agency-service/mongo-deployment.yaml b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-guide/travel-agency-service/mongo-deployment.yaml index 3d40581578..77a5efa13c 100644 --- a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-guide/travel-agency-service/mongo-deployment.yaml +++ b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-guide/travel-agency-service/mongo-deployment.yaml @@ -14,22 +14,24 @@ spec: selector: service: mongo --- -apiVersion: extensions/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: mongo spec: replicas: 1 + selector: + matchLabels: + name: mongodb-service template: metadata: labels: service: mongo - name: mongodb-service + name: mongodb-service spec: containers: - args: - mongod - - --smallfiles image: mongo:latest name: mongo env: From 6a858656fd9a3e6262edd549f2e4585604067e34 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Tue, 26 Sep 2023 13:53:34 +0330 Subject: [PATCH 085/193] #BAEL-6916: remove extra space --- .../camel/file/processor/FileProcessorIntegrationTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java index 67273d8a87..5003021d20 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java @@ -75,7 +75,6 @@ public class FileProcessorIntegrationTest { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml"); verifyFolderContent(); applicationContext.close(); - } private void verifyFolderContent() { From ef3c6c0e0b9e4a8963bebfd01875e29d869eb599 Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Wed, 27 Sep 2023 03:08:30 +0200 Subject: [PATCH 086/193] [list-ic-contains] Check if a List Contains a String Element While Ignoring Case (#14826) --- .../core-java-collections-list-6/pom.xml | 15 +++++++ ...ngListCaseInsensitiveContainsUnitTest.java | 44 +++++++++++++++++++ core-java-modules/pom.xml | 1 + 3 files changed, 60 insertions(+) create mode 100644 core-java-modules/core-java-collections-list-6/pom.xml create mode 100644 core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/lists/StringListCaseInsensitiveContainsUnitTest.java diff --git a/core-java-modules/core-java-collections-list-6/pom.xml b/core-java-modules/core-java-collections-list-6/pom.xml new file mode 100644 index 0000000000..9bea6358c4 --- /dev/null +++ b/core-java-modules/core-java-collections-list-6/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + core-java-collections-list-6 + core-java-collections-list-6 + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + \ No newline at end of file diff --git a/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/lists/StringListCaseInsensitiveContainsUnitTest.java b/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/lists/StringListCaseInsensitiveContainsUnitTest.java new file mode 100644 index 0000000000..51fafcca6b --- /dev/null +++ b/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/lists/StringListCaseInsensitiveContainsUnitTest.java @@ -0,0 +1,44 @@ +package com.baeldung.lists; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; + +import org.junit.jupiter.api.Test; + +public class StringListCaseInsensitiveContainsUnitTest { + private final static List THE_LIST = List.of("Game of Thrones", "Forrest Gump", "American Beauty", "Pretty Woman", "Catch Me If You Can"); + + @Test + void whenUsingContains_thenGetExpectedResult() { + assertFalse(THE_LIST.contains("catch me if you can")); + } + + boolean ignoreCaseContainsForLoop(List list, String value) { + for (String e : list) { + if (value.equalsIgnoreCase(e)) + return true; + } + return false; + } + + @Test + void whenUsingIgnoreCaseContainsForLoop_thenGetExpectedResult() { + assertTrue(ignoreCaseContainsForLoop(THE_LIST, "CATCH me if you CAN")); + assertTrue(ignoreCaseContainsForLoop(THE_LIST, "game of thrones")); + assertFalse(ignoreCaseContainsForLoop(THE_LIST, "The Godfather")); + } + + @Test + void whenUsingIgnoreCaseContainsStream_thenGetExpectedResult() { + assertTrue(THE_LIST.stream() + .anyMatch(e -> e.equalsIgnoreCase("CATCH me if you CAN"))); + + assertTrue(THE_LIST.stream() + .anyMatch("game of thrones"::equalsIgnoreCase)); + + assertFalse(THE_LIST.stream() + .anyMatch("The Godfather"::equalsIgnoreCase)); + } +} \ No newline at end of file diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 34e5204868..d0cce5e66f 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -78,6 +78,7 @@ core-java-collections-list core-java-collections-list-2 core-java-collections-list-3 + core-java-collections-list-6 core-java-collections-maps core-java-collections-maps-2 core-java-collections-maps-3 From bcfb4881fd8e2e0df9366c4a2b3e7dda1b828606 Mon Sep 17 00:00:00 2001 From: timis1 <12120641+timis1@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:22:47 +0300 Subject: [PATCH 087/193] JAVA-24463 Rollback the changes in the spring-reactive and spring-5-reactive (#14845) Co-authored-by: timis1 --- spring-reactive-modules/pom.xml | 4 +- .../.gitignore | 0 .../spring-5-reactive/README.md | 14 ++ .../spring-5-reactive/pom.xml | 164 ++++++++++++++++ .../src/main}/WEB-INF/web.xml | 0 .../src/main/assets/index.html | 0 .../java/com/baeldung/functional/Actor.java | 0 .../com/baeldung/functional/FormHandler.java | 0 .../FunctionalSpringBootApplication.java | 0 .../functional/FunctionalWebApplication.java | 0 .../functional/IndexRewriteFilter.java | 0 .../com/baeldung/functional/RootServlet.java | 0 .../reactive/Spring5ReactiveApplication.java | 0 .../controller/FooReactiveController.java | 0 .../controller/PathPatternController.java | 4 +- .../java/com/baeldung/reactive/model/Foo.java | 0 .../controllers/ResponseHeaderController.java | 0 .../filter/AddResponseHeaderWebFilter.java | 0 .../handlers/ResponseHeaderHandler.java | 0 .../ResponseHeadersRouterFunctions.java | 0 .../com/baeldung/reactive/urlmatch/Actor.java | 0 ...Spring5URLPatternUsingRouterFunctions.java | 2 +- .../reactive/urlmatch/FormHandler.java | 0 .../urlmatch/FunctionalWebApplication.java | 0 .../reactive/urlmatch/IndexRewriteFilter.java | 0 .../com/baeldung/reactive/util/CpuUtils.java | 0 .../com/baeldung/websession/Application.java | 0 .../websession/configuration/RedisConfig.java | 0 .../configuration/SessionConfig.java | 0 .../configuration/WebFluxConfig.java | 0 .../configuration/WebFluxSecurityConfig.java | 0 .../controller/SessionController.java | 0 .../websession/transfer/CustomResponse.java | 0 .../java/com/baeldung/websocket/Event.java | 0 .../ReactiveJavaClientWebSocket.java | 0 .../ReactiveWebSocketApplication.java | 0 .../ReactiveWebSocketConfiguration.java | 0 .../websocket/ReactiveWebSocketHandler.java | 0 .../websocket/WebSocketController.java | 2 - .../src/main/resources/application.properties | 0 .../src/main/resources/files/hello.txt | 0 .../src/main/resources/files/test/test.txt | 0 .../src/main/resources/logback.xml | 0 .../main/resources/resources/test/test.txt | 0 .../resources/static/client-websocket.html | 0 .../java/com/baeldung/SpringContextTest.java | 0 ...nctionalWebApplicationIntegrationTest.java | 0 .../com/baeldung/reactive/FluxUnitTest.java | 0 .../ResponseHeaderLiveTest.java | 0 ...rnUsingRouterFunctionsIntegrationTest.java | 2 +- ...ernsUsingHandlerMethodIntegrationTest.java | 4 +- .../src/test/resources/baeldung-weekly.png | Bin .../spring-reactive-webflux/README.md | 23 --- .../spring-reactive-webflux/pom.xml | 112 ----------- .../spring-reactive/README.md | 28 ++- .../spring-reactive/pom.xml | 177 ++++++------------ .../reactive/concurrency/Application.java | 0 .../reactive/concurrency/Controller.java | 0 .../baeldung/reactive/concurrency/Person.java | 0 .../concurrency/PersonRepository.java | 0 .../ConsumerDebuggingApplication.java | 0 .../ReactiveConfigsToggleRestController.java | 0 .../debugging/consumer/cronjobs/CronJobs.java | 0 .../debugging/consumer/model/Foo.java | 0 .../debugging/consumer/model/FooDto.java | 0 .../consumer/service/FooNameHelper.java | 0 .../consumer/service/FooQuantityHelper.java | 0 .../consumer/service/FooReporter.java | 0 .../consumer/service/FooService.java | 0 .../server/ServerDebuggingApplication.java | 0 .../server/handlers/ServerHandler.java | 0 .../reactive/debugging/server/model/Foo.java | 0 .../server/routers/ServerRouter.java | 0 .../reactive/security/GreetingController.java | 0 .../reactive/security/GreetingService.java | 0 .../reactive/security/SecurityConfig.java | 0 .../security/SpringSecurity6Application.java | 0 .../com/baeldung/reactive/webclient/Foo.java | 0 .../baeldung/reactive/webclient/Tweet.java | 0 .../TweetsSlowServiceController.java | 0 .../webclient/WebClientApplication.java | 0 .../webclient/WebClientController.java | 0 .../reactive/webclient/WebController.java | 0 .../SpringWebClientRequestsApp.java | 0 .../baeldung/reactive/webflux/Employee.java | 0 .../reactive/webflux/EmployeeRepository.java | 0 .../annotation/EmployeeController.java | 0 .../annotation/EmployeeSpringApplication.java | 0 .../webflux/annotation/EmployeeWebClient.java | 0 .../annotation/EmployeeWebSecurityConfig.java | 0 .../functional/EmployeeFunctionalConfig.java | 0 .../EmployeeSpringFunctionalApplication.java | 0 .../ConsumerFooServiceIntegrationTest.java | 0 .../consumer/ConsumerFooServiceLiveTest.java | 0 .../consumer/utils/ListAppender.java | 0 .../introduction/ReactorIntegrationTest.java | 0 .../security/SecurityIntegrationTest.java | 0 .../reactive/webclient/SpringContextTest.java | 0 .../webclient/WebClientIntegrationTest.java | 0 .../WebControllerIntegrationTest.java | 0 .../WebTestClientIntegrationTest.java | 0 ...bClientRequestsWithParametersUnitTest.java | 0 .../EmployeeControllerIntegrationTest.java | 0 ...ployeeSpringFunctionalIntegrationTest.java | 0 .../src/test/resources/logback-test.xml | 0 105 files changed, 266 insertions(+), 270 deletions(-) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/.gitignore (100%) create mode 100644 spring-reactive-modules/spring-5-reactive/README.md create mode 100644 spring-reactive-modules/spring-5-reactive/pom.xml rename spring-reactive-modules/{spring-reactive/src/main/webapp => spring-5-reactive/src/main}/WEB-INF/web.xml (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/assets/index.html (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/functional/Actor.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/functional/FormHandler.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/functional/FunctionalWebApplication.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/functional/IndexRewriteFilter.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/functional/RootServlet.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/reactive/controller/PathPatternController.java (94%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/reactive/model/Foo.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/reactive/responseheaders/controllers/ResponseHeaderController.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/reactive/responseheaders/filter/AddResponseHeaderWebFilter.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/reactive/responseheaders/functional/handlers/ResponseHeaderHandler.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/reactive/responseheaders/functional/routers/ResponseHeadersRouterFunctions.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/reactive/urlmatch/Actor.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java (97%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/reactive/urlmatch/FunctionalWebApplication.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/reactive/urlmatch/IndexRewriteFilter.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/reactive/util/CpuUtils.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/websession/Application.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/websession/configuration/RedisConfig.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/websession/configuration/SessionConfig.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/websession/configuration/WebFluxConfig.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/websession/configuration/WebFluxSecurityConfig.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/websession/controller/SessionController.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/websession/transfer/CustomResponse.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/websocket/Event.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/websocket/ReactiveJavaClientWebSocket.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/websocket/ReactiveWebSocketApplication.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/websocket/ReactiveWebSocketConfiguration.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/websocket/ReactiveWebSocketHandler.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/java/com/baeldung/websocket/WebSocketController.java (92%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/resources/application.properties (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/resources/files/hello.txt (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/resources/files/test/test.txt (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/resources/logback.xml (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/resources/resources/test/test.txt (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/main/resources/static/client-websocket.html (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/test/java/com/baeldung/reactive/FluxUnitTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/test/java/com/baeldung/reactive/responseheaders/ResponseHeaderLiveTest.java (100%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java (98%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java (97%) rename spring-reactive-modules/{spring-reactive => spring-5-reactive}/src/test/resources/baeldung-weekly.png (100%) delete mode 100644 spring-reactive-modules/spring-reactive-webflux/README.md delete mode 100644 spring-reactive-modules/spring-reactive-webflux/pom.xml rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/concurrency/Application.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/concurrency/Controller.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/concurrency/Person.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/concurrency/PersonRepository.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/debugging/consumer/ConsumerDebuggingApplication.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/debugging/consumer/controllers/ReactiveConfigsToggleRestController.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/debugging/consumer/cronjobs/CronJobs.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/debugging/consumer/model/Foo.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/debugging/consumer/model/FooDto.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooNameHelper.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooQuantityHelper.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooReporter.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooService.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/debugging/server/ServerDebuggingApplication.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/debugging/server/handlers/ServerHandler.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/debugging/server/model/Foo.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/debugging/server/routers/ServerRouter.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/security/GreetingController.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/security/GreetingService.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/security/SecurityConfig.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/security/SpringSecurity6Application.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webclient/Foo.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webclient/Tweet.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webclient/TweetsSlowServiceController.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webclient/WebClientApplication.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webclient/WebClientController.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webclient/WebController.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webclientrequests/SpringWebClientRequestsApp.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webflux/Employee.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webflux/EmployeeRepository.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeController.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeSpringApplication.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebClient.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebSecurityConfig.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeFunctionalConfig.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalApplication.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceLiveTest.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/test/java/com/baeldung/reactive/debugging/consumer/utils/ListAppender.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/test/java/com/baeldung/reactive/introduction/ReactorIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/test/java/com/baeldung/reactive/security/SecurityIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/test/java/com/baeldung/reactive/webclient/SpringContextTest.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/test/java/com/baeldung/reactive/webclient/WebClientIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/test/java/com/baeldung/reactive/webclient/WebControllerIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/test/java/com/baeldung/reactive/webclient/WebTestClientIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/test/java/com/baeldung/reactive/webclientrequests/WebClientRequestsWithParametersUnitTest.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/test/java/com/baeldung/reactive/webflux/annotation/EmployeeControllerIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/test/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalIntegrationTest.java (100%) rename spring-reactive-modules/{spring-reactive-webflux => spring-reactive}/src/test/resources/logback-test.xml (100%) diff --git a/spring-reactive-modules/pom.xml b/spring-reactive-modules/pom.xml index efae864b46..06519d723a 100644 --- a/spring-reactive-modules/pom.xml +++ b/spring-reactive-modules/pom.xml @@ -19,7 +19,7 @@ spring-reactive-data spring-reactive-data-2 - spring-reactive + spring-5-reactive spring-reactive-2 spring-reactive-3 spring-reactive-client @@ -28,7 +28,7 @@ spring-reactive-oauth spring-reactive-security spring-data-couchbase - spring-reactive-webflux + spring-reactive spring-reactive-exceptions spring-reactor spring-webflux-amqp diff --git a/spring-reactive-modules/spring-reactive/.gitignore b/spring-reactive-modules/spring-5-reactive/.gitignore similarity index 100% rename from spring-reactive-modules/spring-reactive/.gitignore rename to spring-reactive-modules/spring-5-reactive/.gitignore diff --git a/spring-reactive-modules/spring-5-reactive/README.md b/spring-reactive-modules/spring-5-reactive/README.md new file mode 100644 index 0000000000..3f44267234 --- /dev/null +++ b/spring-reactive-modules/spring-5-reactive/README.md @@ -0,0 +1,14 @@ +## Spring 5 Reactive Project + +This module contains articles about reactive Spring Boot + +### The Course +The "REST With Spring" Classes: https://bit.ly/restwithspring + +### Relevant Articles + +- [Exploring the Spring 5 WebFlux URL Matching](https://www.baeldung.com/spring-5-mvc-url-matching) +- [Reactive WebSockets with Spring 5](https://www.baeldung.com/spring-5-reactive-websockets) +- [How to Set a Header on a Response with Spring 5](https://www.baeldung.com/spring-response-header) +- [A Guide to Spring Session Reactive Support: WebSession](https://www.baeldung.com/spring-session-reactive) +- More articles: [[next -->]](../spring-5-reactive-2) \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-reactive/pom.xml b/spring-reactive-modules/spring-5-reactive/pom.xml new file mode 100644 index 0000000000..fd47c70a07 --- /dev/null +++ b/spring-reactive-modules/spring-5-reactive/pom.xml @@ -0,0 +1,164 @@ + + 4.0.0 + spring-5-reactive + 0.0.1-SNAPSHOT + spring-5-reactive + jar + spring 5 sample project about new features + + + com.baeldung.spring.reactive + spring-reactive-modules + 1.0.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-tomcat + + + org.springframework.boot + spring-boot-starter-integration + + + org.springframework.boot + spring-boot-starter-websocket + + + javax.json.bind + javax.json.bind-api + + + org.projectlombok + lombok + compile + + + org.apache.geronimo.specs + geronimo-json_1.1_spec + ${geronimo-json_1.1_spec.version} + + + org.apache.johnzon + johnzon-jsonb + + + + org.apache.commons + commons-lang3 + + + + org.springframework.boot + spring-boot-devtools + runtime + + + org.springframework + spring-test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + io.projectreactor + reactor-test + test + + + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.session + spring-session-core + + + org.springframework.session + spring-session-data-redis + + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + test + + + io.reactivex.rxjava2 + rxjava + + + org.apache.httpcomponents + httpclient + + + io.netty + netty-all + + + + + + + maven-resources-plugin + 3.0.1 + + + copy-resources + validate + + copy-resources + + + + + src/main/assets + true + + + ${basedir}/target/classes/assets + + + + + + org.springframework.boot + spring-boot-maven-plugin + + com.baeldung.reactive.Spring5ReactiveApplication + JAR + + + + + + + 1.1.3 + 1.0 + 1.0 + + + \ No newline at end of file diff --git a/spring-reactive-modules/spring-reactive/src/main/webapp/WEB-INF/web.xml b/spring-reactive-modules/spring-5-reactive/src/main/WEB-INF/web.xml similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/webapp/WEB-INF/web.xml rename to spring-reactive-modules/spring-5-reactive/src/main/WEB-INF/web.xml diff --git a/spring-reactive-modules/spring-reactive/src/main/assets/index.html b/spring-reactive-modules/spring-5-reactive/src/main/assets/index.html similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/assets/index.html rename to spring-reactive-modules/spring-5-reactive/src/main/assets/index.html diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/Actor.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/Actor.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/Actor.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/Actor.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/FormHandler.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/FormHandler.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/FormHandler.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalSpringBootApplication.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/FunctionalWebApplication.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/IndexRewriteFilter.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/RootServlet.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/functional/RootServlet.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/functional/RootServlet.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/Spring5ReactiveApplication.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/FooReactiveController.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/controller/PathPatternController.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/PathPatternController.java similarity index 94% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/controller/PathPatternController.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/PathPatternController.java index 3c9cb812f2..653c95d566 100644 --- a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/controller/PathPatternController.java +++ b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/PathPatternController.java @@ -22,9 +22,9 @@ public class PathPatternController { return "/spring5/*id"; } - @GetMapping("/resources/**") + @GetMapping("//**") public String wildcardTakingZeroOrMorePathSegments() { - return "/resources/**"; + return "//**"; } @GetMapping("/{baeldung:[a-z]+}") diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/model/Foo.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/model/Foo.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/model/Foo.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/model/Foo.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/controllers/ResponseHeaderController.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/controllers/ResponseHeaderController.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/controllers/ResponseHeaderController.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/controllers/ResponseHeaderController.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/filter/AddResponseHeaderWebFilter.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/filter/AddResponseHeaderWebFilter.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/filter/AddResponseHeaderWebFilter.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/filter/AddResponseHeaderWebFilter.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/handlers/ResponseHeaderHandler.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/handlers/ResponseHeaderHandler.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/handlers/ResponseHeaderHandler.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/handlers/ResponseHeaderHandler.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/routers/ResponseHeadersRouterFunctions.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/routers/ResponseHeadersRouterFunctions.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/routers/ResponseHeadersRouterFunctions.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/responseheaders/functional/routers/ResponseHeadersRouterFunctions.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/Actor.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/Actor.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/Actor.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/Actor.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java similarity index 97% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java index b7bb53600e..60cf85e5da 100644 --- a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java +++ b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java @@ -29,7 +29,7 @@ public class ExploreSpring5URLPatternUsingRouterFunctions { .andRoute(GET("/{var1}_{var2}"), serverRequest -> ok().body(fromValue(serverRequest.pathVariable("var1") + " , " + serverRequest.pathVariable("var2")))) .andRoute(GET("/{baeldung:[a-z]+}"), serverRequest -> ok().body(fromValue("/{baeldung:[a-z]+} was accessed and baeldung=" + serverRequest.pathVariable("baeldung")))) .and(RouterFunctions.resources("/files/{*filepaths}", new ClassPathResource("files/"))) - .and(RouterFunctions.resources("/resources/**", new ClassPathResource("resources/"))); + .and(RouterFunctions.resources("//**", new ClassPathResource("/"))); } WebServer start() throws Exception { diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FormHandler.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/FunctionalWebApplication.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FunctionalWebApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/FunctionalWebApplication.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/FunctionalWebApplication.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/IndexRewriteFilter.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/IndexRewriteFilter.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/urlmatch/IndexRewriteFilter.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/IndexRewriteFilter.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/util/CpuUtils.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/util/CpuUtils.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/util/CpuUtils.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/util/CpuUtils.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/Application.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/Application.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/Application.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/Application.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/RedisConfig.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/RedisConfig.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/RedisConfig.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/RedisConfig.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/SessionConfig.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/SessionConfig.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/SessionConfig.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/SessionConfig.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxConfig.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxConfig.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxConfig.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxConfig.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxSecurityConfig.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxSecurityConfig.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/configuration/WebFluxSecurityConfig.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/controller/SessionController.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/controller/SessionController.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/controller/SessionController.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/controller/SessionController.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/transfer/CustomResponse.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/transfer/CustomResponse.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websession/transfer/CustomResponse.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websession/transfer/CustomResponse.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/Event.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/Event.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/Event.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/Event.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveJavaClientWebSocket.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveJavaClientWebSocket.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveJavaClientWebSocket.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveJavaClientWebSocket.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketApplication.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketApplication.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketApplication.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketConfiguration.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketConfiguration.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketConfiguration.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketConfiguration.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketHandler.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketHandler.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketHandler.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/ReactiveWebSocketHandler.java diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/WebSocketController.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/WebSocketController.java similarity index 92% rename from spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/WebSocketController.java rename to spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/WebSocketController.java index bf4a463ae6..0c8f9debc9 100644 --- a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/websocket/WebSocketController.java +++ b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/WebSocketController.java @@ -6,8 +6,6 @@ import org.slf4j.LoggerFactory; import javax.websocket.*; import javax.websocket.server.ServerEndpoint; import java.io.IOException; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; @ServerEndpoint("/event-emitter") public class WebSocketController { diff --git a/spring-reactive-modules/spring-reactive/src/main/resources/application.properties b/spring-reactive-modules/spring-5-reactive/src/main/resources/application.properties similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/resources/application.properties rename to spring-reactive-modules/spring-5-reactive/src/main/resources/application.properties diff --git a/spring-reactive-modules/spring-reactive/src/main/resources/files/hello.txt b/spring-reactive-modules/spring-5-reactive/src/main/resources/files/hello.txt similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/resources/files/hello.txt rename to spring-reactive-modules/spring-5-reactive/src/main/resources/files/hello.txt diff --git a/spring-reactive-modules/spring-reactive/src/main/resources/files/test/test.txt b/spring-reactive-modules/spring-5-reactive/src/main/resources/files/test/test.txt similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/resources/files/test/test.txt rename to spring-reactive-modules/spring-5-reactive/src/main/resources/files/test/test.txt diff --git a/spring-reactive-modules/spring-reactive/src/main/resources/logback.xml b/spring-reactive-modules/spring-5-reactive/src/main/resources/logback.xml similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/resources/logback.xml rename to spring-reactive-modules/spring-5-reactive/src/main/resources/logback.xml diff --git a/spring-reactive-modules/spring-reactive/src/main/resources/resources/test/test.txt b/spring-reactive-modules/spring-5-reactive/src/main/resources/resources/test/test.txt similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/resources/resources/test/test.txt rename to spring-reactive-modules/spring-5-reactive/src/main/resources/resources/test/test.txt diff --git a/spring-reactive-modules/spring-reactive/src/main/resources/static/client-websocket.html b/spring-reactive-modules/spring-5-reactive/src/main/resources/static/client-websocket.html similarity index 100% rename from spring-reactive-modules/spring-reactive/src/main/resources/static/client-websocket.html rename to spring-reactive-modules/spring-5-reactive/src/main/resources/static/client-websocket.html diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/SpringContextTest.java b/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/SpringContextTest.java rename to spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java b/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java rename to spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/functional/FunctionalWebApplicationIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java b/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java rename to spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/FluxUnitTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/responseheaders/ResponseHeaderLiveTest.java b/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/responseheaders/ResponseHeaderLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/responseheaders/ResponseHeaderLiveTest.java rename to spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/responseheaders/ResponseHeaderLiveTest.java diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java b/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java similarity index 98% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java rename to spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java index a77a67c6ba..63dfbd44a1 100644 --- a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java +++ b/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java @@ -110,7 +110,7 @@ public class ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest { @Test public void givenRouter_whenAccess_thenGot() throws Exception { client.get() - .uri("/resources/test/test.txt") + .uri("//test/test.txt") .exchange() .expectStatus() .isOk() diff --git a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java b/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java similarity index 97% rename from spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java rename to spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java index 0b4607b54a..8eb8d04cd4 100644 --- a/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java +++ b/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java @@ -72,12 +72,12 @@ public class PathPatternsUsingHandlerMethodIntegrationTest { public void givenHandlerMethod_whenURLWithWildcardTakingZeroOrMorePathSegments_then200() { client.get() - .uri("/resources/baeldung") + .uri("//baeldung") .exchange() .expectStatus() .is2xxSuccessful() .expectBody() - .equals("/resources/**"); + .equals("//**"); } @Test diff --git a/spring-reactive-modules/spring-reactive/src/test/resources/baeldung-weekly.png b/spring-reactive-modules/spring-5-reactive/src/test/resources/baeldung-weekly.png similarity index 100% rename from spring-reactive-modules/spring-reactive/src/test/resources/baeldung-weekly.png rename to spring-reactive-modules/spring-5-reactive/src/test/resources/baeldung-weekly.png diff --git a/spring-reactive-modules/spring-reactive-webflux/README.md b/spring-reactive-modules/spring-reactive-webflux/README.md deleted file mode 100644 index d2b63b2186..0000000000 --- a/spring-reactive-modules/spring-reactive-webflux/README.md +++ /dev/null @@ -1,23 +0,0 @@ -### Spring Reactive Articles that are also part of the e-book - -This module contains articles about Spring Reactive that are also part of an Ebook. - -## Spring Reactive - -This module contains articles describing reactive processing in Spring. - -## Relevant articles: - -- [Intro To Reactor Core](https://www.baeldung.com/reactor-core) -- [Debugging Reactive Streams in Java](https://www.baeldung.com/spring-debugging-reactive-streams) -- [Guide to Spring 5 WebFlux](https://www.baeldung.com/spring-webflux) -- [Introduction to the Functional Web Framework in Spring 5](https://www.baeldung.com/spring-5-functional-web) -- [Spring 5 WebClient](https://www.baeldung.com/spring-5-webclient) -- [Spring WebClient vs. RestTemplate](https://www.baeldung.com/spring-webclient-resttemplate) -- [Spring WebClient Requests with Parameters](https://www.baeldung.com/webflux-webclient-parameters) -- [Spring Security 5 for Reactive Applications](https://www.baeldung.com/spring-security-5-reactive) -- [Concurrency in Spring WebFlux](https://www.baeldung.com/spring-webflux-concurrency) - -### NOTE: - -Since this is a module tied to an e-book, it should **not** be moved or used to store the code for any further article. diff --git a/spring-reactive-modules/spring-reactive-webflux/pom.xml b/spring-reactive-modules/spring-reactive-webflux/pom.xml deleted file mode 100644 index cecaeff20c..0000000000 --- a/spring-reactive-modules/spring-reactive-webflux/pom.xml +++ /dev/null @@ -1,112 +0,0 @@ - - - 4.0.0 - spring-reactive-webflux - - - com.baeldung - parent-boot-3 - 0.0.1-SNAPSHOT - ../../parent-boot-3 - - - - - org.springframework.boot - spring-boot-starter-webflux - - - org.springframework.boot - spring-boot-starter-validation - - - org.springframework.boot - spring-boot-starter-security - - - io.reactivex.rxjava2 - rxjava - ${rxjava.version} - - - io.projectreactor.kafka - reactor-kafka - ${reactor-kafka.version} - - - org.springframework.boot - spring-boot-starter-data-mongodb-reactive - - - org.springframework.security - spring-security-test - test - - - io.projectreactor - reactor-test - ${reactor.version} - test - - - org.projectlombok - lombok - - - - - - integration-lite-first - - - - org.apache.maven.plugins - maven-surefire-plugin - - - ${project.basedir}/src/test/resources/logback-test.xml - - - - - - - - integration-lite-second - - - - org.apache.maven.plugins - maven-surefire-plugin - - - ${project.basedir}/src/test/resources/logback-test.xml - - - - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - true - - - - - - - 3.4.16 - 1.3.10 - 2.2.21 - - - \ No newline at end of file diff --git a/spring-reactive-modules/spring-reactive/README.md b/spring-reactive-modules/spring-reactive/README.md index f3148fe696..5e52212061 100644 --- a/spring-reactive-modules/spring-reactive/README.md +++ b/spring-reactive-modules/spring-reactive/README.md @@ -1,14 +1,22 @@ -## Spring 5 Reactive Project -This module contains articles about reactive Spring 5 +This module contains articles about Spring Reactive that are also part of an Ebook. -### The Course -The "REST With Spring" Classes: https://bit.ly/restwithspring +## Spring Reactive -### Relevant Articles +This module contains articles describing reactive processing in Spring. -- [Exploring the Spring 5 WebFlux URL Matching](https://www.baeldung.com/spring-5-mvc-url-matching) -- [Reactive WebSockets with Spring 5](https://www.baeldung.com/spring-5-reactive-websockets) -- [How to Set a Header on a Response with Spring 5](https://www.baeldung.com/spring-response-header) -- [A Guide to Spring Session Reactive Support: WebSession](https://www.baeldung.com/spring-session-reactive) -- More articles: [[next -->]](../spring-5-reactive-2) +## Relevant articles: + +- [Intro To Reactor Core](https://www.baeldung.com/reactor-core) +- [Debugging Reactive Streams in Java](https://www.baeldung.com/spring-debugging-reactive-streams) +- [Guide to Spring 5 WebFlux](https://www.baeldung.com/spring-webflux) +- [Introduction to the Functional Web Framework in Spring 5](https://www.baeldung.com/spring-5-functional-web) +- [Spring 5 WebClient](https://www.baeldung.com/spring-5-webclient) +- [Spring WebClient vs. RestTemplate](https://www.baeldung.com/spring-webclient-resttemplate) +- [Spring WebClient Requests with Parameters](https://www.baeldung.com/webflux-webclient-parameters) +- [Spring Security 5 for Reactive Applications](https://www.baeldung.com/spring-security-5-reactive) +- [Concurrency in Spring WebFlux](https://www.baeldung.com/spring-webflux-concurrency) + +### NOTE: + +Since this is a module tied to an e-book, it should **not** be moved or used to store the code for any further article. \ No newline at end of file diff --git a/spring-reactive-modules/spring-reactive/pom.xml b/spring-reactive-modules/spring-reactive/pom.xml index f843e04c7b..263f29f9b5 100644 --- a/spring-reactive-modules/spring-reactive/pom.xml +++ b/spring-reactive-modules/spring-reactive/pom.xml @@ -4,71 +4,40 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-reactive - 0.0.1-SNAPSHOT - spring-5-reactive - jar - spring 5 sample project about new features - com.baeldung.spring.reactive - spring-reactive-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3/pom.xml + + org.springframework.boot + spring-boot-starter-webflux + org.springframework.boot spring-boot-starter-validation org.springframework.boot - spring-boot-starter-tomcat + spring-boot-starter-security + + + io.reactivex.rxjava2 + rxjava + ${rxjava.version} + + + io.projectreactor.kafka + reactor-kafka + ${reactor-kafka.version} org.springframework.boot - spring-boot-starter-integration - - - org.springframework.boot - spring-boot-starter-websocket - - - javax.json.bind - javax.json.bind-api - - - org.projectlombok - lombok - compile - - - org.apache.geronimo.specs - geronimo-json_1.1_spec - ${geronimo-json_1.1_spec.version} - - - org.apache.johnzon - johnzon-jsonb - - - - org.apache.commons - commons-lang3 - - - - org.springframework.boot - spring-boot-devtools - runtime - - - org.springframework - spring-test - - - org.springframework.boot - spring-boot-starter-test - test + spring-boot-starter-data-mongodb-reactive org.springframework.security @@ -78,88 +47,66 @@ io.projectreactor reactor-test - test - - - - org.springframework.boot - spring-boot-starter-webflux - - - org.springframework.boot - spring-boot-starter-data-redis - - - org.springframework.boot - spring-boot-starter-security - - - org.springframework.session - spring-session-core - - - org.springframework.session - spring-session-data-redis - - - org.apache.commons - commons-collections4 - ${commons-collections4.version} + ${reactor.version} test - io.reactivex.rxjava2 - rxjava - - - org.apache.httpcomponents - httpclient - - - io.netty - netty-all + org.projectlombok + lombok + + + integration-lite-first + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${project.basedir}/src/test/resources/logback-test.xml + + + + + + + + integration-lite-second + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${project.basedir}/src/test/resources/logback-test.xml + + + + + + + + - - maven-resources-plugin - 3.0.1 - - - copy-resources - validate - - copy-resources - - - - - src/main/assets - true - - - ${basedir}/target/classes/assets - - - - org.springframework.boot spring-boot-maven-plugin - com.baeldung.reactive.Spring5ReactiveApplication - JAR + true - 1.1.3 - 1.0 - 1.0 + 3.4.16 + 1.3.10 + 2.2.21 \ No newline at end of file diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/Application.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/Application.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/Application.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/Application.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/Controller.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/Controller.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/Controller.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/Controller.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/Person.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/Person.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/Person.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/Person.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/PersonRepository.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/PersonRepository.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/concurrency/PersonRepository.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/concurrency/PersonRepository.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/ConsumerDebuggingApplication.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/ConsumerDebuggingApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/ConsumerDebuggingApplication.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/ConsumerDebuggingApplication.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/controllers/ReactiveConfigsToggleRestController.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/controllers/ReactiveConfigsToggleRestController.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/controllers/ReactiveConfigsToggleRestController.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/controllers/ReactiveConfigsToggleRestController.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/cronjobs/CronJobs.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/cronjobs/CronJobs.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/cronjobs/CronJobs.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/cronjobs/CronJobs.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/model/Foo.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/model/Foo.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/model/Foo.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/model/Foo.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/model/FooDto.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/model/FooDto.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/model/FooDto.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/model/FooDto.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooNameHelper.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooNameHelper.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooNameHelper.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooNameHelper.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooQuantityHelper.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooQuantityHelper.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooQuantityHelper.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooQuantityHelper.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooReporter.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooReporter.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooReporter.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooReporter.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooService.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooService.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooService.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/consumer/service/FooService.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/ServerDebuggingApplication.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/ServerDebuggingApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/ServerDebuggingApplication.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/ServerDebuggingApplication.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/handlers/ServerHandler.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/handlers/ServerHandler.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/handlers/ServerHandler.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/handlers/ServerHandler.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/model/Foo.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/model/Foo.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/model/Foo.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/model/Foo.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/routers/ServerRouter.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/routers/ServerRouter.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/debugging/server/routers/ServerRouter.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/debugging/server/routers/ServerRouter.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/GreetingController.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/GreetingController.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/GreetingController.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/GreetingController.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/GreetingService.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/GreetingService.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/GreetingService.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/GreetingService.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/SecurityConfig.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/SecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/SecurityConfig.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/SecurityConfig.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/SpringSecurity6Application.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/SpringSecurity6Application.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/security/SpringSecurity6Application.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/security/SpringSecurity6Application.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/Foo.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/Foo.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/Foo.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/Foo.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/Tweet.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/Tweet.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/Tweet.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/Tweet.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/TweetsSlowServiceController.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/TweetsSlowServiceController.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/TweetsSlowServiceController.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/TweetsSlowServiceController.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/WebClientApplication.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/WebClientApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/WebClientApplication.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/WebClientApplication.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/WebClientController.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/WebClientController.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/WebClientController.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/WebClientController.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/WebController.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/WebController.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclient/WebController.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclient/WebController.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclientrequests/SpringWebClientRequestsApp.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclientrequests/SpringWebClientRequestsApp.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webclientrequests/SpringWebClientRequestsApp.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webclientrequests/SpringWebClientRequestsApp.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/Employee.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/Employee.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/Employee.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/Employee.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/EmployeeRepository.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/EmployeeRepository.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/EmployeeRepository.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/EmployeeRepository.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeController.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeController.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeController.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeController.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeSpringApplication.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeSpringApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeSpringApplication.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeSpringApplication.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebClient.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebClient.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebClient.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebClient.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebSecurityConfig.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebSecurityConfig.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/annotation/EmployeeWebSecurityConfig.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeFunctionalConfig.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeFunctionalConfig.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeFunctionalConfig.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeFunctionalConfig.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalApplication.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalApplication.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalApplication.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalApplication.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceIntegrationTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceIntegrationTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceLiveTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceLiveTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/debugging/consumer/ConsumerFooServiceLiveTest.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/debugging/consumer/utils/ListAppender.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/debugging/consumer/utils/ListAppender.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/debugging/consumer/utils/ListAppender.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/debugging/consumer/utils/ListAppender.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/introduction/ReactorIntegrationTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/introduction/ReactorIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/introduction/ReactorIntegrationTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/introduction/ReactorIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/security/SecurityIntegrationTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/security/SecurityIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/security/SecurityIntegrationTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/security/SecurityIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/SpringContextTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/SpringContextTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/SpringContextTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/SpringContextTest.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/WebClientIntegrationTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebClientIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/WebClientIntegrationTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebClientIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/WebControllerIntegrationTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebControllerIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/WebControllerIntegrationTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebControllerIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/WebTestClientIntegrationTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebTestClientIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclient/WebTestClientIntegrationTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebTestClientIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclientrequests/WebClientRequestsWithParametersUnitTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclientrequests/WebClientRequestsWithParametersUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webclientrequests/WebClientRequestsWithParametersUnitTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclientrequests/WebClientRequestsWithParametersUnitTest.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webflux/annotation/EmployeeControllerIntegrationTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webflux/annotation/EmployeeControllerIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webflux/annotation/EmployeeControllerIntegrationTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webflux/annotation/EmployeeControllerIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalIntegrationTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/test/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalIntegrationTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webflux/functional/EmployeeSpringFunctionalIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive-webflux/src/test/resources/logback-test.xml b/spring-reactive-modules/spring-reactive/src/test/resources/logback-test.xml similarity index 100% rename from spring-reactive-modules/spring-reactive-webflux/src/test/resources/logback-test.xml rename to spring-reactive-modules/spring-reactive/src/test/resources/logback-test.xml From 477e4fe8a9281571933251790ac08f674148fdca Mon Sep 17 00:00:00 2001 From: Ulisses Lima Date: Wed, 27 Sep 2023 04:37:56 -0300 Subject: [PATCH 088/193] JAVA-25303 Create contribution guidelines for tutorials repository (#14846) * Update issue templates * improve guidelines * remove default template --- .github/ISSUE_TEMPLATE/issue_report.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/issue_report.md b/.github/ISSUE_TEMPLATE/issue_report.md index 725ae12064..4bc8c8121c 100644 --- a/.github/ISSUE_TEMPLATE/issue_report.md +++ b/.github/ISSUE_TEMPLATE/issue_report.md @@ -5,7 +5,7 @@ title: '[ISSUE] ' --- **Article and Module Links** -A link to the affected article and the affected module. The link to the module is the one in the "over on GitHub" standard phrase. +A link to the affected article and the affected module. You can find the link to the module in the Conclusion section in the "on Github" standard phase. **Describe the Issue** A clear and concise description of what the issue is. @@ -30,9 +30,3 @@ If applicable, add screenshots to help explain your problem. **Additional Context** Add any other context about the issue here. - -Note that, unfortunately, we can only help with issues that are specifically and directly related to the article - not with your own, custom application. - -StackOverflow is a great place to ask more general questions. - -That's primarily because we get a large number of questions and - while we do try to go through as much as everything and help wherever we can, we can't really get back to all of them. \ No newline at end of file From 058119dfea7723b1d2494a0c3e2df18eb229b811 Mon Sep 17 00:00:00 2001 From: Bipin kumar Date: Wed, 27 Sep 2023 16:04:34 +0530 Subject: [PATCH 089/193] JAVA-23380: Removing empty spring.factories file (#14842) --- .../src/main/resources/META-INF/spring.factories | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories deleted file mode 100644 index e69de29bb2..0000000000 From 6528856bc590645b0c9d61c84405adf53e39fbf8 Mon Sep 17 00:00:00 2001 From: Bipin kumar Date: Wed, 27 Sep 2023 16:14:08 +0530 Subject: [PATCH 090/193] Java 25297 (#14844) Disable rethinkdb testing on jenkins --- persistence-modules/pom.xml | 2 +- ...nsertIntegrationTest.java => InsertIntegrationLiveTest.java} | 2 +- ...{QueryIntegrationTest.java => QueryIntegrationLiveTest.java} | 2 +- ...ngIntegrationTest.java => StreamingIntegrationLiveTest.java} | 2 +- ...ablesIntegrationTest.java => TablesIntegrationLiveTest.java} | 2 +- ...pdateIntegrationTest.java => UpdateIntegrationLiveTest.java} | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/{InsertIntegrationTest.java => InsertIntegrationLiveTest.java} (96%) rename persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/{QueryIntegrationTest.java => QueryIntegrationLiveTest.java} (97%) rename persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/{StreamingIntegrationTest.java => StreamingIntegrationLiveTest.java} (98%) rename persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/{TablesIntegrationTest.java => TablesIntegrationLiveTest.java} (94%) rename persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/{UpdateIntegrationTest.java => UpdateIntegrationLiveTest.java} (96%) diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index ec63d5c56e..f35b22a19d 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -115,7 +115,7 @@ java-mongodb questdb neo4j - + rethinkdb scylladb spring-data-cassandra-2 spring-data-jpa-repo-3 diff --git a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/InsertIntegrationTest.java b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/InsertIntegrationLiveTest.java similarity index 96% rename from persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/InsertIntegrationTest.java rename to persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/InsertIntegrationLiveTest.java index 244959d854..0e6cdae2b4 100644 --- a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/InsertIntegrationTest.java +++ b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/InsertIntegrationLiveTest.java @@ -10,7 +10,7 @@ import static com.rethinkdb.RethinkDB.r; /** * Some tests demonstrating inserting data. */ -public class InsertIntegrationTest extends TestBase { +public class InsertIntegrationLiveTest extends TestBase { /** * Create a table for the tests. */ diff --git a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/QueryIntegrationTest.java b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/QueryIntegrationLiveTest.java similarity index 97% rename from persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/QueryIntegrationTest.java rename to persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/QueryIntegrationLiveTest.java index 263dda9bc6..626d15bcb6 100644 --- a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/QueryIntegrationTest.java +++ b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/QueryIntegrationLiveTest.java @@ -16,7 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; /** * Some tests demonstrating querying data. */ -public class QueryIntegrationTest extends TestBase { +public class QueryIntegrationLiveTest extends TestBase { /** * Create a table for the tests. */ diff --git a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/StreamingIntegrationTest.java b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/StreamingIntegrationLiveTest.java similarity index 98% rename from persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/StreamingIntegrationTest.java rename to persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/StreamingIntegrationLiveTest.java index 4ca147cf68..bc105d2e4f 100644 --- a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/StreamingIntegrationTest.java +++ b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/StreamingIntegrationLiveTest.java @@ -13,7 +13,7 @@ import static com.rethinkdb.RethinkDB.r; /** * Some tests demonstrating streaming live changes to data. */ -public class StreamingIntegrationTest extends TestBase { +public class StreamingIntegrationLiveTest extends TestBase { @Test public void getLiveInserts() throws InterruptedException { ExecutorService executorService = Executors.newCachedThreadPool(); diff --git a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/TablesIntegrationTest.java b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/TablesIntegrationLiveTest.java similarity index 94% rename from persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/TablesIntegrationTest.java rename to persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/TablesIntegrationLiveTest.java index d60e500373..7bffb189b3 100644 --- a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/TablesIntegrationTest.java +++ b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/TablesIntegrationLiveTest.java @@ -12,7 +12,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; /** * Some tests demonstrating working with tables. */ -public class TablesIntegrationTest extends TestBase { +public class TablesIntegrationLiveTest extends TestBase { @Test public void createTable() { diff --git a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/UpdateIntegrationTest.java b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/UpdateIntegrationLiveTest.java similarity index 96% rename from persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/UpdateIntegrationTest.java rename to persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/UpdateIntegrationLiveTest.java index 39fad3a878..d47caa0b5e 100644 --- a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/UpdateIntegrationTest.java +++ b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/UpdateIntegrationLiveTest.java @@ -8,7 +8,7 @@ import static com.rethinkdb.RethinkDB.r; /** * Some tests demonstrating updating data. */ -public class UpdateIntegrationTest extends TestBase { +public class UpdateIntegrationLiveTest extends TestBase { /** * Create a table for the tests. */ From 2dc953dcadfb9a6dcda08d371967dbdc7ac6bac7 Mon Sep 17 00:00:00 2001 From: Michael Olayemi Date: Wed, 27 Sep 2023 16:32:18 +0000 Subject: [PATCH 091/193] Code Snippets in Java API Documentation (#14792) --- .../snippettag/GreetingsExternalSnippet.java | 18 ++++++++++ .../snippettag/GreetingsHighlightTag.java | 35 +++++++++++++++++++ .../snippettag/GreetingsInlineSnippet.java | 17 +++++++++ .../GreetingsReplaceAndLinkTag.java | 24 +++++++++++++ .../main/java/snippet-files/BinarySearch.java | 27 ++++++++++++++ .../java/snippet-files/application.properties | 4 +++ 6 files changed, 125 insertions(+) create mode 100644 core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsExternalSnippet.java create mode 100644 core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsHighlightTag.java create mode 100644 core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsInlineSnippet.java create mode 100644 core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsReplaceAndLinkTag.java create mode 100644 core-java-modules/core-java-documentation/src/main/java/snippet-files/BinarySearch.java create mode 100644 core-java-modules/core-java-documentation/src/main/java/snippet-files/application.properties diff --git a/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsExternalSnippet.java b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsExternalSnippet.java new file mode 100644 index 0000000000..6cf27b7acc --- /dev/null +++ b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsExternalSnippet.java @@ -0,0 +1,18 @@ +package com.baeldung.snippettag; + +/** + * + * External code snippet showing the loop process in binary search method. + * {@snippet class="BinarySearch" region="binary"} + * + * Time Zone + * {@snippet file="application.properties" region="zone"} + * + */ + +public class GreetingsExternalSnippet { + public void helloBinarySearch() { + System.out.println("Hi, it's great knowing that binary search uses a loop under the hood"); + } + +} diff --git a/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsHighlightTag.java b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsHighlightTag.java new file mode 100644 index 0000000000..03f30e1ad2 --- /dev/null +++ b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsHighlightTag.java @@ -0,0 +1,35 @@ +package com.baeldung.snippettag; + + +/** + * The code below shows a full highlighted line + * {@snippet : + * public void helloBaeldung() { + * System.out.println("Hello From Team Baeldung"); // @highlight + * } + * } + * + * highlighting a substring + * {@snippet : + * public void helloBaeldung() { + * System.out.println("Hello From Team Baeldung"); // @highlight substring="println" + * } + * } + * + * highlighting texts on multiple lines + * {@snippet : + * public void helloBaeldung() { + * System.out.println("Hello From Team Baeldung"); // @highlight region substring="println" + * String country = "USA"; + * System.out.println("Hello From Team " + country); // @end + * } + * } + * + */ + +public class GreetingsHighlightTag { + public void helloBaeldung() { + System.out.println("Hello From Team Baeldung"); + } + +} diff --git a/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsInlineSnippet.java b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsInlineSnippet.java new file mode 100644 index 0000000000..71876eecf6 --- /dev/null +++ b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsInlineSnippet.java @@ -0,0 +1,17 @@ +package com.baeldung.snippettag; + +/** + * The code below shows the content of {@code helloBaeldung()} method + * {@snippet : + * public void helloBaeldung() { + * System.out.println("Hello From Team Baeldung"); + * } + * } + */ + +public class GreetingsInlineSnippet { + public void helloBaeldung() { + System.out.println("Hello From Team Baeldung"); + } + +} diff --git a/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsReplaceAndLinkTag.java b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsReplaceAndLinkTag.java new file mode 100644 index 0000000000..7f6f1b72f7 --- /dev/null +++ b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsReplaceAndLinkTag.java @@ -0,0 +1,24 @@ +package com.baeldung.snippettag; + +/** + * + * Using the replace tag + * {@snippet : + * public void helloBaeldung() { + * System.out.println("Hello From Team Baeldung"); // @replace regex='".*"' replacement="..." + * } + * } + * Using the link tag + * {@snippet : + * public void helloBaeldung() { + * System.out.println("Hello From Team Baeldung"); // @link substring="System.out" target="System#out" + * } + * } + * + */ + +public class GreetingsReplaceAndLinkTag { + public void helloBaeldung() { + System.out.println("Hello From Team Baeldung"); + } +} diff --git a/core-java-modules/core-java-documentation/src/main/java/snippet-files/BinarySearch.java b/core-java-modules/core-java-documentation/src/main/java/snippet-files/BinarySearch.java new file mode 100644 index 0000000000..a5f6e565ac --- /dev/null +++ b/core-java-modules/core-java-documentation/src/main/java/snippet-files/BinarySearch.java @@ -0,0 +1,27 @@ + +public class BinarySearch { + + public int search(int[] list, int item) { + int index = Integer.MAX_VALUE; + int low = 0; + int high = list.length - 1; + // @start region="binary" + while (low <= high) { + int mid = high - low; + int guess = list[mid]; + if (guess == item) { + index = mid; + break; + } else if (guess > item) { + low = mid - 1; + } else { + low = mid + 1; + } + low++; + } + // @end region="binary" + + return index; + } + +} diff --git a/core-java-modules/core-java-documentation/src/main/java/snippet-files/application.properties b/core-java-modules/core-java-documentation/src/main/java/snippet-files/application.properties new file mode 100644 index 0000000000..a2aeefdb89 --- /dev/null +++ b/core-java-modules/core-java-documentation/src/main/java/snippet-files/application.properties @@ -0,0 +1,4 @@ +# @start region="zone" +local.timezone = GMT+1 +local.zip = 94123 +# @end region="zone" \ No newline at end of file From ca1e69ae862c4fe85ad9f3dd4d0adb1e5b1d3d56 Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Wed, 27 Sep 2023 22:34:49 +0530 Subject: [PATCH 092/193] Review Comments --- .../core-java-collections-array-list-2/README.md | 3 +-- core-java-modules/core-java-collections-array-list-2/pom.xml | 4 +++- .../AlternativeMultipeTypeList.java | 2 +- .../objecttypes => multipleobjecttypes}/CustomObject.java | 2 +- .../MultipleObjectTypeArrayList.java | 2 +- .../UserFunctionalInterface.java | 2 +- core-java-modules/pom.xml | 4 ++-- 7 files changed, 10 insertions(+), 9 deletions(-) rename core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/{multiple/objecttypes => multipleobjecttypes}/AlternativeMultipeTypeList.java (97%) rename core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/{multiple/objecttypes => multipleobjecttypes}/CustomObject.java (88%) rename core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/{multiple/objecttypes => multipleobjecttypes}/MultipleObjectTypeArrayList.java (97%) rename core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/{multiple/objecttypes => multipleobjecttypes}/UserFunctionalInterface.java (91%) diff --git a/core-java-modules/core-java-collections-array-list-2/README.md b/core-java-modules/core-java-collections-array-list-2/README.md index feef70a6dc..00c3e8d9b7 100644 --- a/core-java-modules/core-java-collections-array-list-2/README.md +++ b/core-java-modules/core-java-collections-array-list-2/README.md @@ -2,5 +2,4 @@ This module contains articles about the Java ArrayList collection -### Relevant Articles: -- [Create an ArrayList with Multiple Object Types](https://drafts.baeldung.com/create-an-arraylist-with-multiple-object-types/) \ No newline at end of file +### Relevant Articles: \ No newline at end of file diff --git a/core-java-modules/core-java-collections-array-list-2/pom.xml b/core-java-modules/core-java-collections-array-list-2/pom.xml index c9dd68b457..74fda13525 100644 --- a/core-java-modules/core-java-collections-array-list-2/pom.xml +++ b/core-java-modules/core-java-collections-array-list-2/pom.xml @@ -1,4 +1,6 @@ - + 4.0.0 core-java-collections-array-list-2 core-java-collections-array-list-2 diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/AlternativeMultipeTypeList.java similarity index 97% rename from core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java rename to core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/AlternativeMultipeTypeList.java index 6dd44e0ffa..f073ea4eab 100644 --- a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/AlternativeMultipeTypeList.java +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/AlternativeMultipeTypeList.java @@ -1,4 +1,4 @@ -package com.baeldung.list.multiple.objecttypes; +package com.baeldung.list.multipleobjecttypes; import java.util.ArrayList; import java.util.HashMap; diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/CustomObject.java similarity index 88% rename from core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java rename to core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/CustomObject.java index eec81523f4..b3ac4ffddb 100644 --- a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/CustomObject.java +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/CustomObject.java @@ -1,4 +1,4 @@ -package com.baeldung.list.multiple.objecttypes; +package com.baeldung.list.multipleobjecttypes; public class CustomObject { String classData; diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/MultipleObjectTypeArrayList.java similarity index 97% rename from core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java rename to core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/MultipleObjectTypeArrayList.java index 34610785cb..c5740c5cf8 100644 --- a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/MultipleObjectTypeArrayList.java +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/MultipleObjectTypeArrayList.java @@ -1,4 +1,4 @@ -package com.baeldung.list.multiple.objecttypes; +package com.baeldung.list.multipleobjecttypes; import java.math.BigInteger; import java.time.LocalDate; diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/UserFunctionalInterface.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/UserFunctionalInterface.java similarity index 91% rename from core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/UserFunctionalInterface.java rename to core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/UserFunctionalInterface.java index 7e39d5a152..6c0f8451da 100644 --- a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multiple/objecttypes/UserFunctionalInterface.java +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/UserFunctionalInterface.java @@ -1,4 +1,4 @@ -package com.baeldung.list.multiple.objecttypes; +package com.baeldung.list.multipleobjecttypes; import java.util.List; diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 88797a1bf3..c28fb1f78e 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -28,13 +28,14 @@ core-java-9-improvements - core-java-collections-array-list core-java-9-streams core-java-9 core-java-10 core-java-11 core-java-11-2 core-java-11-3 + core-java-collections-array-list + core-java-collections-array-list-2 core-java-collections-list-4 core-java-collections-list-5 core-java-collections-maps-4 @@ -177,7 +178,6 @@ core-java-collections-maps-6 core-java-records core-java-9-jigsaw - core-java-collections-array-list-2 From 5bc91182a507313d604e46ffa8c3c0ddb7a4aac5 Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Thu, 28 Sep 2023 11:13:45 +0530 Subject: [PATCH 093/193] Update pom.xml --- core-java-modules/core-java-collections-array-list-2/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-collections-array-list-2/pom.xml b/core-java-modules/core-java-collections-array-list-2/pom.xml index 74fda13525..4138939ea6 100644 --- a/core-java-modules/core-java-collections-array-list-2/pom.xml +++ b/core-java-modules/core-java-collections-array-list-2/pom.xml @@ -22,8 +22,9 @@ + 17 17 - \ No newline at end of file + From 20d6dbaef31bd1acb8e0a1baac09f214318b84af Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Thu, 28 Sep 2023 11:14:33 +0530 Subject: [PATCH 094/193] Updating spelling mistake --- .../list/multipleobjecttypes/AlternativeMultipeTypeList.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/AlternativeMultipeTypeList.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/AlternativeMultipeTypeList.java index f073ea4eab..5315147dff 100644 --- a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/AlternativeMultipeTypeList.java +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/AlternativeMultipeTypeList.java @@ -31,10 +31,10 @@ public class AlternativeMultipeTypeList { // List via Functional Interface List dataList = new ArrayList<>(); - Predicate myPricate = inputData -> (inputData instanceof String || inputData instanceof Integer); + Predicate myPredicate = inputData -> (inputData instanceof String || inputData instanceof Integer); UserFunctionalInterface myInterface = (listObj, data) -> { - if (myPricate.test(data)) + if (myPredicate.test(data)) listObj.add(data); else System.out.println("Skipping input as data not allowed for class: " + data.getClass() From 15ca62982ffaa9cef6fa0b366807669f75dd3209 Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Thu, 28 Sep 2023 11:21:46 +0530 Subject: [PATCH 095/193] Updated pom formatting --- core-java-modules/core-java-collections-array-list-2/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-collections-array-list-2/pom.xml b/core-java-modules/core-java-collections-array-list-2/pom.xml index 4138939ea6..d9cadfe622 100644 --- a/core-java-modules/core-java-collections-array-list-2/pom.xml +++ b/core-java-modules/core-java-collections-array-list-2/pom.xml @@ -27,4 +27,4 @@ 17 17 - + \ No newline at end of file From 27d104d197a4f6426a70223bec4b118ce1ef13c5 Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Thu, 28 Sep 2023 11:55:40 +0530 Subject: [PATCH 096/193] Update pom.xml --- core-java-modules/core-java-collections-array-list-2/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-collections-array-list-2/pom.xml b/core-java-modules/core-java-collections-array-list-2/pom.xml index d9cadfe622..44ecb0fffb 100644 --- a/core-java-modules/core-java-collections-array-list-2/pom.xml +++ b/core-java-modules/core-java-collections-array-list-2/pom.xml @@ -10,6 +10,7 @@ core-java-modules 0.0.1-SNAPSHOT + @@ -27,4 +28,4 @@ 17 17 - \ No newline at end of file + From a086bb8bcc3734f54a4e5876350496b78c81c781 Mon Sep 17 00:00:00 2001 From: hmdrz Date: Thu, 28 Sep 2023 10:52:56 +0330 Subject: [PATCH 097/193] #bael-6916:add @Override --- .../main/java/com/baeldung/camel/apache/file/FileProcessor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java index c9537d48de..a0571e7083 100644 --- a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java +++ b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java @@ -10,6 +10,7 @@ import org.springframework.stereotype.Component; @Component public class FileProcessor implements Processor { + @Override public void process(Exchange exchange) throws Exception { String originalFileName = (String) exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); From a06a2415dbc2ecc7b2e115df2008e264d6cab800 Mon Sep 17 00:00:00 2001 From: Anastasios Ioannidis Date: Thu, 28 Sep 2023 11:33:20 +0300 Subject: [PATCH 098/193] JAVA-13321 New Gateway-2 module with spring-cloud-gateway article's subjects --- .../gateway-2/README.md | 8 +- .../gateway-2/baeldung-realm.json | 2186 ----------------- .../spring-cloud-bootstrap/gateway-2/pom.xml | 132 +- .../CustomFiltersGatewayApplication.java | 15 - .../gatewayapp/config/WebClientConfig.java | 16 - .../ChainRequestGatewayFilterFactory.java | 89 - .../LoggingGatewayFilterFactory.java | 85 - .../ModifyRequestGatewayFilterFactory.java | 92 - .../ModifyResponseGatewayFilterFactory.java | 48 - .../ScrubResponseGatewayFilterFactory.java | 110 - .../global/FirstPreLastPostGlobalFilter.java | 31 - .../global/LoggingGlobalFilterProperties.java | 47 - .../LoggingGlobalFiltersConfigurations.java | 25 - .../global/LoggingGlobalPreFilter.java | 22 - .../routes/ServiceRouteConfiguration.java | 28 - .../SecondServiceApplication.java | 15 - .../web/SecondServiceRestController.java | 18 - .../service/ServiceApplication.java | 15 - .../service/web/ServiceRestController.java | 22 - .../rewrite/URLRewriteGatewayApplication.java | 25 - .../rewrite/routes/DynamicRewriteRoute.java | 43 - .../WebFilterGatewayApplication.java | 15 - .../config/ModifyBodyRouteConfig.java | 49 - .../RequestRateLimiterResolverConfig.java | 16 - .../main/resources/application-nosecurity.yml | 8 - .../src/main/resources/application-scrub.yml | 12 - .../resources/application-url-rewrite.yml | 11 - .../main/resources/application-webfilters.yml | 102 - ...ustomfilters-global-application.properties | 19 - .../secondservice-application.properties | 1 - .../resources/service-application.properties | 1 - .../gatewayapp/CustomFiltersLiveTest.java | 112 - ...bResponseGatewayFilterFactoryUnitTest.java | 61 - .../ScrubResponseGatewayFilterLiveTest.java | 135 - .../SecondServiceIntegrationTest.java | 28 - .../secondservice/SpringContextTest.java | 12 - .../service/ServiceIntegrationTest.java | 31 - .../service/SpringContextTest.java | 12 - .../LoggerListAppender.java | 2 +- .../URLRewriteGatewayApplicationLiveTest.java | 109 - .../RedisWebFilterFactoriesLiveTest.java | 64 - .../WebFilterFactoriesLiveTest.java | 136 - .../OAuth_Gateway.postman_collection.json | 203 -- .../src/test/resources/logback-test.xml | 2 +- 44 files changed, 34 insertions(+), 4179 deletions(-) delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/baeldung-realm.json delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersGatewayApplication.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/config/WebClientConfig.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ChainRequestGatewayFilterFactory.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/LoggingGatewayFilterFactory.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyRequestGatewayFilterFactory.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyResponseGatewayFilterFactory.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactory.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/FirstPreLastPostGlobalFilter.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFilterProperties.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFiltersConfigurations.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalPreFilter.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/routes/ServiceRouteConfiguration.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceApplication.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/web/SecondServiceRestController.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/ServiceApplication.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/web/ServiceRestController.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplication.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/routes/DynamicRewriteRoute.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/WebFilterGatewayApplication.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/ModifyBodyRouteConfig.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/RequestRateLimiterResolverConfig.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-nosecurity.yml delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-scrub.yml delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-url-rewrite.yml delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-webfilters.yml delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/customfilters-global-application.properties delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/secondservice-application.properties delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/service-application.properties delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersLiveTest.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactoryUnitTest.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterLiveTest.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceIntegrationTest.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SpringContextTest.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/ServiceIntegrationTest.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/SpringContextTest.java rename spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/{customfilters/gatewayapp/utils => introduction}/LoggerListAppender.java (88%) delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplicationLiveTest.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/RedisWebFilterFactoriesLiveTest.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/WebFilterFactoriesLiveTest.java delete mode 100644 spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/postman/OAuth_Gateway.postman_collection.json diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README.md b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README.md index 80315040c9..b76ae19f26 100644 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README.md +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/README.md @@ -4,10 +4,4 @@ This module contains articles about Spring Cloud Gateway ### Relevant Articles: -- [Exploring the New Spring Cloud Gateway](http://www.baeldung.com/spring-cloud-gateway) -- [Writing Custom Spring Cloud Gateway Filters](https://www.baeldung.com/spring-cloud-custom-gateway-filters) -- [Spring Cloud Gateway Routing Predicate Factories](https://www.baeldung.com/spring-cloud-gateway-routing-predicate-factories) -- [Spring Cloud Gateway WebFilter Factories](https://www.baeldung.com/spring-cloud-gateway-webfilter-factories) -- [Using Spring Cloud Gateway with OAuth 2.0 Patterns](https://www.baeldung.com/spring-cloud-gateway-oauth2) -- [URL Rewriting With Spring Cloud Gateway](https://www.baeldung.com/spring-cloud-gateway-url-rewriting) -- [Processing the Response Body in Spring Cloud Gateway](https://www.baeldung.com/spring-cloud-gateway-response-body) +- [Exploring the New Spring Cloud Gateway](http://www.baeldung.com/spring-cloud-gateway) \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/baeldung-realm.json b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/baeldung-realm.json deleted file mode 100644 index 4dad262568..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/baeldung-realm.json +++ /dev/null @@ -1,2186 +0,0 @@ -{ - "id": "baeldung", - "realm": "baeldung", - "notBefore": 0, - "revokeRefreshToken": false, - "refreshTokenMaxReuse": 0, - "accessTokenLifespan": 300, - "accessTokenLifespanForImplicitFlow": 900, - "ssoSessionIdleTimeout": 1800, - "ssoSessionMaxLifespan": 36000, - "ssoSessionIdleTimeoutRememberMe": 0, - "ssoSessionMaxLifespanRememberMe": 0, - "offlineSessionIdleTimeout": 2592000, - "offlineSessionMaxLifespanEnabled": false, - "offlineSessionMaxLifespan": 5184000, - "clientSessionIdleTimeout": 0, - "clientSessionMaxLifespan": 0, - "clientOfflineSessionIdleTimeout": 0, - "clientOfflineSessionMaxLifespan": 0, - "accessCodeLifespan": 60, - "accessCodeLifespanUserAction": 300, - "accessCodeLifespanLogin": 1800, - "actionTokenGeneratedByAdminLifespan": 43200, - "actionTokenGeneratedByUserLifespan": 300, - "enabled": true, - "sslRequired": "external", - "registrationAllowed": false, - "registrationEmailAsUsername": false, - "rememberMe": false, - "verifyEmail": false, - "loginWithEmailAllowed": true, - "duplicateEmailsAllowed": false, - "resetPasswordAllowed": false, - "editUsernameAllowed": false, - "bruteForceProtected": false, - "permanentLockout": false, - "maxFailureWaitSeconds": 900, - "minimumQuickLoginWaitSeconds": 60, - "waitIncrementSeconds": 60, - "quickLoginCheckMilliSeconds": 1000, - "maxDeltaTimeSeconds": 43200, - "failureFactor": 30, - "roles": { - "realm": [ - { - "id": "2f721e46-398b-43ff-845f-3c747f1f69f5", - "name": "standard", - "description": "Standard customer", - "composite": false, - "clientRole": false, - "containerId": "baeldung", - "attributes": {} - }, - { - "id": "b8b1cb49-c953-4cb0-acea-62b24c4b6d30", - "name": "silver", - "description": "Silver customer", - "composite": false, - "clientRole": false, - "containerId": "baeldung", - "attributes": {} - }, - { - "id": "f44f5ba9-2393-4d2a-b581-81cf8dd7f245", - "name": "gold", - "description": "Gold customers", - "composite": false, - "clientRole": false, - "containerId": "baeldung", - "attributes": {} - }, - { - "id": "3b6109f5-6e5a-4578-83c3-791ec3e2bf9e", - "name": "offline_access", - "description": "${role_offline-access}", - "composite": false, - "clientRole": false, - "containerId": "baeldung", - "attributes": {} - }, - { - "id": "0dd6a8c7-d669-4941-9ea1-521980e9c53f", - "name": "uma_authorization", - "description": "${role_uma_authorization}", - "composite": false, - "clientRole": false, - "containerId": "baeldung", - "attributes": {} - }, - { - "id": "ca962095-7f9b-49e2-a190-e391a0d4b704", - "name": "user", - "composite": false, - "clientRole": false, - "containerId": "baeldung", - "attributes": {} - } - ], - "client": { - "newClient": [], - "realm-management": [ - { - "id": "5d00243f-ceec-4b0c-995e-d86d5b8a0ae6", - "name": "view-clients", - "description": "${role_view-clients}", - "composite": true, - "composites": { - "client": { - "realm-management": [ - "query-clients" - ] - } - }, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "941612de-bd85-47a5-8dfa-37c270dde28c", - "name": "view-authorization", - "description": "${role_view-authorization}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "5ea9810d-63cc-4277-9b32-ba8a3d3c6091", - "name": "manage-realm", - "description": "${role_manage-realm}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "8b7b0dd8-350b-473e-b8cd-8acad34f1358", - "name": "query-clients", - "description": "${role_query-clients}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "0f8e5ee8-b014-4b7c-9b69-50f46abcba5f", - "name": "query-groups", - "description": "${role_query-groups}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "911b1489-9383-4734-b134-bf49bf992ce9", - "name": "manage-clients", - "description": "${role_manage-clients}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "5d48274c-bd6b-4c26-ad54-f1a2254beac0", - "name": "view-realm", - "description": "${role_view-realm}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "3ea43b64-316f-4693-8346-9ee78b24adaf", - "name": "manage-identity-providers", - "description": "${role_manage-identity-providers}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "49735614-96ec-49b2-98fe-3af9bcd1a33a", - "name": "create-client", - "description": "${role_create-client}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "e8f8c3cc-0ff1-4f72-a271-db6821a3cdb6", - "name": "manage-users", - "description": "${role_manage-users}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "387418b1-4f80-4b00-b9dd-805ca041f805", - "name": "view-identity-providers", - "description": "${role_view-identity-providers}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "427c27d4-521a-464b-a0df-16d7f537e8d5", - "name": "realm-admin", - "description": "${role_realm-admin}", - "composite": true, - "composites": { - "client": { - "realm-management": [ - "view-clients", - "view-authorization", - "query-groups", - "manage-realm", - "query-clients", - "manage-clients", - "view-realm", - "manage-identity-providers", - "create-client", - "manage-users", - "view-identity-providers", - "query-users", - "query-realms", - "view-users", - "impersonation", - "manage-authorization", - "manage-events", - "view-events" - ] - } - }, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "a574cf01-03e4-4573-ab9e-276d13a1ce8d", - "name": "query-users", - "description": "${role_query-users}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "c3a253a8-a1b6-4d38-9677-f728f32482ad", - "name": "query-realms", - "description": "${role_query-realms}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "f3cb93da-273e-419a-b2f4-93f09896abcf", - "name": "view-users", - "description": "${role_view-users}", - "composite": true, - "composites": { - "client": { - "realm-management": [ - "query-users", - "query-groups" - ] - } - }, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "6eedf2b7-50ef-4495-a89b-54aef751b7fa", - "name": "manage-authorization", - "description": "${role_manage-authorization}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "0332e99b-3dfc-4193-9e13-5728f8f3e6d6", - "name": "impersonation", - "description": "${role_impersonation}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "b690cb9c-0f4a-4be5-ade0-b40443d8149d", - "name": "view-events", - "description": "${role_view-events}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - }, - { - "id": "aac3def5-f193-4a6c-9065-1667a0746a8a", - "name": "manage-events", - "description": "${role_manage-events}", - "composite": false, - "clientRole": true, - "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", - "attributes": {} - } - ], - "security-admin-console": [], - "quotes-client": [], - "admin-cli": [], - "account-console": [], - "broker": [ - { - "id": "397b5703-4c81-48fd-a24c-a7e8177ef657", - "name": "read-token", - "description": "${role_read-token}", - "composite": false, - "clientRole": true, - "containerId": "4b9609f0-48d1-4e71-9381-2ecec08616f9", - "attributes": {} - } - ], - "account": [ - { - "id": "8daa8096-d14e-4d1c-ad1f-83f822016aa1", - "name": "manage-account", - "description": "${role_manage-account}", - "composite": true, - "composites": { - "client": { - "account": [ - "manage-account-links" - ] - } - }, - "clientRole": true, - "containerId": "12eebf0b-a3eb-49f8-9ecf-173cf8a00145", - "attributes": {} - }, - { - "id": "15f0d8be-932b-4565-8ad0-e8aa170093dd", - "name": "view-consent", - "description": "${role_view-consent}", - "composite": false, - "clientRole": true, - "containerId": "12eebf0b-a3eb-49f8-9ecf-173cf8a00145", - "attributes": {} - }, - { - "id": "c5aa697c-bf87-47c6-bd94-9121b72420b9", - "name": "view-applications", - "description": "${role_view-applications}", - "composite": false, - "clientRole": true, - "containerId": "12eebf0b-a3eb-49f8-9ecf-173cf8a00145", - "attributes": {} - }, - { - "id": "f0b3bbe4-aec1-4227-b9d3-2c314d612a04", - "name": "manage-consent", - "description": "${role_manage-consent}", - "composite": true, - "composites": { - "client": { - "account": [ - "view-consent" - ] - } - }, - "clientRole": true, - "containerId": "12eebf0b-a3eb-49f8-9ecf-173cf8a00145", - "attributes": {} - }, - { - "id": "948269c7-a69c-4c82-a7f3-88868713dfd9", - "name": "manage-account-links", - "description": "${role_manage-account-links}", - "composite": false, - "clientRole": true, - "containerId": "12eebf0b-a3eb-49f8-9ecf-173cf8a00145", - "attributes": {} - }, - { - "id": "aed18201-2433-4998-8fa3-0979b0b31c10", - "name": "view-profile", - "description": "${role_view-profile}", - "composite": false, - "clientRole": true, - "containerId": "12eebf0b-a3eb-49f8-9ecf-173cf8a00145", - "attributes": {} - } - ] - } - }, - "groups": [ - { - "id": "635c3314-f15f-4c02-bcb7-8739fd4c21b7", - "name": "golden_customers", - "path": "/golden_customers", - "attributes": {}, - "realmRoles": [ - "gold" - ], - "clientRoles": {}, - "subGroups": [] - }, - { - "id": "279c5ec4-0588-4884-91c1-2697ed5c9826", - "name": "silver_customers", - "path": "/silver_customers", - "attributes": {}, - "realmRoles": [ - "silver" - ], - "clientRoles": {}, - "subGroups": [] - } - ], - "defaultRoles": [ - "uma_authorization", - "offline_access" - ], - "requiredCredentials": [ - "password" - ], - "otpPolicyType": "totp", - "otpPolicyAlgorithm": "HmacSHA1", - "otpPolicyInitialCounter": 0, - "otpPolicyDigits": 6, - "otpPolicyLookAheadWindow": 1, - "otpPolicyPeriod": 30, - "otpSupportedApplications": [ - "FreeOTP", - "Google Authenticator" - ], - "webAuthnPolicyRpEntityName": "keycloak", - "webAuthnPolicySignatureAlgorithms": [ - "ES256" - ], - "webAuthnPolicyRpId": "", - "webAuthnPolicyAttestationConveyancePreference": "not specified", - "webAuthnPolicyAuthenticatorAttachment": "not specified", - "webAuthnPolicyRequireResidentKey": "not specified", - "webAuthnPolicyUserVerificationRequirement": "not specified", - "webAuthnPolicyCreateTimeout": 0, - "webAuthnPolicyAvoidSameAuthenticatorRegister": false, - "webAuthnPolicyAcceptableAaguids": [], - "webAuthnPolicyPasswordlessRpEntityName": "keycloak", - "webAuthnPolicyPasswordlessSignatureAlgorithms": [ - "ES256" - ], - "webAuthnPolicyPasswordlessRpId": "", - "webAuthnPolicyPasswordlessAttestationConveyancePreference": "not specified", - "webAuthnPolicyPasswordlessAuthenticatorAttachment": "not specified", - "webAuthnPolicyPasswordlessRequireResidentKey": "not specified", - "webAuthnPolicyPasswordlessUserVerificationRequirement": "not specified", - "webAuthnPolicyPasswordlessCreateTimeout": 0, - "webAuthnPolicyPasswordlessAvoidSameAuthenticatorRegister": false, - "webAuthnPolicyPasswordlessAcceptableAaguids": [], - "scopeMappings": [ - { - "clientScope": "offline_access", - "roles": [ - "offline_access" - ] - } - ], - "clientScopeMappings": { - "account": [ - { - "client": "account-console", - "roles": [ - "manage-account" - ] - } - ] - }, - "clients": [ - { - "id": "12eebf0b-a3eb-49f8-9ecf-173cf8a00145", - "clientId": "account", - "name": "${client_account}", - "rootUrl": "${authBaseUrl}", - "baseUrl": "/realms/baeldung/account/", - "surrogateAuthRequired": false, - "enabled": true, - "alwaysDisplayInConsole": false, - "clientAuthenticatorType": "client-secret", - "secret": "**********", - "defaultRoles": [ - "manage-account", - "view-profile" - ], - "redirectUris": [ - "/realms/baeldung/account/*" - ], - "webOrigins": [], - "notBefore": 0, - "bearerOnly": false, - "consentRequired": false, - "standardFlowEnabled": true, - "implicitFlowEnabled": false, - "directAccessGrantsEnabled": false, - "serviceAccountsEnabled": false, - "publicClient": false, - "frontchannelLogout": false, - "protocol": "openid-connect", - "attributes": {}, - "authenticationFlowBindingOverrides": {}, - "fullScopeAllowed": false, - "nodeReRegistrationTimeout": 0, - "defaultClientScopes": [ - "web-origins", - "role_list", - "roles", - "profile", - "email" - ], - "optionalClientScopes": [ - "address", - "phone", - "offline_access", - "microprofile-jwt" - ] - }, - { - "id": "8209784b-8540-43c2-aece-241acf12ea5a", - "clientId": "account-console", - "name": "${client_account-console}", - "rootUrl": "${authBaseUrl}", - "baseUrl": "/realms/baeldung/account/", - "surrogateAuthRequired": false, - "enabled": true, - "alwaysDisplayInConsole": false, - "clientAuthenticatorType": "client-secret", - "secret": "**********", - "redirectUris": [ - "/realms/baeldung/account/*" - ], - "webOrigins": [], - "notBefore": 0, - "bearerOnly": false, - "consentRequired": false, - "standardFlowEnabled": true, - "implicitFlowEnabled": false, - "directAccessGrantsEnabled": false, - "serviceAccountsEnabled": false, - "publicClient": true, - "frontchannelLogout": false, - "protocol": "openid-connect", - "attributes": { - "pkce.code.challenge.method": "S256" - }, - "authenticationFlowBindingOverrides": {}, - "fullScopeAllowed": false, - "nodeReRegistrationTimeout": 0, - "protocolMappers": [ - { - "id": "58395b96-1718-4787-8f92-74577e2bfc30", - "name": "audience resolve", - "protocol": "openid-connect", - "protocolMapper": "oidc-audience-resolve-mapper", - "consentRequired": false, - "config": {} - } - ], - "defaultClientScopes": [ - "web-origins", - "role_list", - "roles", - "profile", - "email" - ], - "optionalClientScopes": [ - "address", - "phone", - "offline_access", - "microprofile-jwt" - ] - }, - { - "id": "13d76feb-d762-4409-bb84-7a75bc395a61", - "clientId": "admin-cli", - "name": "${client_admin-cli}", - "surrogateAuthRequired": false, - "enabled": true, - "alwaysDisplayInConsole": false, - "clientAuthenticatorType": "client-secret", - "secret": "**********", - "redirectUris": [], - "webOrigins": [], - "notBefore": 0, - "bearerOnly": false, - "consentRequired": false, - "standardFlowEnabled": false, - "implicitFlowEnabled": false, - "directAccessGrantsEnabled": true, - "serviceAccountsEnabled": false, - "publicClient": true, - "frontchannelLogout": false, - "protocol": "openid-connect", - "attributes": {}, - "authenticationFlowBindingOverrides": {}, - "fullScopeAllowed": false, - "nodeReRegistrationTimeout": 0, - "defaultClientScopes": [ - "web-origins", - "role_list", - "roles", - "profile", - "email" - ], - "optionalClientScopes": [ - "address", - "phone", - "offline_access", - "microprofile-jwt" - ] - }, - { - "id": "4b9609f0-48d1-4e71-9381-2ecec08616f9", - "clientId": "broker", - "name": "${client_broker}", - "surrogateAuthRequired": false, - "enabled": true, - "alwaysDisplayInConsole": false, - "clientAuthenticatorType": "client-secret", - "secret": "**********", - "redirectUris": [], - "webOrigins": [], - "notBefore": 0, - "bearerOnly": false, - "consentRequired": false, - "standardFlowEnabled": true, - "implicitFlowEnabled": false, - "directAccessGrantsEnabled": false, - "serviceAccountsEnabled": false, - "publicClient": false, - "frontchannelLogout": false, - "protocol": "openid-connect", - "attributes": {}, - "authenticationFlowBindingOverrides": {}, - "fullScopeAllowed": false, - "nodeReRegistrationTimeout": 0, - "defaultClientScopes": [ - "web-origins", - "role_list", - "roles", - "profile", - "email" - ], - "optionalClientScopes": [ - "address", - "phone", - "offline_access", - "microprofile-jwt" - ] - }, - { - "id": "b88ce206-63d6-43b6-87c9-ea09d8c02f32", - "clientId": "newClient", - "surrogateAuthRequired": false, - "enabled": true, - "alwaysDisplayInConsole": false, - "clientAuthenticatorType": "client-secret", - "secret": "**********", - "redirectUris": [ - "http://localhost:8082/new-client/login/oauth2/code/custom", - "http://localhost:8089/", - "http://localhost:8089/auth/redirect/" - ], - "webOrigins": [ - "+" - ], - "notBefore": 0, - "bearerOnly": false, - "consentRequired": false, - "standardFlowEnabled": true, - "implicitFlowEnabled": true, - "directAccessGrantsEnabled": true, - "serviceAccountsEnabled": false, - "publicClient": false, - "frontchannelLogout": false, - "protocol": "openid-connect", - "attributes": { - "saml.assertion.signature": "false", - "saml.force.post.binding": "false", - "saml.multivalued.roles": "false", - "saml.encrypt": "false", - "saml.server.signature": "false", - "saml.server.signature.keyinfo.ext": "false", - "exclude.session.state.from.auth.response": "false", - "saml_force_name_id_format": "false", - "saml.client.signature": "false", - "tls.client.certificate.bound.access.tokens": "false", - "saml.authnstatement": "false", - "display.on.consent.screen": "false", - "saml.onetimeuse.condition": "false" - }, - "authenticationFlowBindingOverrides": {}, - "fullScopeAllowed": true, - "nodeReRegistrationTimeout": -1, - "defaultClientScopes": [ - "role_list", - "profile" - ], - "optionalClientScopes": [ - "web-origins", - "address", - "read", - "phone", - "roles", - "offline_access", - "microprofile-jwt", - "write", - "email" - ] - }, - { - "id": "5898f71f-b91e-4c3f-9c86-48de0e8665c4", - "clientId": "quotes-client", - "name": "Quotes Client", - "surrogateAuthRequired": false, - "enabled": true, - "alwaysDisplayInConsole": false, - "clientAuthenticatorType": "client-secret", - "secret": "0e082231-a70d-48e8-b8a5-fbfb743041b6", - "redirectUris": [ - "http://localhost:8082/*", - "http://localhost:8087/*" - ], - "webOrigins": [], - "notBefore": 0, - "bearerOnly": false, - "consentRequired": false, - "standardFlowEnabled": true, - "implicitFlowEnabled": false, - "directAccessGrantsEnabled": true, - "serviceAccountsEnabled": false, - "publicClient": false, - "frontchannelLogout": false, - "protocol": "openid-connect", - "attributes": { - "saml.assertion.signature": "false", - "saml.multivalued.roles": "false", - "saml.force.post.binding": "false", - "saml.encrypt": "false", - "saml.server.signature": "false", - "saml.server.signature.keyinfo.ext": "false", - "exclude.session.state.from.auth.response": "false", - "saml_force_name_id_format": "false", - "saml.client.signature": "false", - "tls.client.certificate.bound.access.tokens": "false", - "saml.authnstatement": "false", - "display.on.consent.screen": "false", - "saml.onetimeuse.condition": "false" - }, - "authenticationFlowBindingOverrides": {}, - "fullScopeAllowed": true, - "nodeReRegistrationTimeout": -1, - "protocolMappers": [ - { - "id": "008d32b5-ea7b-4739-89af-e90fe137bda9", - "name": "realm roles", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-realm-role-mapper", - "consentRequired": false, - "config": { - "user.attribute": "foo", - "access.token.claim": "true", - "claim.name": "realm_access.roles", - "jsonType.label": "String", - "multivalued": "true" - } - } - ], - "defaultClientScopes": [ - "web-origins", - "role_list", - "roles", - "profile", - "email" - ], - "optionalClientScopes": [ - "address", - "phone", - "offline_access", - "microprofile-jwt" - ] - }, - { - "id": "6a4bfbd0-576d-4778-af56-56f876647355", - "clientId": "realm-management", - "name": "${client_realm-management}", - "surrogateAuthRequired": false, - "enabled": true, - "alwaysDisplayInConsole": false, - "clientAuthenticatorType": "client-secret", - "secret": "**********", - "redirectUris": [], - "webOrigins": [], - "notBefore": 0, - "bearerOnly": true, - "consentRequired": false, - "standardFlowEnabled": true, - "implicitFlowEnabled": false, - "directAccessGrantsEnabled": false, - "serviceAccountsEnabled": false, - "publicClient": false, - "frontchannelLogout": false, - "protocol": "openid-connect", - "attributes": {}, - "authenticationFlowBindingOverrides": {}, - "fullScopeAllowed": false, - "nodeReRegistrationTimeout": 0, - "defaultClientScopes": [ - "web-origins", - "role_list", - "roles", - "profile", - "email" - ], - "optionalClientScopes": [ - "address", - "phone", - "offline_access", - "microprofile-jwt" - ] - }, - { - "id": "8e358d2f-b085-4243-8e6e-c175431e5eeb", - "clientId": "security-admin-console", - "name": "${client_security-admin-console}", - "rootUrl": "${authAdminUrl}", - "baseUrl": "/admin/baeldung/console/", - "surrogateAuthRequired": false, - "enabled": true, - "alwaysDisplayInConsole": false, - "clientAuthenticatorType": "client-secret", - "secret": "**********", - "redirectUris": [ - "/admin/baeldung/console/*" - ], - "webOrigins": [ - "+" - ], - "notBefore": 0, - "bearerOnly": false, - "consentRequired": false, - "standardFlowEnabled": true, - "implicitFlowEnabled": false, - "directAccessGrantsEnabled": false, - "serviceAccountsEnabled": false, - "publicClient": true, - "frontchannelLogout": false, - "protocol": "openid-connect", - "attributes": { - "pkce.code.challenge.method": "S256" - }, - "authenticationFlowBindingOverrides": {}, - "fullScopeAllowed": false, - "nodeReRegistrationTimeout": 0, - "protocolMappers": [ - { - "id": "9cfca9ee-493d-4b5e-8170-2d364149de59", - "name": "locale", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-attribute-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "locale", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "locale", - "jsonType.label": "String" - } - } - ], - "defaultClientScopes": [ - "web-origins", - "role_list", - "roles", - "profile", - "email" - ], - "optionalClientScopes": [ - "address", - "phone", - "offline_access", - "microprofile-jwt" - ] - } - ], - "clientScopes": [ - { - "id": "77c7e29d-1a22-4419-bbfb-4a62bb033449", - "name": "address", - "description": "OpenID Connect built-in scope: address", - "protocol": "openid-connect", - "attributes": { - "include.in.token.scope": "true", - "display.on.consent.screen": "true", - "consent.screen.text": "${addressScopeConsentText}" - }, - "protocolMappers": [ - { - "id": "94e1879d-b49e-4178-96e0-bf8d7f32c160", - "name": "address", - "protocol": "openid-connect", - "protocolMapper": "oidc-address-mapper", - "consentRequired": false, - "config": { - "user.attribute.formatted": "formatted", - "user.attribute.country": "country", - "user.attribute.postal_code": "postal_code", - "userinfo.token.claim": "true", - "user.attribute.street": "street", - "id.token.claim": "true", - "user.attribute.region": "region", - "access.token.claim": "true", - "user.attribute.locality": "locality" - } - } - ] - }, - { - "id": "b3526ac1-10e2-4344-8621-9c5a0853e97a", - "name": "email", - "description": "OpenID Connect built-in scope: email", - "protocol": "openid-connect", - "attributes": { - "include.in.token.scope": "true", - "display.on.consent.screen": "true", - "consent.screen.text": "${emailScopeConsentText}" - }, - "protocolMappers": [ - { - "id": "d30270dc-baa6-455a-8ff6-ddccf8a78d86", - "name": "email verified", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-property-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "emailVerified", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "email_verified", - "jsonType.label": "boolean" - } - }, - { - "id": "f5b1684d-e479-4134-8578-457fa64717da", - "name": "email", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-property-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "email", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "email", - "jsonType.label": "String" - } - } - ] - }, - { - "id": "c658ae14-e96a-4745-b21b-2ed5c4c63f5f", - "name": "microprofile-jwt", - "description": "Microprofile - JWT built-in scope", - "protocol": "openid-connect", - "attributes": { - "include.in.token.scope": "true", - "display.on.consent.screen": "false" - }, - "protocolMappers": [ - { - "id": "959521bc-5ffd-465b-95f2-5b0c20d1909c", - "name": "upn", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-property-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "username", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "upn", - "jsonType.label": "String" - } - }, - { - "id": "07b8550c-b298-4cce-9ffb-900182575b76", - "name": "groups", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-realm-role-mapper", - "consentRequired": false, - "config": { - "multivalued": "true", - "userinfo.token.claim": "true", - "user.attribute": "foo", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "groups", - "jsonType.label": "String" - } - } - ] - }, - { - "id": "569b3d44-4ecd-4768-a58c-70ff38f4b4fe", - "name": "offline_access", - "description": "OpenID Connect built-in scope: offline_access", - "protocol": "openid-connect", - "attributes": { - "consent.screen.text": "${offlineAccessScopeConsentText}", - "display.on.consent.screen": "true" - } - }, - { - "id": "a3e7b19d-df6c-437e-9eea-06fec1becb2f", - "name": "phone", - "description": "OpenID Connect built-in scope: phone", - "protocol": "openid-connect", - "attributes": { - "include.in.token.scope": "true", - "display.on.consent.screen": "true", - "consent.screen.text": "${phoneScopeConsentText}" - }, - "protocolMappers": [ - { - "id": "72a070f7-4363-4c88-8153-6fd2d12b9b04", - "name": "phone number verified", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-attribute-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "phoneNumberVerified", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "phone_number_verified", - "jsonType.label": "boolean" - } - }, - { - "id": "24b42c6d-a93c-4aa1-9a03-2a2b55954c13", - "name": "phone number", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-attribute-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "phoneNumber", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "phone_number", - "jsonType.label": "String" - } - } - ] - }, - { - "id": "ba8c9950-fd0b-4434-8be6-b58456d7b6d4", - "name": "profile", - "description": "OpenID Connect built-in scope: profile", - "protocol": "openid-connect", - "attributes": { - "include.in.token.scope": "true", - "display.on.consent.screen": "true", - "consent.screen.text": "${profileScopeConsentText}" - }, - "protocolMappers": [ - { - "id": "0a9ddd71-309c-40f0-8ea6-a0791070c6ed", - "name": "profile", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-attribute-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "profile", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "profile", - "jsonType.label": "String" - } - }, - { - "id": "fbf53bbd-1ad0-4bf8-8030-50f81696d8ee", - "name": "nickname", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-attribute-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "nickname", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "nickname", - "jsonType.label": "String" - } - }, - { - "id": "423be2cd-42c0-462e-9030-18f9b28ff2d3", - "name": "gender", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-attribute-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "gender", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "gender", - "jsonType.label": "String" - } - }, - { - "id": "53eb9006-4b81-474a-8b60-80f775d54b63", - "name": "picture", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-attribute-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "picture", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "picture", - "jsonType.label": "String" - } - }, - { - "id": "4d8bc82a-eaeb-499e-8eb2-0f1dcbe91699", - "name": "locale", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-attribute-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "locale", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "locale", - "jsonType.label": "String" - } - }, - { - "id": "d3b25485-4042-419d-afff-cfd63a76e229", - "name": "full name", - "protocol": "openid-connect", - "protocolMapper": "oidc-full-name-mapper", - "consentRequired": false, - "config": { - "id.token.claim": "true", - "access.token.claim": "true", - "userinfo.token.claim": "true" - } - }, - { - "id": "422cfa5a-f2f4-4f36-82df-91b47ae1ea50", - "name": "given name", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-property-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "firstName", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "given_name", - "jsonType.label": "String" - } - }, - { - "id": "3f2863c1-d98d-45b5-b08f-af9c4d9c10f8", - "name": "website", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-attribute-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "website", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "website", - "jsonType.label": "String" - } - }, - { - "id": "c98c063d-eee4-41a0-9130-595afd709d1f", - "name": "middle name", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-attribute-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "middleName", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "middle_name", - "jsonType.label": "String" - } - }, - { - "id": "8dbed80a-d672-4185-8dda-4bba2a56ec83", - "name": "family name", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-property-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "lastName", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "family_name", - "jsonType.label": "String" - } - }, - { - "id": "5e5c690c-93cf-489d-a054-b109eab8911b", - "name": "updated at", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-attribute-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "updatedAt", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "updated_at", - "jsonType.label": "String" - } - }, - { - "id": "3b985202-af8a-42f1-ac5f-0966a404f5d7", - "name": "birthdate", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-attribute-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "birthdate", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "birthdate", - "jsonType.label": "String" - } - }, - { - "id": "6eafd1b3-7121-4919-ad1e-039fa58acc32", - "name": "username", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-property-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "username", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "preferred_username", - "jsonType.label": "String" - } - }, - { - "id": "73cba925-8c31-443f-9601-b1514e6396c1", - "name": "zoneinfo", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-attribute-mapper", - "consentRequired": false, - "config": { - "userinfo.token.claim": "true", - "user.attribute": "zoneinfo", - "id.token.claim": "true", - "access.token.claim": "true", - "claim.name": "zoneinfo", - "jsonType.label": "String" - } - } - ] - }, - { - "id": "c1a2eb23-25c6-4be7-a791-bbdca99c83f7", - "name": "read", - "protocol": "openid-connect", - "attributes": { - "include.in.token.scope": "true", - "display.on.consent.screen": "true" - } - }, - { - "id": "18e141bf-dabe-4858-879c-dbc439cdead4", - "name": "role_list", - "description": "SAML role list", - "protocol": "saml", - "attributes": { - "consent.screen.text": "${samlRoleListScopeConsentText}", - "display.on.consent.screen": "true" - }, - "protocolMappers": [ - { - "id": "10cbe37f-0198-4d65-bc8a-bfe5ad8145d1", - "name": "role list", - "protocol": "saml", - "protocolMapper": "saml-role-list-mapper", - "consentRequired": false, - "config": { - "single": "false", - "attribute.nameformat": "Basic", - "attribute.name": "Role" - } - } - ] - }, - { - "id": "111ed87a-5fd3-4cee-96df-8dbfb88cfdc0", - "name": "roles", - "description": "OpenID Connect scope for add user roles to the access token", - "protocol": "openid-connect", - "attributes": { - "include.in.token.scope": "false", - "display.on.consent.screen": "true", - "consent.screen.text": "${rolesScopeConsentText}" - }, - "protocolMappers": [ - { - "id": "24924d8d-6071-4a93-b40f-326176cb335e", - "name": "realm roles", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-realm-role-mapper", - "consentRequired": false, - "config": { - "user.attribute": "foo", - "access.token.claim": "true", - "claim.name": "realm_access.roles", - "jsonType.label": "String", - "multivalued": "true" - } - }, - { - "id": "2f6a9bdf-3758-484c-996d-e4f93555559f", - "name": "audience resolve", - "protocol": "openid-connect", - "protocolMapper": "oidc-audience-resolve-mapper", - "consentRequired": false, - "config": {} - }, - { - "id": "804d4798-d9a3-4fd3-8b28-d12142e8cb3d", - "name": "client roles", - "protocol": "openid-connect", - "protocolMapper": "oidc-usermodel-client-role-mapper", - "consentRequired": false, - "config": { - "user.attribute": "foo", - "access.token.claim": "true", - "claim.name": "resource_access.${client_id}.roles", - "jsonType.label": "String", - "multivalued": "true" - } - } - ] - }, - { - "id": "51d49314-b511-43e0-9258-bfb873758a78", - "name": "web-origins", - "description": "OpenID Connect scope for add allowed web origins to the access token", - "protocol": "openid-connect", - "attributes": { - "include.in.token.scope": "false", - "display.on.consent.screen": "false", - "consent.screen.text": "" - }, - "protocolMappers": [ - { - "id": "2b384cd0-9e85-4a87-8eeb-2b480b0587b7", - "name": "allowed web origins", - "protocol": "openid-connect", - "protocolMapper": "oidc-allowed-origins-mapper", - "consentRequired": false, - "config": {} - } - ] - }, - { - "id": "c3e253fb-7361-47cf-9d4a-86245686fdf1", - "name": "write", - "protocol": "openid-connect", - "attributes": { - "include.in.token.scope": "true", - "display.on.consent.screen": "true" - } - } - ], - "defaultDefaultClientScopes": [ - "roles", - "role_list", - "web-origins", - "email", - "profile" - ], - "defaultOptionalClientScopes": [ - "offline_access", - "address", - "phone", - "microprofile-jwt" - ], - "browserSecurityHeaders": { - "contentSecurityPolicyReportOnly": "", - "xContentTypeOptions": "nosniff", - "xRobotsTag": "none", - "xFrameOptions": "SAMEORIGIN", - "contentSecurityPolicy": "frame-src 'self'; frame-ancestors 'self'; object-src 'none';", - "xXSSProtection": "1; mode=block", - "strictTransportSecurity": "max-age=31536000; includeSubDomains" - }, - "smtpServer": {}, - "eventsEnabled": false, - "eventsListeners": [ - "jboss-logging" - ], - "enabledEventTypes": [], - "adminEventsEnabled": false, - "adminEventsDetailsEnabled": false, - "components": { - "org.keycloak.services.clientregistration.policy.ClientRegistrationPolicy": [ - { - "id": "84305f42-4b6d-4b0a-ac7c-53e406e3ac63", - "name": "Allowed Client Scopes", - "providerId": "allowed-client-templates", - "subType": "authenticated", - "subComponents": {}, - "config": { - "allow-default-scopes": [ - "true" - ] - } - }, - { - "id": "c7c38a95-744f-4558-a403-9cf692fe1944", - "name": "Allowed Client Scopes", - "providerId": "allowed-client-templates", - "subType": "anonymous", - "subComponents": {}, - "config": { - "allow-default-scopes": [ - "true" - ] - } - }, - { - "id": "365b2899-befe-4417-b89b-562650ec4446", - "name": "Full Scope Disabled", - "providerId": "scope", - "subType": "anonymous", - "subComponents": {}, - "config": {} - }, - { - "id": "81c32244-7921-43e9-9356-a3469259b78c", - "name": "Trusted Hosts", - "providerId": "trusted-hosts", - "subType": "anonymous", - "subComponents": {}, - "config": { - "host-sending-registration-request-must-match": [ - "true" - ], - "client-uris-must-match": [ - "true" - ] - } - }, - { - "id": "d09b2147-afea-4f7f-a49c-0aec7eee10de", - "name": "Max Clients Limit", - "providerId": "max-clients", - "subType": "anonymous", - "subComponents": {}, - "config": { - "max-clients": [ - "200" - ] - } - }, - { - "id": "41ffde1b-72a2-416f-87a7-94989e940dc0", - "name": "Allowed Protocol Mapper Types", - "providerId": "allowed-protocol-mappers", - "subType": "authenticated", - "subComponents": {}, - "config": { - "allowed-protocol-mapper-types": [ - "saml-user-property-mapper", - "oidc-address-mapper", - "oidc-usermodel-property-mapper", - "oidc-full-name-mapper", - "oidc-sha256-pairwise-sub-mapper", - "saml-role-list-mapper", - "oidc-usermodel-attribute-mapper", - "saml-user-attribute-mapper" - ] - } - }, - { - "id": "76075388-2782-4656-a986-313493239a9f", - "name": "Consent Required", - "providerId": "consent-required", - "subType": "anonymous", - "subComponents": {}, - "config": {} - }, - { - "id": "3caaf57a-9cd7-48c1-b709-b40b887414f7", - "name": "Allowed Protocol Mapper Types", - "providerId": "allowed-protocol-mappers", - "subType": "anonymous", - "subComponents": {}, - "config": { - "allowed-protocol-mapper-types": [ - "oidc-usermodel-attribute-mapper", - "saml-user-property-mapper", - "oidc-usermodel-property-mapper", - "oidc-full-name-mapper", - "saml-user-attribute-mapper", - "oidc-address-mapper", - "saml-role-list-mapper", - "oidc-sha256-pairwise-sub-mapper" - ] - } - } - ], - "org.keycloak.keys.KeyProvider": [ - { - "id": "d67a940a-52e4-44a5-9f69-6ffdd67a188f", - "name": "rsa-generated", - "providerId": "rsa-generated", - "subComponents": {}, - "config": { - "priority": [ - "100" - ] - } - }, - { - "id": "48d40de3-6234-42e8-9449-f68f56abb54b", - "name": "aes-generated", - "providerId": "aes-generated", - "subComponents": {}, - "config": { - "priority": [ - "100" - ] - } - }, - { - "id": "52ea1c5d-2a30-459f-b66a-249f298b32f8", - "name": "hmac-generated", - "providerId": "hmac-generated", - "subComponents": {}, - "config": { - "priority": [ - "100" - ], - "algorithm": [ - "HS256" - ] - } - } - ] - }, - "internationalizationEnabled": false, - "supportedLocales": [], - "authenticationFlows": [ - { - "id": "b35b726e-c1cc-4a31-8670-8c858c088498", - "alias": "Handle Existing Account", - "description": "Handle what to do if there is existing account with same email/username like authenticated identity provider", - "providerId": "basic-flow", - "topLevel": false, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "idp-confirm-link", - "requirement": "REQUIRED", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "requirement": "REQUIRED", - "priority": 20, - "flowAlias": "Handle Existing Account - Alternatives - 0", - "userSetupAllowed": false, - "autheticatorFlow": true - } - ] - }, - { - "id": "b7cb4b8c-0064-4c6b-95ee-d7f50011bae7", - "alias": "Handle Existing Account - Alternatives - 0", - "description": "Subflow of Handle Existing Account with alternative executions", - "providerId": "basic-flow", - "topLevel": false, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "idp-email-verification", - "requirement": "ALTERNATIVE", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "requirement": "ALTERNATIVE", - "priority": 20, - "flowAlias": "Verify Existing Account by Re-authentication", - "userSetupAllowed": false, - "autheticatorFlow": true - } - ] - }, - { - "id": "2576bf21-a516-4e22-8ed8-8a1a3d35c06a", - "alias": "Verify Existing Account by Re-authentication", - "description": "Reauthentication of existing account", - "providerId": "basic-flow", - "topLevel": false, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "idp-username-password-form", - "requirement": "REQUIRED", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "requirement": "CONDITIONAL", - "priority": 20, - "flowAlias": "Verify Existing Account by Re-authentication - auth-otp-form - Conditional", - "userSetupAllowed": false, - "autheticatorFlow": true - } - ] - }, - { - "id": "867b0355-c2b0-4f4e-b535-09406e2bc086", - "alias": "Verify Existing Account by Re-authentication - auth-otp-form - Conditional", - "description": "Flow to determine if the auth-otp-form authenticator should be used or not.", - "providerId": "basic-flow", - "topLevel": false, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "conditional-user-configured", - "requirement": "REQUIRED", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "auth-otp-form", - "requirement": "REQUIRED", - "priority": 20, - "userSetupAllowed": false, - "autheticatorFlow": false - } - ] - }, - { - "id": "52e45a6a-292f-4a34-9c02-7f97d9997a9c", - "alias": "browser", - "description": "browser based authentication", - "providerId": "basic-flow", - "topLevel": true, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "auth-cookie", - "requirement": "ALTERNATIVE", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "auth-spnego", - "requirement": "DISABLED", - "priority": 20, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "identity-provider-redirector", - "requirement": "ALTERNATIVE", - "priority": 25, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "requirement": "ALTERNATIVE", - "priority": 30, - "flowAlias": "forms", - "userSetupAllowed": false, - "autheticatorFlow": true - } - ] - }, - { - "id": "ef818d24-fb06-418a-a093-16239068cb58", - "alias": "clients", - "description": "Base authentication for clients", - "providerId": "client-flow", - "topLevel": true, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "client-secret", - "requirement": "ALTERNATIVE", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "client-jwt", - "requirement": "ALTERNATIVE", - "priority": 20, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "client-secret-jwt", - "requirement": "ALTERNATIVE", - "priority": 30, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "client-x509", - "requirement": "ALTERNATIVE", - "priority": 40, - "userSetupAllowed": false, - "autheticatorFlow": false - } - ] - }, - { - "id": "f7864004-be4b-40f2-8534-454981f09f98", - "alias": "direct grant", - "description": "OpenID Connect Resource Owner Grant", - "providerId": "basic-flow", - "topLevel": true, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "direct-grant-validate-username", - "requirement": "REQUIRED", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "direct-grant-validate-password", - "requirement": "REQUIRED", - "priority": 20, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "requirement": "CONDITIONAL", - "priority": 30, - "flowAlias": "direct grant - direct-grant-validate-otp - Conditional", - "userSetupAllowed": false, - "autheticatorFlow": true - } - ] - }, - { - "id": "233225f2-78b0-4756-9568-a775ea7cc975", - "alias": "direct grant - direct-grant-validate-otp - Conditional", - "description": "Flow to determine if the direct-grant-validate-otp authenticator should be used or not.", - "providerId": "basic-flow", - "topLevel": false, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "conditional-user-configured", - "requirement": "REQUIRED", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "direct-grant-validate-otp", - "requirement": "REQUIRED", - "priority": 20, - "userSetupAllowed": false, - "autheticatorFlow": false - } - ] - }, - { - "id": "2787939c-3312-4d56-9d61-22a71947e154", - "alias": "docker auth", - "description": "Used by Docker clients to authenticate against the IDP", - "providerId": "basic-flow", - "topLevel": true, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "docker-http-basic-authenticator", - "requirement": "REQUIRED", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - } - ] - }, - { - "id": "c80ca473-6e65-4140-a9d1-035414546bfb", - "alias": "first broker login", - "description": "Actions taken after first broker login with identity provider account, which is not yet linked to any Keycloak account", - "providerId": "basic-flow", - "topLevel": true, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticatorConfig": "review profile config", - "authenticator": "idp-review-profile", - "requirement": "REQUIRED", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "requirement": "REQUIRED", - "priority": 20, - "flowAlias": "first broker login - Alternatives - 0", - "userSetupAllowed": false, - "autheticatorFlow": true - } - ] - }, - { - "id": "700a71e1-f176-432e-9e70-ccb06d539730", - "alias": "first broker login - Alternatives - 0", - "description": "Subflow of first broker login with alternative executions", - "providerId": "basic-flow", - "topLevel": false, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticatorConfig": "create unique user config", - "authenticator": "idp-create-user-if-unique", - "requirement": "ALTERNATIVE", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "requirement": "ALTERNATIVE", - "priority": 20, - "flowAlias": "Handle Existing Account", - "userSetupAllowed": false, - "autheticatorFlow": true - } - ] - }, - { - "id": "13cd2ee9-8ebb-4651-8a9d-535d4020d889", - "alias": "forms", - "description": "Username, password, otp and other auth forms.", - "providerId": "basic-flow", - "topLevel": false, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "auth-username-password-form", - "requirement": "REQUIRED", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "requirement": "CONDITIONAL", - "priority": 20, - "flowAlias": "forms - auth-otp-form - Conditional", - "userSetupAllowed": false, - "autheticatorFlow": true - } - ] - }, - { - "id": "80067ebf-72b9-4ba5-abc3-161dfdd53938", - "alias": "forms - auth-otp-form - Conditional", - "description": "Flow to determine if the auth-otp-form authenticator should be used or not.", - "providerId": "basic-flow", - "topLevel": false, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "conditional-user-configured", - "requirement": "REQUIRED", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "auth-otp-form", - "requirement": "REQUIRED", - "priority": 20, - "userSetupAllowed": false, - "autheticatorFlow": false - } - ] - }, - { - "id": "269354b1-7dd7-46ff-8a69-084cd2c7be80", - "alias": "http challenge", - "description": "An authentication flow based on challenge-response HTTP Authentication Schemes", - "providerId": "basic-flow", - "topLevel": true, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "no-cookie-redirect", - "requirement": "REQUIRED", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "basic-auth", - "requirement": "REQUIRED", - "priority": 20, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "basic-auth-otp", - "requirement": "DISABLED", - "priority": 30, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "auth-spnego", - "requirement": "DISABLED", - "priority": 40, - "userSetupAllowed": false, - "autheticatorFlow": false - } - ] - }, - { - "id": "c5fa64a0-e784-490f-8879-0e8a209e3636", - "alias": "registration", - "description": "registration flow", - "providerId": "basic-flow", - "topLevel": true, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "registration-page-form", - "requirement": "REQUIRED", - "priority": 10, - "flowAlias": "registration form", - "userSetupAllowed": false, - "autheticatorFlow": true - } - ] - }, - { - "id": "bc48f897-4d16-49a8-be70-183c7867e20a", - "alias": "registration form", - "description": "registration form", - "providerId": "form-flow", - "topLevel": false, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "registration-user-creation", - "requirement": "REQUIRED", - "priority": 20, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "registration-profile-action", - "requirement": "REQUIRED", - "priority": 40, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "registration-password-action", - "requirement": "REQUIRED", - "priority": 50, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "registration-recaptcha-action", - "requirement": "DISABLED", - "priority": 60, - "userSetupAllowed": false, - "autheticatorFlow": false - } - ] - }, - { - "id": "fddaba41-87b1-40d1-b147-f062c38e39ad", - "alias": "reset credentials", - "description": "Reset credentials for a user if they forgot their password or something", - "providerId": "basic-flow", - "topLevel": true, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "reset-credentials-choose-user", - "requirement": "REQUIRED", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "reset-credential-email", - "requirement": "REQUIRED", - "priority": 20, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "reset-password", - "requirement": "REQUIRED", - "priority": 30, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "requirement": "CONDITIONAL", - "priority": 40, - "flowAlias": "reset credentials - reset-otp - Conditional", - "userSetupAllowed": false, - "autheticatorFlow": true - } - ] - }, - { - "id": "6b9fa295-1eb4-48b0-a286-b17ebd6be7e1", - "alias": "reset credentials - reset-otp - Conditional", - "description": "Flow to determine if the reset-otp authenticator should be used or not.", - "providerId": "basic-flow", - "topLevel": false, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "conditional-user-configured", - "requirement": "REQUIRED", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - }, - { - "authenticator": "reset-otp", - "requirement": "REQUIRED", - "priority": 20, - "userSetupAllowed": false, - "autheticatorFlow": false - } - ] - }, - { - "id": "c890d4c4-e4e2-4618-b69d-8d30f8278965", - "alias": "saml ecp", - "description": "SAML ECP Profile Authentication Flow", - "providerId": "basic-flow", - "topLevel": true, - "builtIn": true, - "authenticationExecutions": [ - { - "authenticator": "http-basic-authenticator", - "requirement": "REQUIRED", - "priority": 10, - "userSetupAllowed": false, - "autheticatorFlow": false - } - ] - } - ], - "authenticatorConfig": [ - { - "id": "2b02fbe4-e05e-4238-bb0e-04da7d4efd4e", - "alias": "create unique user config", - "config": { - "require.password.update.after.registration": "false" - } - }, - { - "id": "07dd933b-ce95-4a7c-bd81-3efa24f9558c", - "alias": "review profile config", - "config": { - "update.profile.on.first.login": "missing" - } - } - ], - "requiredActions": [ - { - "alias": "CONFIGURE_TOTP", - "name": "Configure OTP", - "providerId": "CONFIGURE_TOTP", - "enabled": true, - "defaultAction": false, - "priority": 10, - "config": {} - }, - { - "alias": "terms_and_conditions", - "name": "Terms and Conditions", - "providerId": "terms_and_conditions", - "enabled": false, - "defaultAction": false, - "priority": 20, - "config": {} - }, - { - "alias": "UPDATE_PASSWORD", - "name": "Update Password", - "providerId": "UPDATE_PASSWORD", - "enabled": true, - "defaultAction": false, - "priority": 30, - "config": {} - }, - { - "alias": "UPDATE_PROFILE", - "name": "Update Profile", - "providerId": "UPDATE_PROFILE", - "enabled": true, - "defaultAction": false, - "priority": 40, - "config": {} - }, - { - "alias": "VERIFY_EMAIL", - "name": "Verify Email", - "providerId": "VERIFY_EMAIL", - "enabled": true, - "defaultAction": false, - "priority": 50, - "config": {} - }, - { - "alias": "update_user_locale", - "name": "Update User Locale", - "providerId": "update_user_locale", - "enabled": true, - "defaultAction": false, - "priority": 1000, - "config": {} - } - ], - "browserFlow": "browser", - "registrationFlow": "registration", - "directGrantFlow": "direct grant", - "resetCredentialsFlow": "reset credentials", - "clientAuthenticationFlow": "clients", - "dockerAuthenticationFlow": "docker auth", - "attributes": { - "clientOfflineSessionMaxLifespan": "0", - "clientSessionIdleTimeout": "0", - "clientSessionMaxLifespan": "0", - "clientOfflineSessionIdleTimeout": "0" - }, - "keycloakVersion": "11.0.2", - "userManagedAccessAllowed": false -} \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml index 520646cc7d..004e7fa302 100644 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml @@ -4,13 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 gateway-2 - spring-cloud-gateway + gateway-2 jar - com.baeldung.spring.cloud - spring-cloud-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../../parent-boot-2 @@ -44,107 +45,36 @@ org.springframework.cloud spring-cloud-starter-gateway - - - org.springframework.cloud - spring-cloud-starter-circuitbreaker-reactor-resilience4j - - - - org.springframework.boot - spring-boot-starter-data-redis-reactive - - - - it.ozimov - embedded-redis - ${redis.version} - test - - - org.hibernate - hibernate-validator-cdi - ${hibernate-validator.version} - - - javax.validation - validation-api - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-devtools - - - - org.springframework.boot - spring-boot-starter-oauth2-resource-server - - - org.springframework.boot - spring-boot-starter-oauth2-client - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - ${java.version} - ${java.version} - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - - - - - - gateway-url-rewrite - - - - org.springframework.boot - spring-boot-maven-plugin - - com.baeldung.springcloudgateway.rewrite.URLRewriteGatewayApplication - -Dspring.profiles.active=url-rewrite - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - 6.0.2.Final - 0.7.2 - 9.19 - + 2021.0.3 \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersGatewayApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersGatewayApplication.java deleted file mode 100644 index fae25bb7cc..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersGatewayApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.PropertySource; - -@SpringBootApplication -@PropertySource("classpath:customfilters-global-application.properties") -public class CustomFiltersGatewayApplication { - - public static void main(String[] args) { - SpringApplication.run(CustomFiltersGatewayApplication.class, args); - } - -} \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/config/WebClientConfig.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/config/WebClientConfig.java deleted file mode 100644 index 0589d8c321..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/config/WebClientConfig.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.reactive.function.client.WebClient; - -@Configuration -public class WebClientConfig { - - @Bean - WebClient client() { - return WebClient.builder() - .build(); - } - -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ChainRequestGatewayFilterFactory.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ChainRequestGatewayFilterFactory.java deleted file mode 100644 index f53b0a3c93..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ChainRequestGatewayFilterFactory.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories; - -import java.util.Arrays; -import java.util.List; -import java.util.Locale.LanguageRange; -import java.util.stream.Collectors; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cloud.gateway.filter.GatewayFilter; -import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; -import org.springframework.stereotype.Component; -import org.springframework.web.reactive.function.client.WebClient; - -import reactor.core.publisher.Mono; - -@Component -public class ChainRequestGatewayFilterFactory extends AbstractGatewayFilterFactory { - - final Logger logger = LoggerFactory.getLogger(ChainRequestGatewayFilterFactory.class); - - private final WebClient client; - - public ChainRequestGatewayFilterFactory(WebClient client) { - super(Config.class); - this.client = client; - } - - @Override - public List shortcutFieldOrder() { - return Arrays.asList("languageServiceEndpoint", "defaultLanguage"); - } - - @Override - public GatewayFilter apply(Config config) { - return (exchange, chain) -> { - return client.get() - .uri(config.getLanguageServiceEndpoint()) - .exchange() - .flatMap(response -> { - return (response.statusCode() - .is2xxSuccessful()) ? response.bodyToMono(String.class) : Mono.just(config.getDefaultLanguage()); - }) - .map(LanguageRange::parse) - .map(range -> { - exchange.getRequest() - .mutate() - .headers(h -> h.setAcceptLanguage(range)); - - String allOutgoingRequestLanguages = exchange.getRequest() - .getHeaders() - .getAcceptLanguage() - .stream() - .map(r -> r.getRange()) - .collect(Collectors.joining(",")); - - logger.info("Chain Request output - Request contains Accept-Language header: " + allOutgoingRequestLanguages); - - return exchange; - }) - .flatMap(chain::filter); - - }; - } - - public static class Config { - private String languageServiceEndpoint; - private String defaultLanguage; - - public Config() { - } - - public String getLanguageServiceEndpoint() { - return languageServiceEndpoint; - } - - public void setLanguageServiceEndpoint(String languageServiceEndpoint) { - this.languageServiceEndpoint = languageServiceEndpoint; - } - - public String getDefaultLanguage() { - return defaultLanguage; - } - - public void setDefaultLanguage(String defaultLanguage) { - this.defaultLanguage = defaultLanguage; - } - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/LoggingGatewayFilterFactory.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/LoggingGatewayFilterFactory.java deleted file mode 100644 index 900d36cc02..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/LoggingGatewayFilterFactory.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories; - -import java.util.Arrays; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cloud.gateway.filter.GatewayFilter; -import org.springframework.cloud.gateway.filter.OrderedGatewayFilter; -import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; -import org.springframework.stereotype.Component; - -import reactor.core.publisher.Mono; - -@Component -public class LoggingGatewayFilterFactory extends AbstractGatewayFilterFactory { - - final Logger logger = LoggerFactory.getLogger(LoggingGatewayFilterFactory.class); - - public static final String BASE_MSG = "baseMessage"; - public static final String PRE_LOGGER = "preLogger"; - public static final String POST_LOGGER = "postLogger"; - - public LoggingGatewayFilterFactory() { - super(Config.class); - } - - @Override - public List shortcutFieldOrder() { - return Arrays.asList(BASE_MSG, PRE_LOGGER, POST_LOGGER); - } - - @Override - public GatewayFilter apply(Config config) { - return new OrderedGatewayFilter((exchange, chain) -> { - if (config.isPreLogger()) - logger.info("Pre GatewayFilter logging: " + config.getBaseMessage()); - return chain.filter(exchange) - .then(Mono.fromRunnable(() -> { - if (config.isPostLogger()) - logger.info("Post GatewayFilter logging: " + config.getBaseMessage()); - })); - }, 1); - } - - public static class Config { - private String baseMessage; - private boolean preLogger; - private boolean postLogger; - - public Config() { - }; - - public Config(String baseMessage, boolean preLogger, boolean postLogger) { - super(); - this.baseMessage = baseMessage; - this.preLogger = preLogger; - this.postLogger = postLogger; - } - - public String getBaseMessage() { - return this.baseMessage; - } - - public boolean isPreLogger() { - return preLogger; - } - - public boolean isPostLogger() { - return postLogger; - } - - public void setBaseMessage(String baseMessage) { - this.baseMessage = baseMessage; - } - - public void setPreLogger(boolean preLogger) { - this.preLogger = preLogger; - } - - public void setPostLogger(boolean postLogger) { - this.postLogger = postLogger; - } - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyRequestGatewayFilterFactory.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyRequestGatewayFilterFactory.java deleted file mode 100644 index 5828f35a36..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyRequestGatewayFilterFactory.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Locale; -import java.util.Optional; -import java.util.stream.Collectors; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cloud.gateway.filter.GatewayFilter; -import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; -import org.springframework.stereotype.Component; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.web.server.ServerWebExchange; -import org.springframework.web.util.UriComponentsBuilder; - -@Component -public class ModifyRequestGatewayFilterFactory extends AbstractGatewayFilterFactory { - - final Logger logger = LoggerFactory.getLogger(ModifyRequestGatewayFilterFactory.class); - - public ModifyRequestGatewayFilterFactory() { - super(Config.class); - } - - @Override - public List shortcutFieldOrder() { - return Arrays.asList("defaultLocale"); - } - - @Override - public GatewayFilter apply(Config config) { - return (exchange, chain) -> { - if (exchange.getRequest() - .getHeaders() - .getAcceptLanguage() - .isEmpty()) { - - String queryParamLocale = exchange.getRequest() - .getQueryParams() - .getFirst("locale"); - - Locale requestLocale = Optional.ofNullable(queryParamLocale) - .map(l -> Locale.forLanguageTag(l)) - .orElse(config.getDefaultLocale()); - - exchange.getRequest() - .mutate() - .headers(h -> h.setAcceptLanguageAsLocales(Collections.singletonList(requestLocale))); - } - - String allOutgoingRequestLanguages = exchange.getRequest() - .getHeaders() - .getAcceptLanguage() - .stream() - .map(range -> range.getRange()) - .collect(Collectors.joining(",")); - - logger.info("Modify request output - Request contains Accept-Language header: {}", allOutgoingRequestLanguages); - - ServerWebExchange modifiedExchange = exchange.mutate() - .request(originalRequest -> originalRequest.uri(UriComponentsBuilder.fromUri(exchange.getRequest() - .getURI()) - .replaceQueryParams(new LinkedMultiValueMap()) - .build() - .toUri())) - .build(); - - logger.info("Removed all query params: {}", modifiedExchange.getRequest() - .getURI()); - - return chain.filter(modifiedExchange); - }; - } - - public static class Config { - private Locale defaultLocale; - - public Config() { - } - - public Locale getDefaultLocale() { - return defaultLocale; - } - - public void setDefaultLocale(String defaultLocale) { - this.defaultLocale = Locale.forLanguageTag(defaultLocale); - }; - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyResponseGatewayFilterFactory.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyResponseGatewayFilterFactory.java deleted file mode 100644 index f5efa69402..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ModifyResponseGatewayFilterFactory.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories; - -import java.util.Optional; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cloud.gateway.filter.GatewayFilter; -import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; -import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.stereotype.Component; - -import reactor.core.publisher.Mono; - -@Component -public class ModifyResponseGatewayFilterFactory extends AbstractGatewayFilterFactory { - - final Logger logger = LoggerFactory.getLogger(ModifyResponseGatewayFilterFactory.class); - - public ModifyResponseGatewayFilterFactory() { - super(Config.class); - } - - @Override - public GatewayFilter apply(Config config) { - return (exchange, chain) -> { - return chain.filter(exchange) - .then(Mono.fromRunnable(() -> { - ServerHttpResponse response = exchange.getResponse(); - - Optional.ofNullable(exchange.getRequest() - .getQueryParams() - .getFirst("locale")) - .ifPresent(qp -> { - String responseContentLanguage = response.getHeaders() - .getContentLanguage() - .getLanguage(); - - response.getHeaders() - .add("Bael-Custom-Language-Header", responseContentLanguage); - logger.info("Added custom header to Response"); - }); - })); - }; - } - - public static class Config { - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactory.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactory.java deleted file mode 100644 index dbe9a9fb4f..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactory.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories; - -import java.util.Arrays; -import java.util.List; -import java.util.regex.Pattern; - -import org.reactivestreams.Publisher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cloud.gateway.filter.GatewayFilter; -import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; -import org.springframework.cloud.gateway.filter.factory.rewrite.ModifyResponseBodyGatewayFilterFactory; -import org.springframework.cloud.gateway.filter.factory.rewrite.RewriteFunction; -import org.springframework.stereotype.Component; -import org.springframework.web.server.ServerWebExchange; - -import com.fasterxml.jackson.core.TreeNode; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.databind.node.TextNode; - -import reactor.core.publisher.Mono; - -@Component -public class ScrubResponseGatewayFilterFactory extends AbstractGatewayFilterFactory { - - final Logger logger = LoggerFactory.getLogger(ScrubResponseGatewayFilterFactory.class); - private ModifyResponseBodyGatewayFilterFactory modifyResponseBodyFilterFactory; - - public ScrubResponseGatewayFilterFactory(ModifyResponseBodyGatewayFilterFactory modifyResponseBodyFilterFactory) { - super(Config.class); - this.modifyResponseBodyFilterFactory = modifyResponseBodyFilterFactory; - } - - @Override - public List shortcutFieldOrder() { - return Arrays.asList("fields", "replacement"); - } - - - @Override - public GatewayFilter apply(Config config) { - - return modifyResponseBodyFilterFactory - .apply(c -> c.setRewriteFunction(JsonNode.class, JsonNode.class, new Scrubber(config))); - } - - public static class Config { - - private String fields; - private String replacement; - - - public String getFields() { - return fields; - } - public void setFields(String fields) { - this.fields = fields; - } - public String getReplacement() { - return replacement; - } - public void setReplacement(String replacement) { - this.replacement = replacement; - } - } - - - public static class Scrubber implements RewriteFunction { - private final Pattern fields; - private final String replacement; - - public Scrubber(Config config) { - this.fields = Pattern.compile(config.getFields()); - this.replacement = config.getReplacement(); - } - - @Override - public Publisher apply(ServerWebExchange t, JsonNode u) { - return Mono.just(scrubRecursively(u)); - } - - private JsonNode scrubRecursively(JsonNode u) { - if ( !u.isContainerNode()) { - return u; - } - - if ( u.isObject()) { - ObjectNode node = (ObjectNode)u; - node.fields().forEachRemaining((f) -> { - if ( fields.matcher(f.getKey()).matches() && f.getValue().isTextual()) { - f.setValue(TextNode.valueOf(replacement)); - } - else { - f.setValue(scrubRecursively(f.getValue())); - } - }); - } - else if ( u.isArray()) { - ArrayNode array = (ArrayNode)u; - for ( int i = 0 ; i < array.size() ; i++ ) { - array.set(i, scrubRecursively(array.get(i))); - } - } - - return u; - } - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/FirstPreLastPostGlobalFilter.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/FirstPreLastPostGlobalFilter.java deleted file mode 100644 index 687f3fe685..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/FirstPreLastPostGlobalFilter.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.global; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cloud.gateway.filter.GatewayFilterChain; -import org.springframework.cloud.gateway.filter.GlobalFilter; -import org.springframework.core.Ordered; -import org.springframework.stereotype.Component; -import org.springframework.web.server.ServerWebExchange; - -import reactor.core.publisher.Mono; - -@Component -public class FirstPreLastPostGlobalFilter implements GlobalFilter, Ordered { - - final Logger logger = LoggerFactory.getLogger(FirstPreLastPostGlobalFilter.class); - - @Override - public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { - logger.info("First Pre Global Filter"); - return chain.filter(exchange) - .then(Mono.fromRunnable(() -> { - logger.info("Last Post Global Filter"); - })); - } - - @Override - public int getOrder() { - return -1; - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFilterProperties.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFilterProperties.java deleted file mode 100644 index 4bf6453355..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFilterProperties.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.global; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties("logging.global") -public class LoggingGlobalFilterProperties { - - private boolean enabled; - private boolean requestHeaders; - private boolean requestBody; - private boolean responseHeaders; - private boolean responseBody; - - public boolean isEnabled() { - return enabled; - } - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - public boolean isRequestHeaders() { - return requestHeaders; - } - public void setRequestHeaders(boolean requestHeaders) { - this.requestHeaders = requestHeaders; - } - public boolean isRequestBody() { - return requestBody; - } - public void setRequestBody(boolean requestBody) { - this.requestBody = requestBody; - } - public boolean isResponseHeaders() { - return responseHeaders; - } - public void setResponseHeaders(boolean responseHeaders) { - this.responseHeaders = responseHeaders; - } - public boolean isResponseBody() { - return responseBody; - } - public void setResponseBody(boolean responseBody) { - this.responseBody = responseBody; - } - - - -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFiltersConfigurations.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFiltersConfigurations.java deleted file mode 100644 index 2dead8da3b..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalFiltersConfigurations.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.global; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cloud.gateway.filter.GlobalFilter; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import reactor.core.publisher.Mono; - -@Configuration -public class LoggingGlobalFiltersConfigurations { - - final Logger logger = LoggerFactory.getLogger(LoggingGlobalFiltersConfigurations.class); - - @Bean - public GlobalFilter postGlobalFilter() { - return (exchange, chain) -> { - return chain.filter(exchange) - .then(Mono.fromRunnable(() -> { - logger.info("Global Post Filter executed"); - })); - }; - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalPreFilter.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalPreFilter.java deleted file mode 100644 index 2bacf033db..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/global/LoggingGlobalPreFilter.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.global; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cloud.gateway.filter.GatewayFilterChain; -import org.springframework.cloud.gateway.filter.GlobalFilter; -import org.springframework.stereotype.Component; -import org.springframework.web.server.ServerWebExchange; - -import reactor.core.publisher.Mono; - -@Component -public class LoggingGlobalPreFilter implements GlobalFilter { - - final Logger logger = LoggerFactory.getLogger(LoggingGlobalPreFilter.class); - - @Override - public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { - logger.info("Global Pre Filter executed"); - return chain.filter(exchange); - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/routes/ServiceRouteConfiguration.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/routes/ServiceRouteConfiguration.java deleted file mode 100644 index 17d4827d93..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/routes/ServiceRouteConfiguration.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp.routes; - -import org.springframework.cloud.gateway.route.RouteLocator; -import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; -import org.springframework.context.annotation.Bean; - -import com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories.LoggingGatewayFilterFactory; -import com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories.LoggingGatewayFilterFactory.Config; - -/** - * Note: We want to keep this as an example of configuring a Route with a custom filter - * - * This corresponds with the properties configuration we have - */ -// @Configuration -public class ServiceRouteConfiguration { - - @Bean - public RouteLocator routes(RouteLocatorBuilder builder, LoggingGatewayFilterFactory loggingFactory) { - - return builder.routes() - .route("service_route_java_config", r -> r.path("/service/**") - .filters(f -> f.rewritePath("/service(?/?.*)", "$\\{segment}") - .filter(loggingFactory.apply(new Config("My Custom Message", true, true)))) - .uri("http://localhost:8081")) - .build(); - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceApplication.java deleted file mode 100644 index b65d0efbd6..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.secondservice; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.PropertySource; - -@SpringBootApplication -@PropertySource("classpath:secondservice-application.properties") -public class SecondServiceApplication { - - public static void main(String[] args) { - SpringApplication.run(SecondServiceApplication.class, args); - } - -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/web/SecondServiceRestController.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/web/SecondServiceRestController.java deleted file mode 100644 index 1ac44ba6b1..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/secondservice/web/SecondServiceRestController.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.secondservice.web; - -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import reactor.core.publisher.Mono; - -@RestController -public class SecondServiceRestController { - - @GetMapping("/resource/language") - public Mono> getResource() { - return Mono.just(ResponseEntity.ok() - .body("es")); - - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/ServiceApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/ServiceApplication.java deleted file mode 100644 index 1e2ffb63c2..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/ServiceApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.service; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.PropertySource; - -@SpringBootApplication -@PropertySource("classpath:service-application.properties") -public class ServiceApplication { - - public static void main(String[] args) { - SpringApplication.run(ServiceApplication.class, args); - } - -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/web/ServiceRestController.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/web/ServiceRestController.java deleted file mode 100644 index 3ca09f6853..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/customfilters/service/web/ServiceRestController.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.service.web; - -import java.util.Locale; - -import org.springframework.http.HttpHeaders; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import reactor.core.publisher.Mono; - -@RestController -public class ServiceRestController { - - @GetMapping("/resource") - public Mono> getResource() { - return Mono.just(ResponseEntity.ok() - .header(HttpHeaders.CONTENT_LANGUAGE, Locale.ENGLISH.getLanguage()) - .body("Service Resource")); - - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplication.java deleted file mode 100644 index 46541b4826..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplication.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - */ -package com.baeldung.springcloudgateway.rewrite; - -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.cloud.gateway.filter.GatewayFilter; - -import reactor.core.publisher.Mono; - -/** - * @author Baeldung - * - */ -@SpringBootApplication -public class URLRewriteGatewayApplication { - - public static void main(String[] args) { - new SpringApplicationBuilder(URLRewriteGatewayApplication.class) - .profiles("url-rewrite") - .run(args); - } - -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/routes/DynamicRewriteRoute.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/routes/DynamicRewriteRoute.java deleted file mode 100644 index 29d40d7021..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/rewrite/routes/DynamicRewriteRoute.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.springcloudgateway.rewrite.routes; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.cloud.gateway.route.RouteLocator; -import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.http.server.reactive.ServerHttpRequest; - -import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR; -import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.addOriginalRequestUrl; - -import java.util.Random; - -@Configuration -@Profile("url-rewrite") -public class DynamicRewriteRoute { - - @Value("${rewrite.backend.uri}") - private String backendUri; - private static Random rnd = new Random(); - - @Bean - public RouteLocator dynamicZipCodeRoute(RouteLocatorBuilder builder) { - return builder.routes() - .route("dynamicRewrite", r -> - r.path("/v2/zip/**") - .filters(f -> f.filter((exchange, chain) -> { - ServerHttpRequest req = exchange.getRequest(); - addOriginalRequestUrl(exchange, req.getURI()); - String path = req.getURI().getRawPath(); - String newPath = path.replaceAll( - "/v2/zip/(?.*)", - "/api/zip/${zipcode}-" + String.format("%03d", rnd.nextInt(1000))); - ServerHttpRequest request = req.mutate().path(newPath).build(); - exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, request.getURI()); - return chain.filter(exchange.mutate().request(request).build()); - })) - .uri(backendUri)) - .build(); - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/WebFilterGatewayApplication.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/WebFilterGatewayApplication.java deleted file mode 100644 index 9e212cc4bf..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/WebFilterGatewayApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.springcloudgateway.webfilters; - -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; - -@SpringBootApplication -public class WebFilterGatewayApplication { - - public static void main(String[] args) { - new SpringApplicationBuilder(WebFilterGatewayApplication.class) - .profiles("url-rewrite") - .run(args); - } - -} \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/ModifyBodyRouteConfig.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/ModifyBodyRouteConfig.java deleted file mode 100644 index 7b6188b66a..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/ModifyBodyRouteConfig.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.baeldung.springcloudgateway.webfilters.config; - -import org.springframework.cloud.gateway.route.RouteLocator; -import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.MediaType; - -import reactor.core.publisher.Mono; - -@Configuration -public class ModifyBodyRouteConfig { - - @Bean - public RouteLocator routes(RouteLocatorBuilder builder) { - return builder.routes() - .route("modify_request_body", r -> r.path("/post") - .filters(f -> f.modifyRequestBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE, - (exchange, s) -> Mono.just(new Hello(s.toUpperCase())))).uri("https://httpbin.org")) - .build(); - } - - @Bean - public RouteLocator responseRoutes(RouteLocatorBuilder builder) { - return builder.routes() - .route("modify_response_body", r -> r.path("/put/**") - .filters(f -> f.modifyResponseBody(String.class, Hello.class, MediaType.APPLICATION_JSON_VALUE, - (exchange, s) -> Mono.just(new Hello("New Body")))).uri("https://httpbin.org")) - .build(); - } - - static class Hello { - String message; - - public Hello() { } - - public Hello(String message) { - this.message = message; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/RequestRateLimiterResolverConfig.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/RequestRateLimiterResolverConfig.java deleted file mode 100644 index f80a742fa6..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/java/com/baeldung/springcloudgateway/webfilters/config/RequestRateLimiterResolverConfig.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.springcloudgateway.webfilters.config; - -import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import reactor.core.publisher.Mono; - -@Configuration -public class RequestRateLimiterResolverConfig { - - @Bean - KeyResolver userKeyResolver() { - return exchange -> Mono.just("1"); - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-nosecurity.yml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-nosecurity.yml deleted file mode 100644 index 40a52ded0f..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-nosecurity.yml +++ /dev/null @@ -1,8 +0,0 @@ -# Enable this profile to disable security -spring: - autoconfigure: - exclude: - - org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration - - org.springframework.boot.actuate.autoconfigure.ManagementSecurityAutoConfiguration - - org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration - - org.springframework.boot.actuate.autoconfigure.security.reactive.ReactiveManagementWebSecurityAutoConfiguration \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-scrub.yml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-scrub.yml deleted file mode 100644 index da7dfea0a7..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-scrub.yml +++ /dev/null @@ -1,12 +0,0 @@ -spring: - cloud: - gateway: - routes: - - id: rewrite_with_scrub - uri: ${rewrite.backend.uri:http://example.com} - predicates: - - Path=/v1/customer/** - filters: - - RewritePath=/v1/customer/(?.*),/api/$\{segment} - - ScrubResponse=ssn,*** - \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-url-rewrite.yml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-url-rewrite.yml deleted file mode 100644 index b2656151db..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-url-rewrite.yml +++ /dev/null @@ -1,11 +0,0 @@ -spring: - cloud: - gateway: - routes: - - id: rewrite_v1 - uri: ${rewrite.backend.uri:http://example.com} - predicates: - - Path=/v1/customer/** - filters: - - RewritePath=/v1/customer/(?.*),/api/$\{segment} - \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-webfilters.yml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-webfilters.yml deleted file mode 100644 index 3348cbbba0..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/application-webfilters.yml +++ /dev/null @@ -1,102 +0,0 @@ -logging: - level: - org.springframework.cloud.gateway: INFO - reactor.netty.http.client: INFO - -spring: - redis: - host: localhost - port: 6379 - cloud: - gateway: - routes: - - id: request_header_route - uri: https://httpbin.org - predicates: - - Path=/get/** - filters: - - AddRequestHeader=My-Header-Good,Good - - AddRequestHeader=My-Header-Remove,Remove - - AddRequestParameter=var, good - - AddRequestParameter=var2, remove - - MapRequestHeader=My-Header-Good, My-Header-Bad - - MapRequestHeader=My-Header-Set, My-Header-Bad - - SetRequestHeader=My-Header-Set, Set - - RemoveRequestHeader=My-Header-Remove - - RemoveRequestParameter=var2 - - PreserveHostHeader - - - id: response_header_route - uri: https://httpbin.org - predicates: - - Path=/header/post/** - filters: - - AddResponseHeader=My-Header-Good,Good - - AddResponseHeader=My-Header-Set,Good - - AddResponseHeader=My-Header-Rewrite, password=12345678 - - DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin - - AddResponseHeader=My-Header-Remove,Remove - - SetResponseHeader=My-Header-Set, Set - - RemoveResponseHeader=My-Header-Remove - - RewriteResponseHeader=My-Header-Rewrite, password=[^&]+, password=*** - - RewriteLocationResponseHeader=AS_IN_REQUEST, Location, , - - StripPrefix=1 - - - id: path_route - uri: https://httpbin.org - predicates: - - Path=/new/post/** - filters: - - RewritePath=/new(?/?.*), $\{segment} - - SetPath=/post - - - id: redirect_route - uri: https://httpbin.org - predicates: - - Path=/fake/post/** - filters: - - RedirectTo=302, https://httpbin.org - - - id: status_route - uri: https://httpbin.org - predicates: - - Path=/delete/** - filters: - - SetStatus=401 - - - id: size_route - uri: https://httpbin.org - predicates: - - Path=/anything - filters: - - name: RequestSize - args: - maxSize: 5000000 - - - id: retry_test - uri: https://httpbin.org - predicates: - - Path=/status/502 - filters: - - name: Retry - args: - retries: 3 - statuses: BAD_GATEWAY - methods: GET,POST - backoff: - firstBackoff: 10ms - maxBackoff: 50ms - factor: 2 - basedOnPreviousValue: false - - - id: request_rate_limiter - uri: https://httpbin.org - predicates: - - Path=/redis/get/** - filters: - - StripPrefix=1 - - name: RequestRateLimiter - args: - redis-rate-limiter.replenishRate: 10 - redis-rate-limiter.burstCapacity: 5 - key-resolver: "#{@userKeyResolver}" \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/customfilters-global-application.properties b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/customfilters-global-application.properties deleted file mode 100644 index 08421a0653..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/customfilters-global-application.properties +++ /dev/null @@ -1,19 +0,0 @@ -spring.cloud.gateway.routes[0].id=service_route -spring.cloud.gateway.routes[0].uri=http://localhost:8081 -spring.cloud.gateway.routes[0].predicates[0]=Path=/service/** -spring.cloud.gateway.routes[0].filters[0]=RewritePath=/service(?/?.*), $\{segment} -spring.cloud.gateway.routes[0].filters[1]=Logging=My Custom Message, true, true -# Or, as an alternative: -#spring.cloud.gateway.routes[0].filters[1].name=Logging -#spring.cloud.gateway.routes[0].filters[1].args[baseMessage]=My Custom Message -#spring.cloud.gateway.routes[0].filters[1].args[preLogger]=true -#spring.cloud.gateway.routes[0].filters[1].args[postLogger]=true - -spring.cloud.gateway.routes[0].filters[2]=ModifyResponse -spring.cloud.gateway.routes[0].filters[3]=ModifyRequest=en -spring.cloud.gateway.routes[0].filters[4]=ChainRequest=http://localhost:8082/resource/language, fr - -management.endpoints.web.exposure.include=* - -server.port=80 - diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/secondservice-application.properties b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/secondservice-application.properties deleted file mode 100644 index 3cf12afeb9..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/secondservice-application.properties +++ /dev/null @@ -1 +0,0 @@ -server.port=8082 diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/service-application.properties b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/service-application.properties deleted file mode 100644 index 4d360de145..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/main/resources/service-application.properties +++ /dev/null @@ -1 +0,0 @@ -server.port=8081 diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersLiveTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersLiveTest.java deleted file mode 100644 index f49f8c68b6..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersLiveTest.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.assertj.core.api.Condition; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.test.web.reactive.server.WebTestClient; -import org.springframework.test.web.reactive.server.WebTestClient.ResponseSpec; - -import com.baeldung.springcloudgateway.customfilters.gatewayapp.utils.LoggerListAppender; - -import ch.qos.logback.classic.spi.ILoggingEvent; - -/** - * This test requires: - * * the service in com.baeldung.service running - * * the 'second service' in com.baeldung.secondservice running - * - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -public class CustomFiltersLiveTest { - - @LocalServerPort - String port; - - @Autowired - private WebTestClient client; - - @BeforeEach - public void clearLogList() { - LoggerListAppender.clearEventList(); - client = WebTestClient.bindToServer() - .baseUrl("http://localhost:" + port) - .build(); - } - - @Test - public void whenCallServiceThroughGateway_thenAllConfiguredFiltersGetExecuted() { - ResponseSpec response = client.get() - .uri("/service/resource") - .exchange(); - - response.expectStatus() - .isOk() - .expectHeader() - .doesNotExist("Bael-Custom-Language-Header") - .expectBody(String.class) - .isEqualTo("Service Resource"); - - assertThat(LoggerListAppender.getEvents()) - // Global Pre Filter - .haveAtLeastOne(eventContains("Global Pre Filter executed")) - // Global Post Filter - .haveAtLeastOne(eventContains("Global Post Filter executed")) - // Global Pre and Post Filter - .haveAtLeastOne(eventContains("First Pre Global Filter")) - .haveAtLeastOne(eventContains("Last Post Global Filter")) - // Logging Filter Factory - .haveAtLeastOne(eventContains("Pre GatewayFilter logging: My Custom Message")) - .haveAtLeastOne(eventContains("Post GatewayFilter logging: My Custom Message")) - // Modify Request - .haveAtLeastOne(eventContains("Modify request output - Request contains Accept-Language header:")) - .haveAtLeastOne(eventContainsExcept("Removed all query params: ", "locale")) - // Modify Response - .areNot(eventContains("Added custom header to Response")) - // Chain Request - .haveAtLeastOne(eventContains("Chain Request output - Request contains Accept-Language header:")); - } - - @Test - public void givenRequestWithLocaleQueryParam_whenCallServiceThroughGateway_thenAllConfiguredFiltersGetExecuted() { - ResponseSpec response = client.get() - .uri("/service/resource?locale=en") - .exchange(); - - response.expectStatus() - .isOk() - .expectHeader() - .exists("Bael-Custom-Language-Header") - .expectBody(String.class) - .isEqualTo("Service Resource"); - - assertThat(LoggerListAppender.getEvents()) - // Modify Response - .haveAtLeastOne(eventContains("Added custom header to Response")) - .haveAtLeastOne(eventContainsExcept("Removed all query params: ", "locale")); - } - - /** - * This condition will be successful if the event contains a substring - */ - private Condition eventContains(String substring) { - return new Condition(entry -> (substring == null || (entry.getFormattedMessage() != null && entry.getFormattedMessage() - .contains(substring))), String.format("entry with message '%s'", substring)); - } - - /** - * This condition will be successful if the event contains a substring, but not another one - */ - private Condition eventContainsExcept(String substring, String except) { - return new Condition(entry -> (substring == null || (entry.getFormattedMessage() != null && entry.getFormattedMessage() - .contains(substring) - && !entry.getFormattedMessage() - .contains(except))), - String.format("entry with message '%s'", substring)); - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactoryUnitTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactoryUnitTest.java deleted file mode 100644 index 667aabaddc..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterFactoryUnitTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories; - -import static org.junit.jupiter.api.Assertions.*; - -import org.junit.jupiter.api.Test; - -import com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories.ScrubResponseGatewayFilterFactory.Config; -import com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories.ScrubResponseGatewayFilterFactory.Scrubber; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.core.TreeNode; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -import reactor.core.publisher.Mono; - -class ScrubResponseGatewayFilterFactoryUnitTest { - - private static final String JSON_WITH_FIELDS_TO_SCRUB = "{\r\n" - + " \"name\" : \"John Doe\",\r\n" - + " \"ssn\" : \"123-45-9999\",\r\n" - + " \"account\" : \"9999888877770000\"\r\n" - + "}"; - - - @Test - void givenJsonWithFieldsToScrub_whenApply_thenScrubFields() throws Exception{ - - JsonFactory jf = new JsonFactory(new ObjectMapper()); - JsonParser parser = jf.createParser(JSON_WITH_FIELDS_TO_SCRUB); - JsonNode root = parser.readValueAsTree(); - - Config config = new Config(); - config.setFields("ssn|account"); - config.setReplacement("*"); - Scrubber scrubber = new ScrubResponseGatewayFilterFactory.Scrubber(config); - - JsonNode scrubbed = Mono.from(scrubber.apply(null, root)).block(); - assertNotNull(scrubbed); - assertEquals("*", scrubbed.get("ssn").asText()); - } - - @Test - void givenJsonWithoutFieldsToScrub_whenApply_theBodUnchanged() throws Exception{ - - JsonFactory jf = new JsonFactory(new ObjectMapper()); - JsonParser parser = jf.createParser(JSON_WITH_FIELDS_TO_SCRUB); - JsonNode root = parser.readValueAsTree(); - - Config config = new Config(); - config.setFields("xxxx"); - config.setReplacement("*"); - Scrubber scrubber = new ScrubResponseGatewayFilterFactory.Scrubber(config); - - JsonNode scrubbed = Mono.from(scrubber.apply(null, root)).block(); - assertNotNull(scrubbed); - assertNotEquals("*", scrubbed.get("ssn").asText()); - } - -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterLiveTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterLiveTest.java deleted file mode 100644 index 8906af774e..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/filters/factories/ScrubResponseGatewayFilterLiveTest.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp.filters.factories; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.Collections; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.cloud.gateway.filter.factory.SetPathGatewayFilterFactory; -import org.springframework.cloud.gateway.route.RouteLocator; -import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Primary; -import org.springframework.http.MediaType; -import org.springframework.http.client.reactive.ReactorClientHttpConnector; -import org.springframework.security.config.web.server.ServerHttpSecurity; -import org.springframework.security.web.server.SecurityWebFilterChain; -import org.springframework.test.web.reactive.server.WebTestClient; - -import com.sun.net.httpserver.HttpServer; - -import reactor.netty.http.client.HttpClient; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -public class ScrubResponseGatewayFilterLiveTest { - - private static Logger log = LoggerFactory.getLogger(ScrubResponseGatewayFilterLiveTest.class); - - private static final String JSON_WITH_FIELDS_TO_SCRUB = "{\r\n" - + " \"name\" : \"John Doe\",\r\n" - + " \"ssn\" : \"123-45-9999\",\r\n" - + " \"account\" : \"9999888877770000\"\r\n" - + "}"; - - private static final String JSON_WITH_SCRUBBED_FIELDS = "{\r\n" - + " \"name\" : \"John Doe\",\r\n" - + " \"ssn\" : \"*\",\r\n" - + " \"account\" : \"9999888877770000\"\r\n" - + "}"; - - @LocalServerPort - String port; - - @Autowired - private WebTestClient client; - - @Autowired HttpServer server; - - @Test - public void givenRequestToScrubRoute_thenResponseScrubbed() { - - client.get() - .uri("/scrub") - .accept(MediaType.APPLICATION_JSON) - .exchange() - .expectStatus() - .is2xxSuccessful() - .expectHeader() - .contentType(MediaType.APPLICATION_JSON) - .expectBody() - .json(JSON_WITH_SCRUBBED_FIELDS); - } - - - @TestConfiguration - public static class TestRoutesConfiguration { - - - @Bean - public RouteLocator scrubSsnRoute(RouteLocatorBuilder builder, ScrubResponseGatewayFilterFactory scrubFilterFactory, SetPathGatewayFilterFactory pathFilterFactory, HttpServer server ) { - - log.info("[I92] Creating scrubSsnRoute..."); - - int mockServerPort = server.getAddress().getPort(); - ScrubResponseGatewayFilterFactory.Config config = new ScrubResponseGatewayFilterFactory.Config(); - config.setFields("ssn"); - config.setReplacement("*"); - - SetPathGatewayFilterFactory.Config pathConfig = new SetPathGatewayFilterFactory.Config(); - pathConfig.setTemplate("/customer"); - - return builder.routes() - .route("scrub_ssn", - r -> r.path("/scrub") - .filters( - f -> f - .filter(scrubFilterFactory.apply(config)) - .filter(pathFilterFactory.apply(pathConfig))) - .uri("http://localhost:" + mockServerPort )) - .build(); - } - - @Bean - public SecurityWebFilterChain testFilterChain(ServerHttpSecurity http ) { - - // @formatter:off - return http.authorizeExchange() - .anyExchange() - .permitAll() - .and() - .build(); - // @formatter:on - } - - @Bean - public HttpServer mockServer() throws IOException { - - log.info("[I48] Starting mock server..."); - - HttpServer server = HttpServer.create(new InetSocketAddress(0),0); - server.createContext("/customer", (exchange) -> { - exchange.getResponseHeaders().set("Content-Type", "application/json"); - - byte[] response = JSON_WITH_FIELDS_TO_SCRUB.getBytes("UTF-8"); - exchange.sendResponseHeaders(200,response.length); - exchange.getResponseBody().write(response); - }); - - server.setExecutor(null); - server.start(); - - log.info("[I65] Mock server started. port={}", server.getAddress().getPort()); - return server; - } - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceIntegrationTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceIntegrationTest.java deleted file mode 100644 index f4b3d0f00d..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SecondServiceIntegrationTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.secondservice; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration; -import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; -import org.springframework.test.web.reactive.server.WebTestClient; - -import com.baeldung.springcloudgateway.customfilters.secondservice.web.SecondServiceRestController; - -@WebFluxTest(controllers = SecondServiceRestController.class, - excludeAutoConfiguration = ReactiveSecurityAutoConfiguration.class) -public class SecondServiceIntegrationTest { - - @Autowired - private WebTestClient webClient; - - @Test - public void whenResourceLanguageEndpointCalled_thenRetrievesSpanishLanguageString() throws Exception { - this.webClient.get() - .uri("/resource/language") - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("es"); - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SpringContextTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SpringContextTest.java deleted file mode 100644 index eaf94c0a42..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/secondservice/SpringContextTest.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.secondservice; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest(classes = SecondServiceApplication.class) -public class SpringContextTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/ServiceIntegrationTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/ServiceIntegrationTest.java deleted file mode 100644 index 9990cd003c..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/ServiceIntegrationTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.service; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration; -import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; -import org.springframework.http.HttpHeaders; -import org.springframework.test.web.reactive.server.WebTestClient; - -import com.baeldung.springcloudgateway.customfilters.service.web.ServiceRestController; - -@WebFluxTest(controllers = ServiceRestController.class, - excludeAutoConfiguration = ReactiveSecurityAutoConfiguration.class) -public class ServiceIntegrationTest { - - @Autowired - private WebTestClient webClient; - - @Test - public void whenResourceEndpointCalled_thenRetrievesResourceStringWithContentLanguageHeader() throws Exception { - this.webClient.get() - .uri("/resource") - .exchange() - .expectStatus() - .isOk() - .expectHeader() - .valueEquals(HttpHeaders.CONTENT_LANGUAGE, "en") - .expectBody(String.class) - .isEqualTo("Service Resource"); - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/SpringContextTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/SpringContextTest.java deleted file mode 100644 index 2a9b322d5e..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/service/SpringContextTest.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.springcloudgateway.customfilters.service; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest(classes = ServiceApplication.class) -public class SpringContextTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/utils/LoggerListAppender.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/introduction/LoggerListAppender.java similarity index 88% rename from spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/utils/LoggerListAppender.java rename to spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/introduction/LoggerListAppender.java index 8e113b417b..33855cd15d 100644 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/utils/LoggerListAppender.java +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/introduction/LoggerListAppender.java @@ -1,4 +1,4 @@ -package com.baeldung.springcloudgateway.customfilters.gatewayapp.utils; +package com.baeldung.springcloudgateway.introduction; import java.util.ArrayList; import java.util.List; diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplicationLiveTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplicationLiveTest.java deleted file mode 100644 index 41fe37045c..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/rewrite/URLRewriteGatewayApplicationLiveTest.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.baeldung.springcloudgateway.rewrite; - -import static org.junit.Assert.assertTrue; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.OutputStream; -import java.net.InetSocketAddress; - -import org.junit.AfterClass; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.DynamicPropertyRegistry; -import org.springframework.test.context.DynamicPropertySource; -import org.springframework.test.web.reactive.server.WebTestClient; - -import com.sun.net.httpserver.HttpServer; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@ActiveProfiles({ "nosecurity", "url-rewrite" }) -class URLRewriteGatewayApplicationLiveTest { - - // NOTE for Eclipse users: By default, Eclipse will complain about com.sun.** classes. - // To solve this issue, follow instructions available at the : - // https://stackoverflow.com/questions/13155734/eclipse-cant-recognize-com-sun-net-httpserver-httpserver-package - private static HttpServer mockServer; - private static Logger log = LoggerFactory.getLogger(URLRewriteGatewayApplicationLiveTest.class); - - // Create a running HttpServer that echoes back the request URL. - private static HttpServer startTestServer() { - - try { - log.info("[I26] Starting mock server"); - mockServer = HttpServer.create(); - mockServer.bind(new InetSocketAddress(0), 0); - mockServer.createContext("/api", (xchg) -> { - String uri = xchg.getRequestURI() - .toString(); - log.info("[I23] Backend called: uri={}", uri); - xchg.getResponseHeaders() - .add("Content-Type", "text/plain"); - xchg.sendResponseHeaders(200, 0); - OutputStream os = xchg.getResponseBody(); - os.write(uri.getBytes()); - os.flush(); - os.close(); - }); - - mockServer.start(); - InetSocketAddress localAddr = mockServer.getAddress(); - log.info("[I36] mock server started: local address={}", localAddr); - - return mockServer; - } catch (Exception ex) { - throw new RuntimeException(ex); - } - - } - - // TIP: https://www.baeldung.com/spring-dynamicpropertysource - @DynamicPropertySource - static void registerBackendServer(DynamicPropertyRegistry registry) { - registry.add("rewrite.backend.uri", () -> { - HttpServer s = startTestServer(); - return "http://localhost:" + s.getAddress().getPort(); - }); - } - - @AfterClass - public static void stopMockBackend() throws Exception { - log.info("[I40] Shutdown mock http server"); - mockServer.stop(5); - } - - @LocalServerPort - private int localPort; - - @Test - void testWhenApiCall_thenRewriteSuccess(@Autowired WebTestClient webClient) { - webClient.get() - .uri("http://localhost:" + localPort + "/v1/customer/customer1") - .exchange() - .expectBody() - .consumeWith((result) -> { - String body = new String(result.getResponseBody()); - log.info("[I99] body={}", body); - assertEquals("/api/customer1", body); - }); - } - - @Test - void testWhenDslCall_thenRewriteSuccess(@Autowired WebTestClient webClient) { - webClient.get() - .uri("http://localhost:" + localPort + "/v2/zip/123456") - .exchange() - .expectBody() - .consumeWith((result) -> { - String body = new String(result.getResponseBody()); - log.info("[I99] body={}", body); - assertTrue(body.matches("/api/zip/123456-\\d{3}")); - }); - } - -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/RedisWebFilterFactoriesLiveTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/RedisWebFilterFactoriesLiveTest.java deleted file mode 100644 index a28eb68775..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/RedisWebFilterFactoriesLiveTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.baeldung.springcloudgateway.webfilters; - -import org.junit.After; -import org.junit.Before; -import org.junit.jupiter.api.RepeatedTest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ActiveProfiles; - -import redis.embedded.RedisServer; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@ActiveProfiles("webfilters") -@TestConfiguration -public class RedisWebFilterFactoriesLiveTest { - - private static final Logger LOGGER = LoggerFactory.getLogger(RedisWebFilterFactoriesLiveTest.class); - - private RedisServer redisServer; - - public RedisWebFilterFactoriesLiveTest() { - } - - @Before - public void postConstruct() { - this.redisServer = new RedisServer(6379); - redisServer.start(); - } - - @LocalServerPort - String port; - - @Autowired - private TestRestTemplate restTemplate; - - @Autowired - TestRestTemplate template; - - @RepeatedTest(25) - public void whenCallRedisGetThroughGateway_thenOKStatusOrIsReceived() { - String url = "http://localhost:" + port + "/redis/get"; - - ResponseEntity r = restTemplate.getForEntity(url, String.class); - // assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - - LOGGER.info("Received: status->{}, reason->{}, remaining->{}", - r.getStatusCodeValue(), r.getStatusCode().getReasonPhrase(), - r.getHeaders().get("X-RateLimit-Remaining")); - } - - @After - public void preDestroy() { - redisServer.stop(); - } - -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/WebFilterFactoriesLiveTest.java b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/WebFilterFactoriesLiveTest.java deleted file mode 100644 index 67e00a42fc..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/java/com/baeldung/springcloudgateway/webfilters/WebFilterFactoriesLiveTest.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.baeldung.springcloudgateway.webfilters; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import org.assertj.core.api.Condition; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.web.reactive.server.WebTestClient; -import org.springframework.test.web.reactive.server.WebTestClient.ResponseSpec; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@ActiveProfiles("webfilters") -public class WebFilterFactoriesLiveTest { - - @LocalServerPort - String port; - - @Autowired - private WebTestClient client; - - @Autowired - private TestRestTemplate restTemplate; - - @BeforeEach - public void configureClient() { - client = WebTestClient.bindToServer() - .baseUrl("http://localhost:" + port) - .build(); - } - - @Test - public void whenCallGetThroughGateway_thenAllHTTPRequestHeadersParametersAreSet() throws JSONException { - String url = "http://localhost:" + port + "/get"; - ResponseEntity response = restTemplate.getForEntity(url, String.class); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - - JSONObject json = new JSONObject(response.getBody()); - JSONObject headers = json.getJSONObject("headers"); - assertThat(headers.getString("My-Header-Good")).isEqualTo("Good"); - assertThat(headers.getString("My-Header-Bad")).isEqualTo("Good"); - assertThat(headers.getString("My-Header-Set")).isEqualTo("Set"); - assertTrue(headers.isNull("My-Header-Remove")); - JSONObject vars = json.getJSONObject("args"); - assertThat(vars.getString("var")).isEqualTo("good"); - } - - @Test - public void whenCallHeaderPostThroughGateway_thenAllHTTPResponseHeadersAreSet() { - ResponseSpec response = client.post() - .uri("/header/post") - .exchange(); - - response.expectStatus() - .isOk() - .expectHeader() - .valueEquals("My-Header-Rewrite", "password=***") - .expectHeader() - .valueEquals("My-Header-Set", "Set") - .expectHeader() - .valueEquals("My-Header-Good", "Good") - .expectHeader() - .doesNotExist("My-Header-Remove"); - } - - @Test - public void whenCallPostThroughGateway_thenBodyIsRetrieved() throws JSONException { - String url = "http://localhost:" + port + "/post"; - - HttpEntity entity = new HttpEntity<>("content", new HttpHeaders()); - - ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - - JSONObject json = new JSONObject(response.getBody()); - JSONObject data = json.getJSONObject("json"); - assertThat(data.getString("message")).isEqualTo("CONTENT"); - } - - @Test - public void whenCallPutThroughGateway_thenBodyIsRetrieved() throws JSONException { - String url = "http://localhost:" + port + "/put"; - - HttpEntity entity = new HttpEntity<>("CONTENT", new HttpHeaders()); - - ResponseEntity response = restTemplate.exchange(url, HttpMethod.PUT, entity, String.class); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - - JSONObject json = new JSONObject(response.getBody()); - assertThat(json.getString("message")).isEqualTo("New Body"); - } - - @Test - public void whenCallDeleteThroughGateway_thenIsUnauthorizedCodeIsSet() { - ResponseSpec response = client.delete() - .uri("/delete") - .exchange(); - - response.expectStatus() - .isUnauthorized(); - } - - @Test - public void whenCallFakePostThroughGateway_thenIsUnauthorizedCodeIsSet() { - ResponseSpec response = client.post() - .uri("/fake/post") - .exchange(); - - response.expectStatus() - .is3xxRedirection(); - } - - @Test - public void whenCallStatus504ThroughGateway_thenCircuitBreakerIsExecuted() throws JSONException { - String url = "http://localhost:" + port + "/status/504"; - ResponseEntity response = restTemplate.getForEntity(url, String.class); - - JSONObject json = new JSONObject(response.getBody()); - assertThat(json.getString("url")).contains("anything"); - } -} diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/postman/OAuth_Gateway.postman_collection.json b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/postman/OAuth_Gateway.postman_collection.json deleted file mode 100644 index ac920a271b..0000000000 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/postman/OAuth_Gateway.postman_collection.json +++ /dev/null @@ -1,203 +0,0 @@ -{ - "info": { - "_postman_id": "b3d00e23-c2cd-40ce-a90b-673efb25e5c0", - "name": "Baeldung - OAuth", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" - }, - "item": [ - { - "name": "Token", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "var jsonData = pm.response.json();\r", - "pm.environment.set(\"access_token\", jsonData.access_token);\r", - "pm.environment.set(\"refresh_token\", jsonData.refresh_token);\r", - "pm.environment.set(\"backend_token\", \"Bearer \" + jsonData.access_token);" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "urlencoded", - "urlencoded": [ - { - "key": "client_id", - "value": "{{client_id}}", - "type": "text" - }, - { - "key": "client_secret", - "value": "{{client_secret}}", - "type": "text" - }, - { - "key": "grant_type", - "value": "password", - "type": "text" - }, - { - "key": "scope", - "value": "email roles profile", - "type": "text" - }, - { - "key": "username", - "value": "maxwell.smart", - "type": "text" - }, - { - "key": "password", - "value": "1234", - "type": "text" - } - ] - }, - "url": { - "raw": "{{keycloack_base}}/token", - "host": [ - "{{keycloack_base}}" - ], - "path": [ - "token" - ] - } - }, - "response": [] - }, - { - "name": "Quote", - "protocolProfileBehavior": { - "disabledSystemHeaders": { - "accept": true - } - }, - "request": { - "auth": { - "type": "bearer", - "bearer": [ - { - "key": "token", - "value": "{{access_token}}", - "type": "string" - } - ] - }, - "method": "GET", - "header": [ - { - "key": "Accept", - "value": "application/json", - "type": "text" - } - ], - "url": { - "raw": "http://localhost:8085/quotes/:symbol", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "8085", - "path": [ - "quotes", - ":symbol" - ], - "variable": [ - { - "key": "symbol", - "value": "IBM" - } - ] - } - }, - "response": [] - }, - { - "name": "Quote via Gateway", - "protocolProfileBehavior": { - "disabledSystemHeaders": { - "accept": true - } - }, - "request": { - "auth": { - "type": "bearer", - "bearer": [ - { - "key": "token", - "value": "{{access_token}}", - "type": "string" - } - ] - }, - "method": "GET", - "header": [ - { - "key": "Accept", - "value": "application/json", - "type": "text" - } - ], - "url": { - "raw": "http://localhost:8086/quotes/:symbol", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "8086", - "path": [ - "quotes", - ":symbol" - ], - "variable": [ - { - "key": "symbol", - "value": "IBM" - } - ] - } - }, - "response": [] - } - ], - "event": [ - { - "listen": "prerequest", - "script": { - "type": "text/javascript", - "exec": [ - "" - ] - } - }, - { - "listen": "test", - "script": { - "type": "text/javascript", - "exec": [ - "" - ] - } - } - ], - "variable": [ - { - "key": "keycloack_base", - "value": "http://localhost:8083/auth/realms/baeldung/protocol/openid-connect" - }, - { - "key": "client_id", - "value": "quotes-client" - }, - { - "key": "client_secret", - "value": "56be94c8-b20a-4374-899c-e39cb022d3f8" - } - ] -} \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/resources/logback-test.xml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/resources/logback-test.xml index 6980d119b1..90c8f570aa 100644 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/resources/logback-test.xml +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/src/test/resources/logback-test.xml @@ -1,7 +1,7 @@ + class="com.baeldung.springcloudgateway.introduction.LoggerListAppender"> From ac054b44bba5567e2e1d581d9395cb9817b9f4eb Mon Sep 17 00:00:00 2001 From: Anastasios Ioannidis Date: Thu, 28 Sep 2023 11:49:20 +0300 Subject: [PATCH 099/193] JAVA-13321 Clean up --- .../spring-cloud-bootstrap/gateway-2/pom.xml | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml index 004e7fa302..3d64edc338 100644 --- a/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml +++ b/spring-cloud-modules/spring-cloud-bootstrap/gateway-2/pom.xml @@ -47,32 +47,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - 2021.0.3 From eabaf2764d28b88a45f4fb725128c3b4de747e8b Mon Sep 17 00:00:00 2001 From: Eugene Kovko <37694937+eukovko@users.noreply.github.com> Date: Thu, 28 Sep 2023 18:04:54 +0200 Subject: [PATCH 100/193] BAEL-6773: Get the OS Username in Java (#14848) * BAEL-6773: Removed Ignored Tests * BAEL-6773: Initializing a New Module * BAEL-6773: user.name Property Example * BAEL-6773: Removed Unused Dependencies --- core-java-modules/core-java-os-2/.gitignore | 26 ++++++++ core-java-modules/core-java-os-2/README.md | 7 ++ core-java-modules/core-java-os-2/pom.xml | 42 ++++++++++++ .../baeldung/system/EnvironmentExample.java | 9 +++ .../baeldung/system/PropertiesExample.java | 19 ++++++ .../system/WhenDetectingOSUnitTest.java | 25 -------- .../system/exit/SystemExitUnitTest.java | 64 ------------------- 7 files changed, 103 insertions(+), 89 deletions(-) create mode 100644 core-java-modules/core-java-os-2/.gitignore create mode 100644 core-java-modules/core-java-os-2/README.md create mode 100644 core-java-modules/core-java-os-2/pom.xml create mode 100644 core-java-modules/core-java-os-2/src/main/java/com/baeldung/system/EnvironmentExample.java create mode 100644 core-java-modules/core-java-os-2/src/main/java/com/baeldung/system/PropertiesExample.java delete mode 100644 core-java-modules/core-java-os/src/test/java/com/baeldung/system/WhenDetectingOSUnitTest.java delete mode 100644 core-java-modules/core-java-os/src/test/java/com/baeldung/system/exit/SystemExitUnitTest.java diff --git a/core-java-modules/core-java-os-2/.gitignore b/core-java-modules/core-java-os-2/.gitignore new file mode 100644 index 0000000000..3de4cc647e --- /dev/null +++ b/core-java-modules/core-java-os-2/.gitignore @@ -0,0 +1,26 @@ +*.class + +0.* + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* +.resourceCache + +# Packaged files # +*.jar +*.war +*.ear + +# Files generated by integration tests +*.txt +backup-pom.xml +/bin/ +/temp + +#IntelliJ specific +.idea/ +*.iml \ No newline at end of file diff --git a/core-java-modules/core-java-os-2/README.md b/core-java-modules/core-java-os-2/README.md new file mode 100644 index 0000000000..fa9f504184 --- /dev/null +++ b/core-java-modules/core-java-os-2/README.md @@ -0,0 +1,7 @@ +## Core Java OS + +This module contains articles about working with the operating system (OS) in Java + +### Relevant Articles: + + diff --git a/core-java-modules/core-java-os-2/pom.xml b/core-java-modules/core-java-os-2/pom.xml new file mode 100644 index 0000000000..53fdafa7d4 --- /dev/null +++ b/core-java-modules/core-java-os-2/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + core-java-os + core-java-os + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + + + core-java-os + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + 1.9 + 1.9 + + + \ No newline at end of file diff --git a/core-java-modules/core-java-os-2/src/main/java/com/baeldung/system/EnvironmentExample.java b/core-java-modules/core-java-os-2/src/main/java/com/baeldung/system/EnvironmentExample.java new file mode 100644 index 0000000000..2557c0cfa8 --- /dev/null +++ b/core-java-modules/core-java-os-2/src/main/java/com/baeldung/system/EnvironmentExample.java @@ -0,0 +1,9 @@ +package com.baeldung.system; + +public class EnvironmentExample { + public void getUserName() { + String username = System.getenv("USERNAME"); + System.out.println("User: " + username); + } + +} diff --git a/core-java-modules/core-java-os-2/src/main/java/com/baeldung/system/PropertiesExample.java b/core-java-modules/core-java-os-2/src/main/java/com/baeldung/system/PropertiesExample.java new file mode 100644 index 0000000000..cb203c40c6 --- /dev/null +++ b/core-java-modules/core-java-os-2/src/main/java/com/baeldung/system/PropertiesExample.java @@ -0,0 +1,19 @@ +package com.baeldung.system; + +public class PropertiesExample { + public void getUserName() { + String username = System.getProperty("user.name"); + System.out.println("User: " + username); + } + + public void getCustomProp() { + String customProperty = System.getProperty("custom.prop"); + System.out.println("Custom property: " + customProperty); + } + + public void getCustomPropWithFallback() { + String customProperty = System.getProperty("non-existent-property", "default value"); + System.out.println("Custom property: " + customProperty); + } + +} diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/system/WhenDetectingOSUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/system/WhenDetectingOSUnitTest.java deleted file mode 100644 index 27a6dd43c6..0000000000 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/system/WhenDetectingOSUnitTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.system; - -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class WhenDetectingOSUnitTest { - - private DetectOS os = new DetectOS(); - - @Test - public void whenUsingSystemProperty_shouldReturnOS() { - String expected = "Windows 10"; - String actual = os.getOperatingSystem(); - Assert.assertEquals(expected, actual); - } - - @Test - public void whenUsingSystemUtils_shouldReturnOS() { - String expected = "Windows 10"; - String actual = os.getOperatingSystemSystemUtils(); - Assert.assertEquals(expected, actual); - } -} diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/system/exit/SystemExitUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/system/exit/SystemExitUnitTest.java deleted file mode 100644 index 8ad3f75623..0000000000 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/system/exit/SystemExitUnitTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.baeldung.system.exit; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import java.security.Permission; - -import static org.junit.Assert.assertEquals; - -@Ignore("This test is ignored because it tests deprecated code") -public class SystemExitUnitTest { - - private SecurityManager securityManager; - private SystemExitExample example; - - @Before - public void setUp() { - example = new SystemExitExample(); - securityManager = System.getSecurityManager(); - System.setSecurityManager(new NoExitSecurityManager()); - } - - @After - public void tearDown() throws Exception { - System.setSecurityManager(securityManager); - } - - @Test - public void testExit() throws Exception { - try { - example.readFile(); - } catch (ExitException e) { - assertEquals("Exit status", 2, e.status); - } - } - - protected static class ExitException extends SecurityException { - - private static final long serialVersionUID = 1L; - public final int status; - - public ExitException(int status) { - this.status = status; - } - } - - private static class NoExitSecurityManager extends SecurityManager { - @Override - public void checkPermission(Permission perm) { - } - - @Override - public void checkPermission(Permission perm, Object context) { - } - - @Override - public void checkExit(int status) { - super.checkExit(status); - throw new ExitException(status); - } - } -} \ No newline at end of file From 204555a479341a07a14f3fc220a9c7ca6d60881e Mon Sep 17 00:00:00 2001 From: Vlad <48989383+VladGaluska@users.noreply.github.com> Date: Thu, 28 Sep 2023 19:05:39 +0300 Subject: [PATCH 101/193] Bael 6961 Unnamed Patterns and Variables (#14829) * BAEL-6961 Added first code snippets * Added code for article * Added debug configuration * Build trigger --------- Co-authored-by: Vlad --- core-java-modules/core-java-21/README.md | 2 +- core-java-modules/core-java-21/pom.xml | 26 +++- .../com/baeldung/unnamed/variables/Car.java | 11 ++ .../unnamed/variables/UnnamedPatterns.java | 50 +++++++ .../unnamed/variables/UnnamedVariables.java | 134 ++++++++++++++++++ .../unnamed/variables/CarScenario.java | 13 ++ .../variables/UnnamedPatternsUnitTest.java | 44 ++++++ .../variables/UnnamedVariablesUnitTest.java | 93 ++++++++++++ 8 files changed, 366 insertions(+), 7 deletions(-) create mode 100644 core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/Car.java create mode 100644 core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedPatterns.java create mode 100644 core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedVariables.java create mode 100644 core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/CarScenario.java create mode 100644 core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedPatternsUnitTest.java create mode 100644 core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedVariablesUnitTest.java diff --git a/core-java-modules/core-java-21/README.md b/core-java-modules/core-java-21/README.md index 2e7130c906..04f99a244b 100644 --- a/core-java-modules/core-java-21/README.md +++ b/core-java-modules/core-java-21/README.md @@ -1,2 +1,2 @@ ## Relevant Articles -- [Sequenced Collections in Java 21](https://www.baeldung.com/java-21-sequenced-collections) +- [Sequenced Collections in Java 21](https://www.baeldung.com/java-21-sequenced-collections) \ No newline at end of file diff --git a/core-java-modules/core-java-21/pom.xml b/core-java-modules/core-java-21/pom.xml index 0504f787c6..7b8fa9063f 100644 --- a/core-java-modules/core-java-21/pom.xml +++ b/core-java-modules/core-java-21/pom.xml @@ -12,6 +12,12 @@ 0.0.1-SNAPSHOT + + 21 + 21 + UTF-8 + + @@ -20,14 +26,22 @@ 21 21 - --enable-preview + + false + + --enable-preview + + + org.apache.maven.plugins + maven-surefire-plugin + + --enable-preview + + + - - 21 - 21 - UTF-8 - + \ No newline at end of file diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/Car.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/Car.java new file mode 100644 index 0000000000..8f51c03539 --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/Car.java @@ -0,0 +1,11 @@ +package com.baeldung.unnamed.variables; + +public record Car(String name, String color, T engine) { } + +abstract class Engine { } + +class GasEngine extends Engine { } + +class ElectricEngine extends Engine { } + +class HybridEngine extends Engine { } \ No newline at end of file diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedPatterns.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedPatterns.java new file mode 100644 index 0000000000..310ce621f9 --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedPatterns.java @@ -0,0 +1,50 @@ +package com.baeldung.unnamed.variables; + +public class UnnamedPatterns { + + static String getObjectsColorWithNamedPattern(Object object) { + if (object instanceof Car(String name, String color, Engine engine)) { + return color; + } + return "No color!"; + } + + static String getObjectsColorWithUnnamedPattern(Object object) { + if (object instanceof Car(_, String color, _)) { + return color; + } + return "No color!"; + } + + static String getObjectsColorWithSwitchAndNamedPattern(Object object) { + return switch (object) { + case Car(String name, String color, Engine engine) -> color; + default -> "No color!"; + }; + } + + static String getObjectsColorWithSwitchAndUnnamedPattern(Object object) { + return switch (object) { + case Car(_, String color, _) -> color; + default -> "No color!"; + }; + } + + static String getEngineTypeWithNamedPattern(Car car) { + return switch (car) { + case Car(String name, String color, GasEngine engine) -> "gas"; + case Car(String name, String color, ElectricEngine engine) -> "electric"; + case Car(String name, String color, HybridEngine engine) -> "hybrid"; + default -> "none"; + }; + } + + static String getEngineTypeWithUnnamedPattern(Car car) { + return switch (car) { + case Car(_, _, GasEngine _) -> "gas"; + case Car(_, _, ElectricEngine _) -> "electric"; + case Car(_, _, HybridEngine _) -> "hybrid"; + default -> "none"; + }; + } +} diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedVariables.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedVariables.java new file mode 100644 index 0000000000..82e76b40a4 --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedVariables.java @@ -0,0 +1,134 @@ +package com.baeldung.unnamed.variables; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Queue; + +class Transaction implements AutoCloseable { + + @Override + public void close() { + System.out.println("Closed!"); + } +} + +public class UnnamedVariables { + + static int countCarsOverLimitWithNamedVariable(Collection> cars, int limit) { + var total = 0; + var totalOverLimit = 0; + for (var car : cars) { + total++; + if (total > limit) { + totalOverLimit++; + // side effect + } + } + return totalOverLimit; + } + + static int countCarsOverLimitWithUnnamedVariable(Collection> cars, int limit) { + var total = 0; + var totalOverLimit = 0; + for (var _ : cars) { + total++; + if (total > limit) { + totalOverLimit++; + // side effect + } + } + return totalOverLimit; + } + + static void sendNotificationToCarsWithNamedVariable(Collection> cars) { + sendOneTimeNotification(); + for (int i = 0; i < cars.size(); i++) { + // Notify car + } + } + + static void sendNotificationToCarsWithUnnamedVariable(Collection> cars) { + for (int i = 0, _ = sendOneTimeNotification(); i < cars.size(); i++) { + // Notify car + } + } + + private static int sendOneTimeNotification() { + System.out.println("Sending one time notification!"); + return 1; + } + + static Car removeThreeCarsAndReturnFirstRemovedWithNamedVariables(Queue> cars) { + var x = cars.poll(); + var y = cars.poll(); + var z = cars.poll(); + return x; + } + + static Car removeThreeCarsAndReturnFirstRemovedWithUnnamedVariables(Queue> cars) { + var car = cars.poll(); + var _ = cars.poll(); + var _ = cars.poll(); + return car; + } + + static void handleCarExceptionWithNamedVariables(Car car) { + try { + someOperationThatFails(car); + } catch (IllegalStateException ex) { + System.out.println("Got an illegal state exception for: " + car.name()); + } catch (RuntimeException ex) { + System.out.println("Got a runtime exception!"); + } + } + + static void handleCarExceptionWithUnnamedVariables(Car car) { + try { + someOperationThatFails(car); + } catch (IllegalStateException | NumberFormatException _) { + System.out.println("Got an illegal state exception for: " + car.name()); + } catch (RuntimeException _) { + System.out.println("Got a runtime exception!"); + } + } + + static void obtainTransactionAndUpdateCarWithNamedVariables(Car car) { + try (var transaction = new Transaction()) { + updateCar(car); + } + } + + static void obtainTransactionAndUpdateCarWithUnnamedVariables(Car car) { + try (var _ = new Transaction()) { + updateCar(car); + } + } + + static void updateCar(Car car) { + // Some update logic + System.out.println("Car updated!"); + } + + static Map>> getCarsByFirstLetterWithNamedVariables(List> cars) { + Map>> carMap = new HashMap<>(); + cars.forEach(car -> + carMap.computeIfAbsent(car.name().substring(0, 1), firstLetter -> new ArrayList<>()).add(car) + ); + return carMap; + } + + static Map>> getCarsByFirstLetterWithUnnamedVariables(List> cars) { + Map>> carMap = new HashMap<>(); + cars.forEach(car -> + carMap.computeIfAbsent(car.name().substring(0, 1), _ -> new ArrayList<>()).add(car) + ); + return carMap; + } + + private static void someOperationThatFails(Car car) { + throw new IllegalStateException("Triggered exception for: " + car.name()); + } +} diff --git a/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/CarScenario.java b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/CarScenario.java new file mode 100644 index 0000000000..2acb83cdef --- /dev/null +++ b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/CarScenario.java @@ -0,0 +1,13 @@ +package com.baeldung.unnamed.variables; + +import java.util.List; + +class CarScenario { + + protected final List> cars = List.of( + new Car<>("Mitsubishi", "blue", new GasEngine()), + new Car<>("Toyota", "red", new ElectricEngine()), + new Car<>("Jaguar", "white", new HybridEngine()) + ); + +} diff --git a/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedPatternsUnitTest.java b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedPatternsUnitTest.java new file mode 100644 index 0000000000..9d860a201a --- /dev/null +++ b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedPatternsUnitTest.java @@ -0,0 +1,44 @@ +package com.baeldung.unnamed.variables; + +import static com.baeldung.unnamed.variables.UnnamedPatterns.getEngineTypeWithNamedPattern; +import static com.baeldung.unnamed.variables.UnnamedPatterns.getEngineTypeWithUnnamedPattern; +import static com.baeldung.unnamed.variables.UnnamedPatterns.getObjectsColorWithNamedPattern; +import static com.baeldung.unnamed.variables.UnnamedPatterns.getObjectsColorWithSwitchAndNamedPattern; +import static com.baeldung.unnamed.variables.UnnamedPatterns.getObjectsColorWithSwitchAndUnnamedPattern; +import static com.baeldung.unnamed.variables.UnnamedPatterns.getObjectsColorWithUnnamedPattern; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class UnnamedPatternsUnitTest extends CarScenario { + + @Test + public void whenExtractingColorWithNamedPatterns_thenReturnBlue() { + assertEquals("blue", getObjectsColorWithNamedPattern(cars.get(0))); + } + + @Test + public void whenExtractingColorWithUnnamedPatterns_thenReturnBlue() { + assertEquals("blue", getObjectsColorWithUnnamedPattern(cars.get(0))); + } + + @Test + public void whenExtractingColorWithSwitchAndNamedPatterns_thenReturnBlue() { + assertEquals("blue", getObjectsColorWithSwitchAndNamedPattern(cars.get(0))); + } + + @Test + public void whenExtractingColorWithSwitchAndUnnamedPatterns_thenReturnBlue() { + assertEquals("blue", getObjectsColorWithSwitchAndUnnamedPattern(cars.get(0))); + } + + @Test + public void whenExtractingEngineTypeWithNamedPatterns_thenReturnGas() { + assertEquals("gas", getEngineTypeWithNamedPattern(cars.get(0))); + } + + @Test + public void whenExtractingEngineTypeWithUnnamedPatterns_thenReturnGas() { + assertEquals("gas", getEngineTypeWithUnnamedPattern(cars.get(0))); + } +} diff --git a/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedVariablesUnitTest.java b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedVariablesUnitTest.java new file mode 100644 index 0000000000..094879c277 --- /dev/null +++ b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedVariablesUnitTest.java @@ -0,0 +1,93 @@ +package com.baeldung.unnamed.variables; + +import static com.baeldung.unnamed.variables.UnnamedVariables.countCarsOverLimitWithNamedVariable; +import static com.baeldung.unnamed.variables.UnnamedVariables.countCarsOverLimitWithUnnamedVariable; +import static com.baeldung.unnamed.variables.UnnamedVariables.getCarsByFirstLetterWithNamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.getCarsByFirstLetterWithUnnamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.handleCarExceptionWithNamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.handleCarExceptionWithUnnamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.obtainTransactionAndUpdateCarWithNamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.obtainTransactionAndUpdateCarWithUnnamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.removeThreeCarsAndReturnFirstRemovedWithNamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.removeThreeCarsAndReturnFirstRemovedWithUnnamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.sendNotificationToCarsWithNamedVariable; +import static com.baeldung.unnamed.variables.UnnamedVariables.sendNotificationToCarsWithUnnamedVariable; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.LinkedList; + +import org.junit.jupiter.api.Test; + +public class UnnamedVariablesUnitTest extends CarScenario { + + @Test + public void whenCountingCarsOverLimitWithNamedVariables_thenShouldReturnOne() { + assertEquals(1, countCarsOverLimitWithNamedVariable(cars, 2)); + } + + @Test + public void whenCountingCarsOverLimitWithUnnamedVariables_thenShouldReturnOne() { + assertEquals(1, countCarsOverLimitWithUnnamedVariable(cars, 2)); + } + + @Test + public void whenNotifyingCarsWithNamedVariables_thenShouldNotFail() { + assertDoesNotThrow(() -> sendNotificationToCarsWithNamedVariable(cars)); + } + + @Test + public void whenNotifyingCarsWithUnnamedVariables_thenShouldNotFail() { + assertDoesNotThrow(() -> sendNotificationToCarsWithUnnamedVariable(cars)); + } + + @Test + public void whenPollingCarsWithNamedVariables_thenReturnFirstOneAndEmptyQueue() { + var carQueue = new LinkedList<>(cars); + assertEquals("Mitsubishi", removeThreeCarsAndReturnFirstRemovedWithNamedVariables(carQueue).name()); + assertEquals(0, carQueue.size()); + } + + @Test + public void whenPollingCarsWithUnnamedVariables_thenReturnFirstOneAndEmptyQueue() { + var carQueue = new LinkedList<>(cars); + assertEquals("Mitsubishi", removeThreeCarsAndReturnFirstRemovedWithUnnamedVariables(carQueue).name()); + assertEquals(0, carQueue.size()); + } + + @Test + public void whenHandlingExceptionWithNamedVariables_thenNoExceptionIsThrown() { + assertDoesNotThrow(() -> handleCarExceptionWithNamedVariables(cars.get(0))); + } + + @Test + public void whenHandlingExceptionWithUnnamedVariables_thenNoExceptionIsThrown() { + assertDoesNotThrow(() -> handleCarExceptionWithUnnamedVariables(cars.get(0))); + } + + @Test + public void whenHandlingTransactionUpdateWithNamedVariables_thenNoExceptionIsThrown() { + assertDoesNotThrow(() -> obtainTransactionAndUpdateCarWithNamedVariables(cars.get(0))); + } + + @Test + public void whenHandlingTransactionUpdateWithUnnamedVariables_thenNoExceptionIsThrown() { + assertDoesNotThrow(() -> obtainTransactionAndUpdateCarWithUnnamedVariables(cars.get(0))); + } + + @Test + public void whenGettingCarsByFirstLetterWithNamedVariables_thenHaveThreeKeys() { + var carsByLetter = getCarsByFirstLetterWithNamedVariables(cars); + assertEquals(1, carsByLetter.get("M").size()); + assertEquals(1, carsByLetter.get("T").size()); + assertEquals(1, carsByLetter.get("J").size()); + } + + @Test + public void whenGettingCarsByFirstLetterWithUnnamedVariables_thenHaveThreeKeys() { + var carsByLetter = getCarsByFirstLetterWithUnnamedVariables(cars); + assertEquals(1, carsByLetter.get("M").size()); + assertEquals(1, carsByLetter.get("T").size()); + assertEquals(1, carsByLetter.get("J").size()); + } +} From ed4b43ce9802053a1ceec592808b2de07140314f Mon Sep 17 00:00:00 2001 From: Eugene Kovko <37694937+eukovko@users.noreply.github.com> Date: Fri, 29 Sep 2023 00:05:22 +0200 Subject: [PATCH 102/193] BAEL-6705: Check if a String is Strictly Alphanumeric With Java (#14865) * BAEL-6705: Check if a String is Strictly Alphanumeric With Java * BAEL-6705: Rename a Class * BAEL-6705: Fix isAlpanumeric Logic * BAEL-6705: Fix alphanumericIterationWithCharacterChecks Logic * BAEL-6705: Expose isAlphanumeric method * BAEL-6705: Added isAlphanumeric test --- .../AlphanumericPerformanceBenchmark.java | 91 +++++++++++++++++++ .../alphanumeric/AlphanumericUnitTest.java | 30 ++++++ 2 files changed, 121 insertions(+) create mode 100644 core-java-modules/core-java-regex-2/src/main/java/com/baeldung/alphanumeric/AlphanumericPerformanceBenchmark.java create mode 100644 core-java-modules/core-java-regex-2/src/test/java/com/baeldung/alphanumeric/AlphanumericUnitTest.java diff --git a/core-java-modules/core-java-regex-2/src/main/java/com/baeldung/alphanumeric/AlphanumericPerformanceBenchmark.java b/core-java-modules/core-java-regex-2/src/main/java/com/baeldung/alphanumeric/AlphanumericPerformanceBenchmark.java new file mode 100644 index 0000000000..4b2ecc4c4d --- /dev/null +++ b/core-java-modules/core-java-regex-2/src/main/java/com/baeldung/alphanumeric/AlphanumericPerformanceBenchmark.java @@ -0,0 +1,91 @@ +package com.baeldung.alphanumeric; + +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.infra.Blackhole; + +@Warmup(iterations = 1) +@Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MINUTES) +@Fork(1) +public class AlphanumericPerformanceBenchmark { + + private static final String TEST_STRING = "ABC123abc123"; + private static final String REGEX = "[^[a-zA-Z0-9]*$]"; + private static final Pattern PATTERN = Pattern.compile(REGEX); + + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void alphanumericRegex(Blackhole blackhole) { + final Matcher matcher = PATTERN.matcher(TEST_STRING); + boolean result = matcher.matches(); + blackhole.consume(result); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void alphanumericRegexDirectlyOnString(Blackhole blackhole) { + boolean result = TEST_STRING.matches(REGEX); + blackhole.consume(result); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void alphanumericIteration(Blackhole blackhole) { + boolean result = true; + for (int i = 0; i < TEST_STRING.length(); ++i) { + final int codePoint = TEST_STRING.codePointAt(i); + if (!isAlphanumeric(codePoint)) { + result = false; + break; + } + } + blackhole.consume(result); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void alphanumericIterationWithCharacterChecks(Blackhole blackhole) { + boolean result = true; + for (int i = 0; i < TEST_STRING.length(); ++i) { + final int codePoint = TEST_STRING.codePointAt(i); + if (!Character.isAlphabetic(codePoint) || !Character.isDigit(codePoint)) { + result = false; + break; + } + } + blackhole.consume(result); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void alphanumericIterationWithCopy(Blackhole blackhole) { + boolean result = true; + for (final char c : TEST_STRING.toCharArray()) { + if (!isAlphanumeric(c)) { + result = false; + break; + } + } + blackhole.consume(result); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void alphanumericIterationWithStream(Blackhole blackhole) { + boolean result = TEST_STRING.chars().allMatch(this::isAlphanumeric); + blackhole.consume(result); + } + + public boolean isAlphanumeric(final int codePoint) { + return (codePoint >= 65 && codePoint <= 90) || + (codePoint >= 97 && codePoint <= 172) || + (codePoint >= 48 && codePoint <= 57); + } +} diff --git a/core-java-modules/core-java-regex-2/src/test/java/com/baeldung/alphanumeric/AlphanumericUnitTest.java b/core-java-modules/core-java-regex-2/src/test/java/com/baeldung/alphanumeric/AlphanumericUnitTest.java new file mode 100644 index 0000000000..b00bf7c4e3 --- /dev/null +++ b/core-java-modules/core-java-regex-2/src/test/java/com/baeldung/alphanumeric/AlphanumericUnitTest.java @@ -0,0 +1,30 @@ +package com.baeldung.alphanumeric; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class AlphanumericUnitTest { + + private AlphanumericPerformanceBenchmark alphanumericPerformanceBenchmark = new AlphanumericPerformanceBenchmark(); + + @ParameterizedTest + @CsvSource({ + "A,true", + "B,true", + "C,true", + "1,true", + "2,true", + "3,true", + "!,false", + "@,false", + "#,false", + "$,false", + "%,false" + }) + void shouldCorrectlyIdentifyAlphanumericCharacterTest(char character, boolean result) { + boolean actual = alphanumericPerformanceBenchmark.isAlphanumeric(character); + assertEquals(actual, result); + } +} \ No newline at end of file From cf058499c4e2f418f96f1631e7016d7c53d4b562 Mon Sep 17 00:00:00 2001 From: Zahid Khan <63726443+zahikhan@users.noreply.github.com> Date: Fri, 29 Sep 2023 09:17:51 +0530 Subject: [PATCH 103/193] Generation of the Sequence numbers (#14589) * Add of unit test. * Add of unit test. * Update and rename GenerationOfAlphabetsUsingForVariousWaysUnitTest.java to GenerationOfCharactersUsingForVariousWaysUnitTest.java * Replace the variable name * Update GenerationOfCharactersUsingForVariousWaysUnitTest.java --- ...CharactersUsingForVariousWaysUnitTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 core-java-modules/core-java-char/src/test/java/com/baeldung/alphabetgeneration/GenerationOfCharactersUsingForVariousWaysUnitTest.java diff --git a/core-java-modules/core-java-char/src/test/java/com/baeldung/alphabetgeneration/GenerationOfCharactersUsingForVariousWaysUnitTest.java b/core-java-modules/core-java-char/src/test/java/com/baeldung/alphabetgeneration/GenerationOfCharactersUsingForVariousWaysUnitTest.java new file mode 100644 index 0000000000..bda50bb136 --- /dev/null +++ b/core-java-modules/core-java-char/src/test/java/com/baeldung/alphabetgeneration/GenerationOfCharactersUsingForVariousWaysUnitTest.java @@ -0,0 +1,29 @@ +package com.baeldung.alphabetgeneration; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +class GenerationOfCharactersUsingForVariousWaysUnitTest { + @Test + void whenUsingForLoop_thenGenerateCharacters(){ + final List allCapitalCharacters = Arrays.asList('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); + List characters = new ArrayList<>(); + for (char character = 'A'; character <= 'Z'; character++) { + characters.add(character); + } + Assertions.assertEquals(characters, allCapitalCharacters); + } + + @Test + void whenUsingStreams_thenGenerateCharacters() { + final List allCapitalCharacters = Arrays.asList('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); + final List characters = IntStream.rangeClosed('A', 'Z').mapToObj(c -> (char) c).collect(Collectors.toList()); + Assertions.assertEquals(characters, allCapitalCharacters); + } +} From 0fbf2beda5fdb63eeccc71ef7af641b9aa31893e Mon Sep 17 00:00:00 2001 From: Zahid Khan <63726443+zahikhan@users.noreply.github.com> Date: Fri, 29 Sep 2023 11:06:54 +0530 Subject: [PATCH 104/193] Character generation. (#14871) * Add of unit test. * Add of unit test. * Update and rename GenerationOfAlphabetsUsingForVariousWaysUnitTest.java to GenerationOfCharactersUsingForVariousWaysUnitTest.java * Replace the variable name * Update GenerationOfCharactersUsingForVariousWaysUnitTest.java * Rename of package * Rename of file and package. --- .../IncrementCharUnitTest.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename core-java-modules/core-java-char/src/test/java/com/baeldung/{alphabetgeneration/GenerationOfCharactersUsingForVariousWaysUnitTest.java => incrementchar/IncrementCharUnitTest.java} (92%) diff --git a/core-java-modules/core-java-char/src/test/java/com/baeldung/alphabetgeneration/GenerationOfCharactersUsingForVariousWaysUnitTest.java b/core-java-modules/core-java-char/src/test/java/com/baeldung/incrementchar/IncrementCharUnitTest.java similarity index 92% rename from core-java-modules/core-java-char/src/test/java/com/baeldung/alphabetgeneration/GenerationOfCharactersUsingForVariousWaysUnitTest.java rename to core-java-modules/core-java-char/src/test/java/com/baeldung/incrementchar/IncrementCharUnitTest.java index bda50bb136..7621e85762 100644 --- a/core-java-modules/core-java-char/src/test/java/com/baeldung/alphabetgeneration/GenerationOfCharactersUsingForVariousWaysUnitTest.java +++ b/core-java-modules/core-java-char/src/test/java/com/baeldung/incrementchar/IncrementCharUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.alphabetgeneration; +package com.baeldung.incrementchar; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -9,7 +9,7 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; -class GenerationOfCharactersUsingForVariousWaysUnitTest { +class IncrementCharUnitTest { @Test void whenUsingForLoop_thenGenerateCharacters(){ final List allCapitalCharacters = Arrays.asList('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); From a50bdf68166803c5ec7be67a7a34abf28742459b Mon Sep 17 00:00:00 2001 From: timis1 Date: Fri, 29 Sep 2023 09:14:20 +0300 Subject: [PATCH 105/193] JAVA-25350 Potential issue in "Sorting Java Map in Descending Order" article --- .../objecttomap/ObjectToMapUnitTest.java | 76 ----------- .../objecttomap/ObjectToMapUnitTest.java | 128 ++++++++++++++++++ 2 files changed, 128 insertions(+), 76 deletions(-) delete mode 100644 core-java-modules/core-java-collections-maps-6/src/test/com/baeldung/objecttomap/ObjectToMapUnitTest.java create mode 100644 core-java-modules/core-java-collections-maps-6/src/test/java/com/baeldung/objecttomap/ObjectToMapUnitTest.java diff --git a/core-java-modules/core-java-collections-maps-6/src/test/com/baeldung/objecttomap/ObjectToMapUnitTest.java b/core-java-modules/core-java-collections-maps-6/src/test/com/baeldung/objecttomap/ObjectToMapUnitTest.java deleted file mode 100644 index 52c2fb2bea..0000000000 --- a/core-java-modules/core-java-collections-maps-6/src/test/com/baeldung/objecttomap/ObjectToMapUnitTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package java.com.baeldung.objecttomap; -import com.google.gson.Gson; -import org.junit.Assert; -import org.junit.Test; -import wiremock.com.fasterxml.jackson.core.type.TypeReference; -import wiremock.com.fasterxml.jackson.databind.ObjectMapper; -import wiremock.com.google.common.reflect.TypeToken; -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; - -public class ObjectToMapUnitTest { - Employee employee = new Employee("John", 3000.0); - - @Test - public void givenJavaObject_whenUsingReflection_thenConvertToMap() throws IllegalAccessException { - Map map = convertUsingReflection(employee); - Assert.assertEquals(employee.getName(), map.get("name")); - Assert.assertEquals(employee.getSalary(), map.get("salary")); - } - - private Map convertUsingReflection(Object object) throws IllegalAccessException { - Map map = new HashMap<>(); - Field[] fields = object.getClass().getDeclaredFields(); - - for (Field field : fields) { - field.setAccessible(true); - map.put(field.getName(), field.get(object)); - } - - return map; - } - - @Test - public void givenJavaObject_whenUsingJackson_thenConvertToMap() { - ObjectMapper objectMapper = new ObjectMapper(); - Map map = objectMapper.convertValue(employee, new TypeReference>() {}); - Assert.assertEquals(employee.getName(), map.get("name")); - Assert.assertEquals(employee.getSalary(), map.get("salary")); - } - - @Test - public void givenJavaObject_whenUsingGson_thenConvertToMap() { - Gson gson = new Gson(); - String json = gson.toJson(employee); - Map map = gson.fromJson(json, new TypeToken>() {}.getType()); - Assert.assertEquals(employee.getName(), map.get("name")); - Assert.assertEquals(employee.getSalary(), map.get("salary")); - } - - private static class Employee { - private String name; - private Double salary; - - public Employee(String name, Double salary) { - this.name = name; - this.salary = salary; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Double getSalary() { - return salary; - } - - public void setSalary(Double age) { - this.salary = salary; - } - } -} diff --git a/core-java-modules/core-java-collections-maps-6/src/test/java/com/baeldung/objecttomap/ObjectToMapUnitTest.java b/core-java-modules/core-java-collections-maps-6/src/test/java/com/baeldung/objecttomap/ObjectToMapUnitTest.java new file mode 100644 index 0000000000..e232121048 --- /dev/null +++ b/core-java-modules/core-java-collections-maps-6/src/test/java/com/baeldung/objecttomap/ObjectToMapUnitTest.java @@ -0,0 +1,128 @@ +package com.baeldung.objecttomap; + +import static org.junit.Assert.assertEquals; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import org.junit.Test; +import java.lang.reflect.Field; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.stream.Collectors; + +public class ObjectToMapUnitTest { + Employee employee = new Employee("John", 3000.0); + + @Test + public void givenJavaObject_whenUsingReflection_thenConvertToMap() throws IllegalAccessException { + Map map = convertUsingReflection(employee); + assertEquals(employee.getName(), map.get("name")); + assertEquals(employee.getSalary(), map.get("salary")); + } + + private Map convertUsingReflection(Object object) throws IllegalAccessException { + Map map = new HashMap<>(); + Field[] fields = object.getClass().getDeclaredFields(); + + for (Field field : fields) { + field.setAccessible(true); + map.put(field.getName(), field.get(object)); + } + + return map; + } + + @Test + public void givenJavaObject_whenUsingJackson_thenConvertToMap() { + ObjectMapper objectMapper = new ObjectMapper(); + Map map = objectMapper.convertValue(employee, new TypeReference>() {}); + assertEquals(employee.getName(), map.get("name")); + assertEquals(employee.getSalary(), map.get("salary")); + } + + @Test + public void givenJavaObject_whenUsingGson_thenConvertToMap() { + Gson gson = new Gson(); + String json = gson.toJson(employee); + Map map = gson.fromJson(json, new TypeToken>() {}.getType()); + assertEquals(employee.getName(), map.get("name")); + assertEquals(employee.getSalary(), map.get("salary")); + } + + @Test + public void given_UnsortedMap_whenSortingByValueDescending_thenValuesAreInDescendingOrder() { + Map unsortedMap = new HashMap<>(); + unsortedMap.put("one", 1); + unsortedMap.put("three", 3); + unsortedMap.put("five", 5); + unsortedMap.put("two", 2); + unsortedMap.put("four", 4); + + Map sortedMap = sortMapByValueDescending(unsortedMap); + + assertEquals(5, sortedMap.size()); + final Iterator iterator = sortedMap.values().iterator(); + assertEquals(5, (int) iterator.next()); + assertEquals(4, (int) iterator.next()); + assertEquals(3, (int) iterator.next()); + assertEquals(2, (int) iterator.next()); + assertEquals(1, (int) iterator.next()); + } + + @Test + public void given_UnsortedMap_whenUsingTreeMap_thenKeysAreInDescendingOrder() { + SortedMap treeMap = new TreeMap<>(Comparator.reverseOrder()); + treeMap.put("one", 1); + treeMap.put("three", 3); + treeMap.put("five", 5); + treeMap.put("two", 2); + treeMap.put("four", 4); + + assertEquals(5, treeMap.size()); + final Iterator iterator = treeMap.keySet().iterator(); + assertEquals("two", iterator.next()); + assertEquals("three", iterator.next()); + assertEquals("one", iterator.next()); + assertEquals("four", iterator.next()); + assertEquals("five", iterator.next()); + } + + private static class Employee { + private String name; + private Double salary; + + public Employee(String name, Double salary) { + this.name = name; + this.salary = salary; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Double getSalary() { + return salary; + } + + public void setSalary(Double age) { + this.salary = salary; + } + } + + public static > Map sortMapByValueDescending(Map map) { + return map.entrySet().stream() + .sorted(Map.Entry.comparingByValue().reversed()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); + } +} From b2295ce3b7795a953fed0a0163fdcb26476da060 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:14:32 +0800 Subject: [PATCH 106/193] Update README.md [skip ci] --- core-java-modules/core-java-arrays-operations-advanced/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-modules/core-java-arrays-operations-advanced/README.md b/core-java-modules/core-java-arrays-operations-advanced/README.md index 0647d89d16..b379958f37 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/README.md +++ b/core-java-modules/core-java-arrays-operations-advanced/README.md @@ -14,4 +14,3 @@ This module contains articles about advanced operations on arrays in Java. They - [Slicing Arrays in Java](https://www.baeldung.com/java-slicing-arrays) - [Combining Two or More Byte Arrays](https://www.baeldung.com/java-concatenate-byte-arrays) - [Calculating the Sum of Two Arrays in Java](https://www.baeldung.com/java-sum-arrays-element-wise) -- [Find the Middle Element of an Array in Java](https://www.baeldung.com/java-array-middle-item) From 823d0efb332a653dffa62bd86e3976c589f4caac Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:16:10 +0800 Subject: [PATCH 107/193] Create README.md [skip ci] --- .../core-java-arrays-operations-advanced-2/README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 core-java-modules/core-java-arrays-operations-advanced-2/README.md diff --git a/core-java-modules/core-java-arrays-operations-advanced-2/README.md b/core-java-modules/core-java-arrays-operations-advanced-2/README.md new file mode 100644 index 0000000000..17ffa2562d --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced-2/README.md @@ -0,0 +1,2 @@ +## Relevant Articles +- [Find the Middle Element of an Array in Java](https://www.baeldung.com/java-array-middle-item) From af59c6a5397d420e5999c9677dfb0912ae6bb92d Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:53:50 +0800 Subject: [PATCH 108/193] Update README.md [skip ci] --- persistence-modules/spring-jdbc/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/spring-jdbc/README.md b/persistence-modules/spring-jdbc/README.md index 21d25915de..19f8537a4e 100644 --- a/persistence-modules/spring-jdbc/README.md +++ b/persistence-modules/spring-jdbc/README.md @@ -7,3 +7,4 @@ - [Obtaining Auto-generated Keys in Spring JDBC](https://www.baeldung.com/spring-jdbc-autogenerated-keys) - [Spring JDBC Batch Inserts](https://www.baeldung.com/spring-jdbc-batch-inserts) - [Fix EmptyResultDataAccessException When Using JdbcTemplate](https://www.baeldung.com/jdbctemplate-fix-emptyresultdataaccessexception) +- [How to replace deprecated jdbcTemplate.queryForObject and jdbcTemplate.query in spring boot 2.4.X and above](https://www.baeldung.com/spring-boot-replace-deprecated-jdbctemplate-queryforobject-query) From 95946165620b8131bffca2679cc59e651b4eae19 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:56:54 +0800 Subject: [PATCH 109/193] Update README.md [skip ci] --- core-java-modules/core-java-string-algorithms-3/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-string-algorithms-3/README.md b/core-java-modules/core-java-string-algorithms-3/README.md index 2bb70f5c97..3ef07129ed 100644 --- a/core-java-modules/core-java-string-algorithms-3/README.md +++ b/core-java-modules/core-java-string-algorithms-3/README.md @@ -11,4 +11,5 @@ This module contains articles about string-related algorithms. - [Find the First Non Repeating Character in a String in Java](https://www.baeldung.com/java-find-the-first-non-repeating-character) - [Find the First Embedded Occurrence of an Integer in a Java String](https://www.baeldung.com/java-string-find-embedded-integer) - [Find the Most Frequent Characters in a String](https://www.baeldung.com/java-string-find-most-frequent-characters) -- [Checking If a String Is a Repeated Substring](https://www.baeldung.com/java-repeated-substring) \ No newline at end of file +- [Checking If a String Is a Repeated Substring](https://www.baeldung.com/java-repeated-substring) +- [Check if Letter Is Emoji With Java](https://www.baeldung.com/java-check-letter-emoji) From 14971d6017f3d7851b204185d78d2f8af3fe848e Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:59:09 +0800 Subject: [PATCH 110/193] Update README.md [skip ci] --- core-java-modules/core-java-9-streams/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-9-streams/README.md b/core-java-modules/core-java-9-streams/README.md index 0ad8500689..d9663e0858 100644 --- a/core-java-modules/core-java-9-streams/README.md +++ b/core-java-modules/core-java-9-streams/README.md @@ -4,3 +4,4 @@ This module contains articles about Java 9 streams ### Relevant Articles: - [How to Break from Java Stream forEach](https://www.baeldung.com/java-break-stream-foreach) +- [Creating Stream of Regex Matches](https://www.baeldung.com/java-stream-regex-matches) From 3d09f92af7121c5de8736f10ed4e308f517c02e0 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 29 Sep 2023 23:02:38 +0800 Subject: [PATCH 111/193] Update README.md [skip ci] --- core-java-modules/core-java-io-apis-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-io-apis-2/README.md b/core-java-modules/core-java-io-apis-2/README.md index cc3c351afc..3ec3220424 100644 --- a/core-java-modules/core-java-io-apis-2/README.md +++ b/core-java-modules/core-java-io-apis-2/README.md @@ -7,3 +7,4 @@ This module contains articles about core Java input/output(IO) APIs. - [Get the Desktop Path in Java](https://www.baeldung.com/java-desktop-path) - [Check if a File Is Empty in Java](https://www.baeldung.com/java-check-file-empty) - [Converting Relative to Absolute Paths in Java](https://www.baeldung.com/java-from-relative-to-absolute-paths) +- [Detect EOF in Java](https://www.baeldung.com/java-file-detect-end-of-file) From c731ff9446380a99271e794f7d27d8b9750166b3 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 29 Sep 2023 23:12:27 +0800 Subject: [PATCH 112/193] Update README.md [skip ci] --- core-java-modules/core-java-numbers-6/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-numbers-6/README.md b/core-java-modules/core-java-numbers-6/README.md index 254b2b58d7..3bd9fe6ddb 100644 --- a/core-java-modules/core-java-numbers-6/README.md +++ b/core-java-modules/core-java-numbers-6/README.md @@ -4,4 +4,5 @@ - [Integer.class vs Integer.TYPE vs int.class](https://www.baeldung.com/java-integer-class-vs-type-vs-int) - [Does Java Read Integers in Little Endian or Big Endian?](https://www.baeldung.com/java-integers-little-big-endian) - [How to Split an Integer Number Into Digits in Java](https://www.baeldung.com/java-integer-individual-digits) +- [Java Double vs. BigDecimal](https://www.baeldung.com/java-double-vs-bigdecimal) - More articles: [[<-- prev]](../core-java-numbers-5) From 520f7d508d05f0a1b9234f555ead3b65dfa65141 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 29 Sep 2023 23:15:40 +0800 Subject: [PATCH 113/193] Create README.md [skip ci] --- apache-poi-3/README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 apache-poi-3/README.md diff --git a/apache-poi-3/README.md b/apache-poi-3/README.md new file mode 100644 index 0000000000..58ddc8b41c --- /dev/null +++ b/apache-poi-3/README.md @@ -0,0 +1,2 @@ +## Relevant Articles +- [How To Convert Excel Data Into List Of Java Objects](https://www.baeldung.com/java-convert-excel-data-into-list) From dd1503b6e07161e25257212dce0f78856d5598ac Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 29 Sep 2023 23:19:11 +0800 Subject: [PATCH 114/193] Update README.md [skip ci] --- core-java-modules/core-java-arrays-guides/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-arrays-guides/README.md b/core-java-modules/core-java-arrays-guides/README.md index 0af77980af..d8b0d126a1 100644 --- a/core-java-modules/core-java-arrays-guides/README.md +++ b/core-java-modules/core-java-arrays-guides/README.md @@ -9,3 +9,4 @@ This module contains complete guides about arrays in Java - [Guide to ArrayStoreException](https://www.baeldung.com/java-arraystoreexception) - [Creating a Generic Array in Java](https://www.baeldung.com/java-generic-array) - [Maximum Size of Java Arrays](https://www.baeldung.com/java-arrays-max-size) +- [Merge Two Arrays and Remove Duplicates in Java](https://www.baeldung.com/java-merge-two-arrays-delete-duplicates) From 21ae31a8ef66d5e4d56dde84daf7bc4a1348006f Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Fri, 29 Sep 2023 23:23:11 +0800 Subject: [PATCH 115/193] Update README.md [skip ci] --- spring-boot-modules/spring-boot-security/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-security/README.md b/spring-boot-modules/spring-boot-security/README.md index d848f798ba..2fd9e77c92 100644 --- a/spring-boot-modules/spring-boot-security/README.md +++ b/spring-boot-modules/spring-boot-security/README.md @@ -11,7 +11,7 @@ This module contains articles about Spring Boot Security - [Disable Security for a Profile in Spring Boot](https://www.baeldung.com/spring-security-disable-profile) - [Spring @EnableWebSecurity vs. @EnableGlobalMethodSecurity](https://www.baeldung.com/spring-enablewebsecurity-vs-enableglobalmethodsecurity) - [Spring Security – Configuring Different URLs](https://www.baeldung.com/spring-security-configuring-urls) - +- [Difference Between permitAll() and anonymous() in Spring Security](https://www.baeldung.com/spring-security-permitall-vs-anonymous) ### Spring Boot Security Auto-Configuration From 29bfc410bcda58ce2f020542f053afbfd820d2e9 Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Fri, 29 Sep 2023 21:03:32 +0530 Subject: [PATCH 116/193] Update pom.xml --- .../pom.xml | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/core-java-modules/core-java-collections-array-list-2/pom.xml b/core-java-modules/core-java-collections-array-list-2/pom.xml index 44ecb0fffb..2ab88c9944 100644 --- a/core-java-modules/core-java-collections-array-list-2/pom.xml +++ b/core-java-modules/core-java-collections-array-list-2/pom.xml @@ -1,31 +1,32 @@ - 4.0.0 - core-java-collections-array-list-2 - core-java-collections-array-list-2 - jar - - com.baeldung.core-java-modules - core-java-modules - 0.0.1-SNAPSHOT - + 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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + core-java-collections-array-list-2 + core-java-collections-array-list-2 + jar + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${maven-compiler-plugin.source} - ${maven-compiler-plugin.target} - - - - + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${maven-compiler-plugin.source} + ${maven-compiler-plugin.target} + + + + - - 17 - 17 - + + 17 + 17 + From d109a6bcb5847323850dd59051f439e9a353fd1a Mon Sep 17 00:00:00 2001 From: Niket Agrawal Date: Fri, 29 Sep 2023 21:04:56 +0530 Subject: [PATCH 117/193] Updated POM Formatting --- .../core-java-collections-array-list-2/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-collections-array-list-2/pom.xml b/core-java-modules/core-java-collections-array-list-2/pom.xml index 2ab88c9944..042f6e5bb5 100644 --- a/core-java-modules/core-java-collections-array-list-2/pom.xml +++ b/core-java-modules/core-java-collections-array-list-2/pom.xml @@ -1,7 +1,7 @@ + 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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 core-java-collections-array-list-2 core-java-collections-array-list-2 From 6a7f88cbbdbd16b9d4b9d637084ad75ec953f6b7 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 30 Sep 2023 00:06:01 +0800 Subject: [PATCH 118/193] Update README.md [skip ci] --- core-java-modules/core-java-16/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-16/README.md b/core-java-modules/core-java-16/README.md index b2740d194c..11b0fba8d3 100644 --- a/core-java-modules/core-java-16/README.md +++ b/core-java-modules/core-java-16/README.md @@ -5,3 +5,4 @@ - [Collecting Stream Elements into a List in Java](https://www.baeldung.com/java-stream-to-list-collecting) - [New Features in Java 16](https://www.baeldung.com/java-16-new-features) - [Guide to Java 8 groupingBy Collector](https://www.baeldung.com/java-groupingby-collector) +- [Value-Based Classes in Java](https://www.baeldung.com/java-value-based-classes) From 55c8c26ef99cf522873365f4f69204f17cac7d1a Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 30 Sep 2023 00:08:32 +0800 Subject: [PATCH 119/193] Update README.md [skip ci] --- logging-modules/log4j2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/logging-modules/log4j2/README.md b/logging-modules/log4j2/README.md index 87e92e0d48..fa7133ffdd 100644 --- a/logging-modules/log4j2/README.md +++ b/logging-modules/log4j2/README.md @@ -9,3 +9,4 @@ - [Log4j 2 Plugins](https://www.baeldung.com/log4j2-plugins) - [Printing Thread Info in Log File Using Log4j2](https://www.baeldung.com/log4j2-print-thread-info) - [Log4j2 – Logging to Both File and Console](https://www.baeldung.com/java-log4j2-file-and-console) +- [Log4j 2 Configuration Using a Properties File](https://www.baeldung.com/java-log4j2-config-with-prop-file) From 38d88c7eec7943dabec75c57d4088ceeafa3d013 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 30 Sep 2023 00:11:58 +0800 Subject: [PATCH 120/193] Update README.md [skip ci] --- apache-poi-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/apache-poi-3/README.md b/apache-poi-3/README.md index 58ddc8b41c..9e9d6a94eb 100644 --- a/apache-poi-3/README.md +++ b/apache-poi-3/README.md @@ -1,2 +1,3 @@ ## Relevant Articles - [How To Convert Excel Data Into List Of Java Objects](https://www.baeldung.com/java-convert-excel-data-into-list) +- [Expand Columns with Apache POI](https://www.baeldung.com/java-apache-poi-expand-columns) From d73922fd580cfcbb347cc7e8b36434bac78d8d45 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 30 Sep 2023 00:16:32 +0800 Subject: [PATCH 121/193] Update README.md [skip ci] --- logging-modules/log4j/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/logging-modules/log4j/README.md b/logging-modules/log4j/README.md index a47d0ae89b..32ea358369 100644 --- a/logging-modules/log4j/README.md +++ b/logging-modules/log4j/README.md @@ -4,3 +4,4 @@ - [A Guide to Rolling File Appenders](http://www.baeldung.com/java-logging-rolling-file-appenders) - [Logging Exceptions Using SLF4J](https://www.baeldung.com/slf4j-log-exceptions) - [Log4j Warning: “No Appenders Could Be Found for Logger”](https://www.baeldung.com/log4j-no-appenders-found) +- [A Guide to Log4j and the log4j.properties File in Java](https://www.baeldung.com/java-log4j-properties-guide) From fe818359cce4572cb8bd9fdc905c4a812698017e Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 30 Sep 2023 00:21:44 +0800 Subject: [PATCH 122/193] Update README.md [skip ci] --- testing-modules/mockito-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/mockito-2/README.md b/testing-modules/mockito-2/README.md index b60885c6d5..da8f339e56 100644 --- a/testing-modules/mockito-2/README.md +++ b/testing-modules/mockito-2/README.md @@ -8,3 +8,4 @@ This module contains articles about Mockito - [Matching Null With Mockito](https://www.baeldung.com/mockito-match-null) - [Mock Same Method with Different Parameters](https://www.baeldung.com/java-mock-same-method-other-parameters) - [How to Mock Constructors for Unit Testing using Mockito](https://www.baeldung.com/java-mockito-constructors-unit-testing) +- [Overview of Mockito MockedConstruction](https://www.baeldung.com/java-mockito-mockedconstruction) From ac1d97801d0f8ee59af2b47715b27f87518eb8af Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 30 Sep 2023 00:27:07 +0800 Subject: [PATCH 123/193] Update README.md [skip ci] --- core-java-modules/core-java-documentation/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-documentation/README.md b/core-java-modules/core-java-documentation/README.md index b66b9e8c05..972e76c165 100644 --- a/core-java-modules/core-java-documentation/README.md +++ b/core-java-modules/core-java-documentation/README.md @@ -3,4 +3,4 @@ ### Relevant Articles: - [Introduction to Javadoc](http://www.baeldung.com/javadoc) - +- [Code Snippets in Java API Documentation](https://www.baeldung.com/java-doc-code-snippets) From aebe7fa26b2f56596a5a17dae9cf291cb6e62669 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 30 Sep 2023 00:29:54 +0800 Subject: [PATCH 124/193] Update README.md [skip ci] --- core-java-modules/core-java-21/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-21/README.md b/core-java-modules/core-java-21/README.md index 04f99a244b..2c51db275a 100644 --- a/core-java-modules/core-java-21/README.md +++ b/core-java-modules/core-java-21/README.md @@ -1,2 +1,3 @@ ## Relevant Articles -- [Sequenced Collections in Java 21](https://www.baeldung.com/java-21-sequenced-collections) \ No newline at end of file +- [Sequenced Collections in Java 21](https://www.baeldung.com/java-21-sequenced-collections) +- [String Templates in Java 21](https://www.baeldung.com/java-21-string-templates) From 8faea6ae1330be27ee2c699ab4bbc324974eb6c7 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Sat, 30 Sep 2023 00:33:33 +0800 Subject: [PATCH 125/193] Create README.md [skip ci] --- core-java-modules/core-java-collections-list-6/README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 core-java-modules/core-java-collections-list-6/README.md diff --git a/core-java-modules/core-java-collections-list-6/README.md b/core-java-modules/core-java-collections-list-6/README.md new file mode 100644 index 0000000000..fd162743dc --- /dev/null +++ b/core-java-modules/core-java-collections-list-6/README.md @@ -0,0 +1,2 @@ +## Relevant Articles +- [Check if a List Contains a String Element While Ignoring Case](https://www.baeldung.com/java-list-search-case-insensitive) From 9e5c656d84853bd4fccba8ca517a284d651068f2 Mon Sep 17 00:00:00 2001 From: Eugene Kovko <37694937+eukovko@users.noreply.github.com> Date: Fri, 29 Sep 2023 23:39:41 +0200 Subject: [PATCH 126/193] BAEL-6781: Skip First Iteration in Java Foreach (#14876) --- .../SkipFirstElementExample.java | 126 ++++++++++++++++++ .../SkipFirstElementExampleUnitTest.java | 122 +++++++++++++++++ .../skippingfirstelement/TestableSkip.java | 10 ++ .../TestableSkipFirstElement.java | 37 +++++ 4 files changed, 295 insertions(+) create mode 100644 core-java-modules/core-java-collections-5/src/main/java/com/baeldung/skippingfirstelement/SkipFirstElementExample.java create mode 100644 core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/SkipFirstElementExampleUnitTest.java create mode 100644 core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkip.java create mode 100644 core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkipFirstElement.java diff --git a/core-java-modules/core-java-collections-5/src/main/java/com/baeldung/skippingfirstelement/SkipFirstElementExample.java b/core-java-modules/core-java-collections-5/src/main/java/com/baeldung/skippingfirstelement/SkipFirstElementExample.java new file mode 100644 index 0000000000..86982486fa --- /dev/null +++ b/core-java-modules/core-java-collections-5/src/main/java/com/baeldung/skippingfirstelement/SkipFirstElementExample.java @@ -0,0 +1,126 @@ +package com.baeldung.skippingfirstelement; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +public class SkipFirstElementExample { + + private final List stringList = new ArrayList<>(); + private final Set stringSet = new HashSet<>(); + private final Map stringMap = new HashMap<>(); + + public SkipFirstElementExample() { + // Initializing a List + stringList.add("Monday"); + stringList.add("Tuesday"); + stringList.add("Wednesday"); + stringList.add("Thursday"); + stringList.add("Friday"); + stringList.add("Saturday"); + stringList.add("Sunday"); + // Initializing a Set + stringSet.add("Monday"); + stringSet.add("Tuesday"); + stringSet.add("Wednesday"); + stringSet.add("Thursday"); + stringSet.add("Friday"); + stringSet.add("Saturday"); + stringSet.add("Sunday"); + // Initializing a Map + stringMap.put("Monday", "The day when coffee is a life support system."); + stringMap.put("Tuesday", "The day you realize that Monday's optimism was a lie."); + stringMap.put("Wednesday", "Hump Day, or as it's known, the 'Is it Friday yet?' day."); + stringMap.put("Thursday", "The day that says, 'Hold my beer, Friday is coming!'"); + stringMap.put("Friday", "The golden child of the weekdays. The superhero of the workweek."); + stringMap.put("Saturday", "The day of rest? More like the day of 'What can I binge-watch next?'"); + stringMap.put("Sunday", "The day before you have to adult again."); + } + + void skippingFirstElementInListWithForLoop(List stringList) { + for (int i = 1; i < stringList.size(); i++) { + process(stringList.get(i)); + } + } + + void skippingFirstElementInListWithWhileLoop(List stringList) { + final Iterator iterator = stringList.iterator(); + if (iterator.hasNext()) { + iterator.next(); + } + while (iterator.hasNext()) { + process(iterator.next()); + } + } + + void skippingFirstElementInSetWithWhileLoop(Set stringSet) { + final Iterator iterator = stringSet.iterator(); + if (iterator.hasNext()) { + iterator.next(); + } + while (iterator.hasNext()) { + process(iterator.next()); + } + } + + void skippingFirstElementInListWithWhileLoopStoringFirstElement(List stringList) { + final Iterator iterator = stringList.iterator(); + String firstElement = null; + if (iterator.hasNext()) { + firstElement = iterator.next(); + } + while (iterator.hasNext()) { + process(iterator.next()); + // additional logic using fistElement + } + } + + void skippingFirstElementInMapWithStreamSkip(Map stringMap) { + stringMap.entrySet().stream().skip(1).forEach(this::process); + } + + void skippingFirstElementInListWithSubList(List stringList) { + for (final String element : stringList.subList(1, stringList.size())) { + process(element); + } + } + + void skippingFirstElementInListWithForLoopWithAdditionalCheck(List stringList) { + for (int i = 0; i < stringList.size(); i++) { + if (i == 0) { + // do something else + } else { + process(stringList.get(i)); + } + } + } + + void skippingFirstElementInListWithWhileLoopWithCounter(List stringList) { + int counter = 0; + while (counter < stringList.size()) { + if (counter != 0) { + process(stringList.get(counter)); + } + ++counter; + } + } + + void skippingFirstElementInListWithReduce(List stringList) { + stringList.stream().reduce((skip, element) -> { + process(element); + return element; + }); + } + + protected void process(String string) { + System.out.println(string); + } + protected void process(Entry mapEntry) { + System.out.println(mapEntry); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/SkipFirstElementExampleUnitTest.java b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/SkipFirstElementExampleUnitTest.java new file mode 100644 index 0000000000..9821b22ac7 --- /dev/null +++ b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/SkipFirstElementExampleUnitTest.java @@ -0,0 +1,122 @@ +package com.baeldung.skippingfirstelement; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Stream; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +@EnabledForJreRange(min = JRE.JAVA_9) +class SkipFirstElementExampleUnitTest { + + private static TestableSkipFirstElement testableSkip = new TestableSkipFirstElement(); + + @BeforeEach + void setup() { + testableSkip.reset(); + } + + private static Stream listProvider() { + return Stream.of( + Arguments.of( + List.of("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"), + List.of("Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")) + ); + } + + private static Stream mapProvider() { + return Stream.of( + Arguments.of( + Map.of( + "Monday", "The day when coffee is a life support system.", + "Tuesday", "The day you realize that Monday's optimism was a lie.", + "Wednesday", "Hump Day, or as it's known, the 'Is it Friday yet?' day.", + "Thursday", "The day that says, 'Hold my beer, Friday is coming!'", + "Friday", "The golden child of the weekdays. The superhero of the workweek.", + "Saturday", "The day of rest? More like the day of 'What can I binge-watch next?'", + "Sunday", "The day before you have to adult again." + ) + ) + ); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInListWithForLoop(List input, List expected) { + testableSkip.skippingFirstElementInListWithForLoop(input); + List actual = testableSkip.getResult(); + assertEquals(actual, expected); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInListWithWhileLoop(List input, List expected) { + testableSkip.skippingFirstElementInListWithWhileLoop(input); + List actual = testableSkip.getResult(); + assertEquals(actual, expected); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInSetWithWhileLoop(List input) { + testableSkip.skippingFirstElementInSetWithWhileLoop(new HashSet<>(input)); + Set actual = new HashSet<>(testableSkip.getResult()); + assertEquals(actual.size(), input.size() - 1); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInListWithWhileLoopStoringFirstElement(List input, List expected) { + testableSkip.skippingFirstElementInListWithWhileLoopStoringFirstElement(input); + List actual = testableSkip.getResult(); + assertEquals(actual, expected); + } + + @ParameterizedTest + @MethodSource("mapProvider") + void skippingFirstElementInMapWithStreamSkip(Map input) { + testableSkip.skippingFirstElementInMapWithStreamSkip(input); + List actual = testableSkip.getResult(); + assertEquals(actual.size(), input.size() - 1); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInListWithSubList(List input, List expected) { + testableSkip.skippingFirstElementInListWithSubList(input); + List actual = testableSkip.getResult(); + assertEquals(actual, expected); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInListWithForLoopWithAdditionalCheck(List input, List expected) { + testableSkip.skippingFirstElementInListWithForLoopWithAdditionalCheck(input); + List actual = testableSkip.getResult(); + assertEquals(actual, expected); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInListWithWhileLoopWithCounter(List input, List expected) { + testableSkip.skippingFirstElementInListWithWhileLoopWithCounter(input); + List actual = testableSkip.getResult(); + assertEquals(actual, expected); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInListWithReduce(List input, List expected) { + testableSkip.skippingFirstElementInListWithReduce(input); + List actual = testableSkip.getResult(); + assertEquals(actual, expected); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkip.java b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkip.java new file mode 100644 index 0000000000..0e2f340485 --- /dev/null +++ b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkip.java @@ -0,0 +1,10 @@ +package com.baeldung.skippingfirstelement; + +import java.util.List; + +public interface TestableSkip { + + void reset(); + + List getResult(); +} diff --git a/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkipFirstElement.java b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkipFirstElement.java new file mode 100644 index 0000000000..99facb73ad --- /dev/null +++ b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkipFirstElement.java @@ -0,0 +1,37 @@ +package com.baeldung.skippingfirstelement; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; + +public class TestableSkipFirstElement extends SkipFirstElementExample implements TestableSkip { + + + private List processedList = new ArrayList<>(); + private List> processedEntryList = new ArrayList<>(); + + @Override + public void process(String string) { + processedList.add(string); + } + + @Override + public void process(Entry stringEntry) { + processedEntryList.add(stringEntry); + } + + @Override + public void reset() { + processedList.clear(); + processedEntryList.clear(); + } + + @Override + public List getResult() { + if (!processedList.isEmpty()) + return processedList; + return processedEntryList; + } + + +} From cafabdfe55fad89de6cb991a5a410b42bf25f1c2 Mon Sep 17 00:00:00 2001 From: Reza Ganji Date: Sat, 30 Sep 2023 03:53:21 +0330 Subject: [PATCH 127/193] BAEL-6082 RSocket Interface in Spring 6 (#14873) * Rsocket in spring framework6. * reformat code. * Reformate code with removing blank rows. * some changes in maven dependency and codes * moving spring boot dependency from parent to new projects.changing spring core version --------- Co-authored-by: rezaganjis --- parent-spring-6/pom.xml | 4 +- pom.xml | 1 + spring-6-rsocket/README.md | 7 ++ spring-6-rsocket/pom.xml | 74 +++++++++++++++++++ .../rsocket/requester/MessageClient.java | 21 ++++++ .../rsocket/responder/MessageController.java | 45 +++++++++++ .../rsocket/responder/RSocketApplication.java | 73 ++++++++++++++++++ .../src/main/resources/application.properties | 1 + ...RSocketRequestResponseIntegrationTest.java | 35 +++++++++ 9 files changed, 259 insertions(+), 2 deletions(-) create mode 100644 spring-6-rsocket/README.md create mode 100644 spring-6-rsocket/pom.xml create mode 100644 spring-6-rsocket/src/main/java/com/bealdung/rsocket/requester/MessageClient.java create mode 100644 spring-6-rsocket/src/main/java/com/bealdung/rsocket/responder/MessageController.java create mode 100644 spring-6-rsocket/src/main/java/com/bealdung/rsocket/responder/RSocketApplication.java create mode 100644 spring-6-rsocket/src/main/resources/application.properties create mode 100644 spring-6-rsocket/src/test/java/com/bealdung/rsocket/RSocketRequestResponseIntegrationTest.java diff --git a/parent-spring-6/pom.xml b/parent-spring-6/pom.xml index 77afe2072a..7b61ac524b 100644 --- a/parent-spring-6/pom.xml +++ b/parent-spring-6/pom.xml @@ -1,7 +1,7 @@ + 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"> 4.0.0 parent-spring-6 0.0.1-SNAPSHOT diff --git a/pom.xml b/pom.xml index 060f158888..e9a6da387b 100644 --- a/pom.xml +++ b/pom.xml @@ -892,6 +892,7 @@ spring-5 spring-5-webflux spring-5-webflux-2 + spring-6-rsocket spring-activiti spring-actuator spring-core-2 diff --git a/spring-6-rsocket/README.md b/spring-6-rsocket/README.md new file mode 100644 index 0000000000..21ab282bd1 --- /dev/null +++ b/spring-6-rsocket/README.md @@ -0,0 +1,7 @@ +## RSocket + +This module contains articles about RSocket in Spring Framework 6. + +### Relevant articles + +- [Introduction to RSocket](#) \ No newline at end of file diff --git a/spring-6-rsocket/pom.xml b/spring-6-rsocket/pom.xml new file mode 100644 index 0000000000..5d15a605ae --- /dev/null +++ b/spring-6-rsocket/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + com.bealdung + rsocket + 0.0.1-SNAPSHOT + rsocket + + + com.baeldung + parent-spring-6 + 0.0.1-SNAPSHOT + ../parent-spring-6 + + + + + + org.springframework.boot + spring-boot-starter-rsocket + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit + junit-bom + ${junit-jupiter.version} + pom + import + + + ch.qos.logback + logback-classic + ${logback.version} + + + ch.qos.logback + logback-core + ${logback.version} + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + 3.1.3 + 1.4.11 + 2.0.9 + + diff --git a/spring-6-rsocket/src/main/java/com/bealdung/rsocket/requester/MessageClient.java b/spring-6-rsocket/src/main/java/com/bealdung/rsocket/requester/MessageClient.java new file mode 100644 index 0000000000..8fed6bee9b --- /dev/null +++ b/spring-6-rsocket/src/main/java/com/bealdung/rsocket/requester/MessageClient.java @@ -0,0 +1,21 @@ +package com.bealdung.rsocket.requester; + +import org.springframework.messaging.rsocket.service.RSocketExchange; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public interface MessageClient { + + @RSocketExchange("MyDestination") + Mono sendMessage(Mono input); + + @RSocketExchange("Counter") + Flux Counter(); + + @RSocketExchange("Warning") + Mono Warning(Mono warning); + + @RSocketExchange("channel") + Flux channel(Flux input); +} diff --git a/spring-6-rsocket/src/main/java/com/bealdung/rsocket/responder/MessageController.java b/spring-6-rsocket/src/main/java/com/bealdung/rsocket/responder/MessageController.java new file mode 100644 index 0000000000..a2cfcc69ca --- /dev/null +++ b/spring-6-rsocket/src/main/java/com/bealdung/rsocket/responder/MessageController.java @@ -0,0 +1,45 @@ +package com.bealdung.rsocket.responder; + +import org.springframework.messaging.handler.annotation.MessageMapping; +import org.springframework.stereotype.Controller; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@Controller +public class MessageController { + + @MessageMapping("MyDestination") + public Mono message(Mono input) { + return input.doOnNext(msg -> System.out.println("Request is:" + msg + ",Request!")) + .map(msg -> msg + ",Response!"); + } + + @MessageMapping("Counter") + public Flux Counter() { + return Flux.range(1, 10) + .map(i -> "Count is: " + i); + } + + @MessageMapping("Warning") + public Mono Warning(Mono error) { + error.doOnNext(e -> System.out.println("warning is :" + e)) + .subscribe(); + return Mono.empty(); + } + + @MessageMapping("channel") + public Flux channel(Flux input) { + return input.doOnNext(i -> { + System.out.println("Received message is : " + i); + }) + .map(m -> m.toUpperCase()) + .doOnNext(r -> { + System.out.println("RESPONSE IS :" + r); + }); + } + +} + + + diff --git a/spring-6-rsocket/src/main/java/com/bealdung/rsocket/responder/RSocketApplication.java b/spring-6-rsocket/src/main/java/com/bealdung/rsocket/responder/RSocketApplication.java new file mode 100644 index 0000000000..9e763007fe --- /dev/null +++ b/spring-6-rsocket/src/main/java/com/bealdung/rsocket/responder/RSocketApplication.java @@ -0,0 +1,73 @@ +package com.bealdung.rsocket.responder; + +import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.messaging.rsocket.RSocketRequester; +import org.springframework.messaging.rsocket.service.RSocketServiceProxyFactory; + +import com.bealdung.rsocket.requester.MessageClient; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@SpringBootApplication +public class RSocketApplication { + public static void main(String[] args) { + SpringApplication.run(RSocketApplication.class, args); + } + + @Bean + public RSocketServiceProxyFactory getRSocketServiceProxyFactory(RSocketRequester.Builder requestBuilder) { + RSocketRequester requester = requestBuilder.tcp("localhost", 7000); + return RSocketServiceProxyFactory.builder(requester) + .build(); + } + + @Bean + public MessageClient getClient(RSocketServiceProxyFactory factory) { + return factory.createClient(MessageClient.class); + } + + @Bean + public ApplicationRunner runRequestResponseModel(MessageClient client) { + return args -> { + client.sendMessage(Mono.just("Request-Response test ")) + .doOnNext(message -> { + System.out.println("Response is :" + message); + }) + .subscribe(); + }; + } + + @Bean + public ApplicationRunner runStreamModel(MessageClient client) { + return args -> { + client.Counter() + .doOnNext(t -> { + System.out.println("message is :" + t); + }) + .subscribe(); + }; + } + + @Bean + public ApplicationRunner runFireAndForget(MessageClient client) { + return args -> { + client.Warning(Mono.just("Important Warning")) + .subscribe(); + }; + } + + @Bean + public ApplicationRunner runChannel(MessageClient client) { + return args -> { + client.channel(Flux.just("a", "b", "c", "d", "e")) + .doOnNext(i -> { + System.out.println(i); + }) + .subscribe(); + }; + } +} \ No newline at end of file diff --git a/spring-6-rsocket/src/main/resources/application.properties b/spring-6-rsocket/src/main/resources/application.properties new file mode 100644 index 0000000000..cab786cd30 --- /dev/null +++ b/spring-6-rsocket/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.rsocket.server.port=7000 \ No newline at end of file diff --git a/spring-6-rsocket/src/test/java/com/bealdung/rsocket/RSocketRequestResponseIntegrationTest.java b/spring-6-rsocket/src/test/java/com/bealdung/rsocket/RSocketRequestResponseIntegrationTest.java new file mode 100644 index 0000000000..4b85c4c6fc --- /dev/null +++ b/spring-6-rsocket/src/test/java/com/bealdung/rsocket/RSocketRequestResponseIntegrationTest.java @@ -0,0 +1,35 @@ +package com.bealdung.rsocket; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.messaging.rsocket.RSocketRequester; +import org.springframework.messaging.rsocket.service.RSocketServiceProxyFactory; + +import com.bealdung.rsocket.requester.MessageClient; +import com.bealdung.rsocket.responder.RSocketApplication; + +import reactor.core.publisher.Mono; + +@SpringBootTest(classes = RSocketApplication.class) +public class RSocketRequestResponseIntegrationTest { + + MessageClient client; + + public RSocketRequestResponseIntegrationTest() { + RSocketRequester.Builder requesterBuilder = RSocketRequester.builder(); + RSocketRequester requester = requesterBuilder.tcp("localhost", 7000); + RSocketServiceProxyFactory factory = RSocketServiceProxyFactory.builder(requester) + .build(); + client = factory.createClient(MessageClient.class); + } + + @Test + public void whenSendingStream_thenReceiveTheSameStream() { + String message = "test message"; + assertEquals(message, client.sendMessage(Mono.just(message)) + .block()); + } + +} From a93751923d4e79bb5d80ad155e6527e4e5688643 Mon Sep 17 00:00:00 2001 From: Ulisses Lima Date: Sat, 30 Sep 2023 03:44:07 -0300 Subject: [PATCH 128/193] BAEL 6701 - MongoDB - Atlas Search using the Java Driver and Spring Data (#14777) * research 1 * new search methods * first draft * removing old code * updated to parent-boot-3 --- .../spring-boot-persistence-mongodb-3/pom.xml | 36 +--- .../MongoDbAtlasSearchApplication.java | 12 ++ .../boot/atlassearch/config/IndexConfig.java | 22 +++ .../service/MovieAtlasSearchService.java | 183 ++++++++++++++++++ .../web/MovieAtlasSearchController.java | 48 +++++ .../src/main/resources/application.properties | 3 + .../MovieAtlasSearchServiceLiveTest.java | 67 +++++++ .../src/test/resources/embedded.properties | 2 +- 8 files changed, 342 insertions(+), 31 deletions(-) create mode 100644 persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/MongoDbAtlasSearchApplication.java create mode 100644 persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/config/IndexConfig.java create mode 100644 persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/service/MovieAtlasSearchService.java create mode 100644 persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/web/MovieAtlasSearchController.java create mode 100644 persistence-modules/spring-boot-persistence-mongodb-3/src/test/java/com/baeldung/boot/atlassearch/MovieAtlasSearchServiceLiveTest.java diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/pom.xml b/persistence-modules/spring-boot-persistence-mongodb-3/pom.xml index c48525673a..3f144bae54 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-3/pom.xml +++ b/persistence-modules/spring-boot-persistence-mongodb-3/pom.xml @@ -9,27 +9,12 @@ com.baeldung - parent-boot-2 + parent-boot-3 0.0.1-SNAPSHOT - ../../parent-boot-2 + ../../parent-boot-3 - - org.mongodb - mongodb-driver-sync - ${mongodb-driver.version} - - - org.mongodb - mongodb-driver-core - ${mongodb-driver.version} - - - org.mongodb - bson - ${mongodb-driver.version} - org.springframework.boot spring-boot-starter-web @@ -37,16 +22,6 @@ org.springframework.boot spring-boot-starter-data-mongodb - - - org.mongodb - mongodb-driver-sync - - - org.mongodb - mongodb-driver-core - - org.mongodb @@ -57,12 +32,13 @@ de.flapdoodle.embed de.flapdoodle.embed.mongo test + ${de.flapdoodle.embed.mongo.version} - 1.7.3 - 4.9.1 + com.baeldung.boot.atlassearch.MongoDbAtlasSearchApplication + 1.8.0 + 4.9.2 - diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/MongoDbAtlasSearchApplication.java b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/MongoDbAtlasSearchApplication.java new file mode 100644 index 0000000000..afaf524829 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/MongoDbAtlasSearchApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.boot.atlassearch; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MongoDbAtlasSearchApplication { + + public static void main(String... args) { + SpringApplication.run(MongoDbAtlasSearchApplication.class, args); + } +} diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/config/IndexConfig.java b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/config/IndexConfig.java new file mode 100644 index 0000000000..cb4fae89e4 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/config/IndexConfig.java @@ -0,0 +1,22 @@ +package com.baeldung.boot.atlassearch.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class IndexConfig { + + @Value("${com.baeldung.atlas-search.index.query}") + private String queryIndex; + + @Value("${com.baeldung.atlas-search.index.facet}") + private String facetIndex; + + public String getFacetIndex() { + return facetIndex; + } + + public String getQueryIndex() { + return queryIndex; + } +} diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/service/MovieAtlasSearchService.java b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/service/MovieAtlasSearchService.java new file mode 100644 index 0000000000..55d47759d5 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/service/MovieAtlasSearchService.java @@ -0,0 +1,183 @@ +package com.baeldung.boot.atlassearch.service; + +import static com.mongodb.client.model.Aggregates.facet; +import static com.mongodb.client.model.Aggregates.limit; +import static com.mongodb.client.model.Aggregates.project; +import static com.mongodb.client.model.Aggregates.replaceWith; +import static com.mongodb.client.model.Aggregates.search; +import static com.mongodb.client.model.Aggregates.searchMeta; +import static com.mongodb.client.model.Aggregates.skip; +import static com.mongodb.client.model.Projections.excludeId; +import static com.mongodb.client.model.Projections.fields; +import static com.mongodb.client.model.Projections.include; +import static com.mongodb.client.model.Projections.metaSearchScore; +import static com.mongodb.client.model.search.SearchCount.total; +import static com.mongodb.client.model.search.SearchFacet.combineToBson; +import static com.mongodb.client.model.search.SearchFacet.numberFacet; +import static com.mongodb.client.model.search.SearchFacet.stringFacet; +import static com.mongodb.client.model.search.SearchOperator.compound; +import static com.mongodb.client.model.search.SearchOperator.numberRange; +import static com.mongodb.client.model.search.SearchOperator.of; +import static com.mongodb.client.model.search.SearchOperator.text; +import static com.mongodb.client.model.search.SearchOptions.searchOptions; +import static com.mongodb.client.model.search.SearchPath.fieldPath; +import static java.util.Arrays.asList; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.apache.logging.log4j.LogManager; +import org.bson.Document; +import org.bson.conversions.Bson; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.stereotype.Service; + +import com.baeldung.boot.atlassearch.config.IndexConfig; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.model.Facet; +import com.mongodb.client.model.search.SearchScore; + +@Service +public class MovieAtlasSearchService { + + @Autowired + private IndexConfig config; + + private final MongoCollection collection; + + public MovieAtlasSearchService(MongoTemplate mongoTemplate) { + MongoDatabase database = mongoTemplate.getDb(); + this.collection = database.getCollection("movies"); + } + + public static void debug(List pipeline) { + StringBuilder builder = new StringBuilder("["); + final AtomicBoolean first = new AtomicBoolean(true); + pipeline.forEach(stage -> { + builder.append((first.get() ? "" : ",") + + stage.toBsonDocument() + ); + + first.set(false); + }); + builder.append("]"); + + LogManager.getLogger(MovieAtlasSearchService.class) + .debug(builder.toString()); + } + + public Document late90sMovies(int skip, int limit, String keywords, SearchScore modifier) { + List pipeline = asList( + search( + compound() + .must(asList( + numberRange( + fieldPath("year")) + .gteLt(1995, 2000) + )) + .should(asList( + text( + fieldPath("fullplot"), keywords + ) + .score(modifier) + )), + searchOptions() + .index(config.getQueryIndex()) + ), + project(fields( + excludeId(), + include("title", "year", "fullplot", "imdb.rating"), + metaSearchScore("score") + )), + facet( + new Facet("rows", + skip(skip), + limit(limit) + ), + new Facet("totalRows", + replaceWith("$$SEARCH_META"), + limit(1) + ) + ) + ); + + debug(pipeline); + return collection.aggregate(pipeline) + .first(); + } + + public Document countLate90sMovies(String keywords) { + List pipeline = asList( + searchMeta( + compound() + .must(asList( + numberRange( + fieldPath("year")) + .gteLt(1995, 2000), + text( + fieldPath("fullplot"), keywords + ) + )), + searchOptions() + .index(config.getQueryIndex()) + .count(total()) + ) + ); + + debug(pipeline); + return collection.aggregate(pipeline) + .first(); + } + + public Collection moviesByKeywords(String keywords) { + List pipeline = asList( + search( + text( + fieldPath("fullplot"), keywords + ), + searchOptions() + .index(config.getQueryIndex()) + ), + project(fields( + excludeId(), + include("title", "year", "fullplot", "imdb.rating") + )) + ); + + debug(pipeline); + return collection.aggregate(pipeline) + .into(new ArrayList()); + } + + public Document genresThroughTheDecades(String genre) { + List pipeline = asList( + searchMeta(of( + new Document("facet", + new Document("operator", + text( + fieldPath("genres"), genre + ) + ).append("facets", combineToBson(asList( + stringFacet("genresFacet", + fieldPath("genres") + ).numBuckets(5), + numberFacet("yearFacet", + fieldPath("year"), + asList(1900, 1930, 1960, 1990, 2020) + ) + ))) + )), + searchOptions() + .index(config.getFacetIndex()) + ) + ); + + debug(pipeline); + return collection.aggregate(pipeline) + .first(); + } +} diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/web/MovieAtlasSearchController.java b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/web/MovieAtlasSearchController.java new file mode 100644 index 0000000000..4c41915347 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/web/MovieAtlasSearchController.java @@ -0,0 +1,48 @@ +package com.baeldung.boot.atlassearch.web; + +import java.util.Collection; + +import org.bson.Document; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.boot.atlassearch.service.MovieAtlasSearchService; +import com.mongodb.client.model.search.SearchScore; + +@RestController +@RequestMapping("/movies") +public class MovieAtlasSearchController { + + @Autowired + private MovieAtlasSearchService service; + + @GetMapping("with/{keywords}") + Collection getMoviesWithKeywords(@PathVariable String keywords) { + return service.moviesByKeywords(keywords); + } + + @GetMapping("90s/with/{keywords}/count") + Document getCount90sMoviesWithKeywords(@PathVariable String keywords) { + return service.countLate90sMovies(keywords); + } + + @GetMapping("90s/{skip}/{limit}/with/{keywords}") + Document getMoviesUsingScoreBoost(@PathVariable int skip, @PathVariable int limit, @PathVariable String keywords) { + return service.late90sMovies(skip, limit, keywords, SearchScore.boost(2)); + } + + @PostMapping("90s/{skip}/{limit}/with/{keywords}") + Document getMoviesUsingScoringFunction(@RequestBody String jsonFunction, @PathVariable int skip, @PathVariable int limit, @PathVariable String keywords) { + return service.late90sMovies(skip, limit, keywords, SearchScore.of(new Document("function", Document.parse(jsonFunction)))); + } + + @GetMapping("by-genre/{genre}") + Document getMoviesWithFacets(@PathVariable String genre) { + return service.genresThroughTheDecades(genre); + } +} diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/main/resources/application.properties b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/resources/application.properties index 8309c4461f..02ba79e336 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-3/src/main/resources/application.properties +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/resources/application.properties @@ -1 +1,4 @@ spring.application.name=spring-boot-persistence-mongodb-3 + +com.baeldung.atlas-search.index.query=idx-queries +com.baeldung.atlas-search.index.facet=idx-facets \ No newline at end of file diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/test/java/com/baeldung/boot/atlassearch/MovieAtlasSearchServiceLiveTest.java b/persistence-modules/spring-boot-persistence-mongodb-3/src/test/java/com/baeldung/boot/atlassearch/MovieAtlasSearchServiceLiveTest.java new file mode 100644 index 0000000000..190ebc19d9 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/test/java/com/baeldung/boot/atlassearch/MovieAtlasSearchServiceLiveTest.java @@ -0,0 +1,67 @@ +package com.baeldung.boot.atlassearch; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.bson.Document; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.boot.atlassearch.service.MovieAtlasSearchService; +import com.mongodb.client.model.search.SearchScore; + +@DirtiesContext +@RunWith(SpringRunner.class) +@TestPropertySource("/embedded.properties") +@SpringBootTest(classes = MongoDbAtlasSearchApplication.class) +public class MovieAtlasSearchServiceLiveTest { + + @Autowired + private MovieAtlasSearchService service; + + @Test + public void givenScoreBoost_thenFirstItemContainsPlot() { + final String plot = "space"; + + Document movies = service.late90sMovies(0, 1, plot, SearchScore.boost(2)); + + assertTrue(movies.getList("rows", Document.class) + .iterator() + .next() + .getString("fullplot") + .contains(plot)); + } + + @Test + public void givenFacetOperator_thenCorrespondingBucketsReturned() { + final String genre = "Sci-Fi"; + + Document meta = service.genresThroughTheDecades(genre); + + Long lowerBound = meta + .get("count", Document.class) + .getLong("lowerBound"); + + Document genresFacetFirstBucket = meta.get("facet", Document.class) + .get("genresFacet", Document.class) + .getList("buckets", Document.class) + .iterator() + .next(); + + Document yearFacetFirstBucket = meta.get("facet", Document.class) + .get("yearFacet", Document.class) + .getList("buckets", Document.class) + .iterator() + .next(); + + assertEquals(lowerBound, genresFacetFirstBucket.getLong("count")); + assertEquals(genre, genresFacetFirstBucket.getString("_id")); + assertNotNull(yearFacetFirstBucket); + } +} diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/test/resources/embedded.properties b/persistence-modules/spring-boot-persistence-mongodb-3/src/test/resources/embedded.properties index cd1c1d43c7..f47eca5023 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-3/src/test/resources/embedded.properties +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/test/resources/embedded.properties @@ -1,4 +1,4 @@ -spring.mongodb.embedded.version=4.4.9 +spring.mongodb.embedded.version=4.9.2 #spring.data.mongodb.uri=changeit #spring.data.mongodb.database=changeit From 1775ac73f03b303a9cfa4e9fb1f5fc4e230e7d2e Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Sat, 30 Sep 2023 17:27:47 +0330 Subject: [PATCH 129/193] #BAEL-6916: add indentation and private access --- .../camel/jackson/FruitListJacksonUnmarshalUnitTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java index bb31884d11..8120eeffec 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java @@ -32,7 +32,7 @@ import static org.springframework.test.util.AssertionErrors.assertNotNull; public class FruitListJacksonUnmarshalUnitTest { @Autowired - ProducerTemplate template; + private ProducerTemplate template; @EndpointInject("mock:marshalledObject") private MockEndpoint mock; @@ -44,8 +44,8 @@ public class FruitListJacksonUnmarshalUnitTest { return new RouteBuilder() { @Override public void configure() throws Exception { - from("direct:jsonInput").unmarshal(new JacksonDataFormat(FruitList.class)) - .to("mock:marshalledObject"); + from("direct:jsonInput").unmarshal(new JacksonDataFormat(FruitList.class)) + .to("mock:marshalledObject"); } }; } From fad02f73d2cf9c22bb329f04b59044192d019222 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 30 Sep 2023 18:08:57 +0300 Subject: [PATCH 130/193] BAEL-6847 move article --- core-java-modules/core-java-string-operations-5/README.md | 1 - core-java-modules/core-java-string-operations-6/README.md | 2 ++ .../test/java/com/baeldung/replace/ReplaceStringUnitTest.java | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename core-java-modules/{core-java-string-operations-5 => core-java-string-operations-6}/src/test/java/com/baeldung/replace/ReplaceStringUnitTest.java (100%) diff --git a/core-java-modules/core-java-string-operations-5/README.md b/core-java-modules/core-java-string-operations-5/README.md index fda7f39654..dffd3c1ab6 100644 --- a/core-java-modules/core-java-string-operations-5/README.md +++ b/core-java-modules/core-java-string-operations-5/README.md @@ -11,4 +11,3 @@ - [Check if the First Letter of a String Is a Number](https://www.baeldung.com/java-check-if-string-starts-with-number) - [Print “” Quotes Around a String in Java](https://www.baeldung.com/java-string-print-quotes) - [Remove Punctuation From a String in Java](https://www.baeldung.com/java-remove-punctuation-from-string) -- [Replacing Single Quote with \’ in Java String](https://www.baeldung.com/java-replacing-single-quote-string) diff --git a/core-java-modules/core-java-string-operations-6/README.md b/core-java-modules/core-java-string-operations-6/README.md index 853d58287d..b4b78d1ad7 100644 --- a/core-java-modules/core-java-string-operations-6/README.md +++ b/core-java-modules/core-java-string-operations-6/README.md @@ -10,3 +10,5 @@ - [Check if a String Contains Non-Alphanumeric Characters](https://www.baeldung.com/java-string-test-special-characters) - [Check if a String Has All Unique Characters in Java](https://www.baeldung.com/java-check-string-all-unique-chars) - [Performance Comparison Between Different Java String Concatenation Methods](https://www.baeldung.com/java-string-concatenation-methods) +- [Replacing Single Quote with \’ in Java String](https://www.baeldung.com/java-replacing-single-quote-string) + diff --git a/core-java-modules/core-java-string-operations-5/src/test/java/com/baeldung/replace/ReplaceStringUnitTest.java b/core-java-modules/core-java-string-operations-6/src/test/java/com/baeldung/replace/ReplaceStringUnitTest.java similarity index 100% rename from core-java-modules/core-java-string-operations-5/src/test/java/com/baeldung/replace/ReplaceStringUnitTest.java rename to core-java-modules/core-java-string-operations-6/src/test/java/com/baeldung/replace/ReplaceStringUnitTest.java From 306f1335b8e25ebcf13c6911f33de3ff9901b17d Mon Sep 17 00:00:00 2001 From: Anton Dalagan Date: Sat, 30 Sep 2023 17:39:12 +0200 Subject: [PATCH 131/193] Bael 6962 convert double to float in java (#14883) * Commit 1 - Anton Dalagan Code for Evaluation article. Contains Unit tests, domain class, and App main method. * BAEL-6962 - Created unit test, and updated pom.xml * BAEL-6962 - Removed files unrelated to the article * BAEL-6962 - Added a declartions for float and double in diff class. Updated unit tests. --- .../core-java-numbers-conversions/pom.xml | 12 +++++++ .../FloatAndDoubleConversions.java | 15 +++++++++ .../FloatDoubleConversionsTest.java | 33 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 core-java-modules/core-java-numbers-conversions/src/main/java/com/baeldung/floatdoubleconversions/FloatAndDoubleConversions.java create mode 100644 core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsTest.java diff --git a/core-java-modules/core-java-numbers-conversions/pom.xml b/core-java-modules/core-java-numbers-conversions/pom.xml index f745b83f8a..d014675ead 100644 --- a/core-java-modules/core-java-numbers-conversions/pom.xml +++ b/core-java-modules/core-java-numbers-conversions/pom.xml @@ -18,6 +18,18 @@ commons-lang3 ${commons-lang3.version} + + org.testng + testng + RELEASE + test + + + junit + junit + 4.13.2 + test + diff --git a/core-java-modules/core-java-numbers-conversions/src/main/java/com/baeldung/floatdoubleconversions/FloatAndDoubleConversions.java b/core-java-modules/core-java-numbers-conversions/src/main/java/com/baeldung/floatdoubleconversions/FloatAndDoubleConversions.java new file mode 100644 index 0000000000..f4fd68550c --- /dev/null +++ b/core-java-modules/core-java-numbers-conversions/src/main/java/com/baeldung/floatdoubleconversions/FloatAndDoubleConversions.java @@ -0,0 +1,15 @@ +package com.baeldung.floatdoubleconversions; + +public class FloatAndDoubleConversions { + public static void main(String args[]){ + float vatRate = 14.432511f; + System.out.println("vatRate:"+vatRate); + Float localTaxRate = 20.12434f; + System.out.println("localTaxRate:"+localTaxRate); + + double shootingAverage = 56.00000000000001; + System.out.println("shootingAverage:"+shootingAverage); + Double assistAverage = 81.123000000045; + System.out.println("assistAverage:"+assistAverage); + } +} diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsTest.java new file mode 100644 index 0000000000..10e9fd4c36 --- /dev/null +++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsTest.java @@ -0,0 +1,33 @@ +package com.baeldung.floatdoubleconversions; + +import org.junit.Assert; +import org.junit.Test; + +public class FloatDoubleConversionsTest { + + @Test + public void whenDoubleType_thenFloatTypeSuccess(){ + double interestRatesYearly = 13.333333333333334; + float interest = (float) interestRatesYearly; + System.out.println(interest); //13.333333 + Assert.assertTrue(Float.class.isInstance(interest));//true + + Double monthlyRates = 2.111111111111112; + float rates = monthlyRates.floatValue(); + System.out.println(rates); //2.1111112 + Assert.assertTrue(Float.class.isInstance(rates));//true + } + @Test + public void whenFloatType_thenDoubleTypeSuccess(){ + float gradeAverage =2.05f; + double average = gradeAverage; + System.out.println(average); //2.049999952316284 + Assert.assertTrue(Double.class.isInstance(average));//true + + Float monthlyRates = 2.1111112f; + Double rates = monthlyRates.doubleValue(); + System.out.println(rates); //2.1111112 + Assert.assertTrue(Double.class.isInstance(rates));//true + } + +} From 88ea37c981bb68e0e59c0d22f021381e5335e1d3 Mon Sep 17 00:00:00 2001 From: balasr3 Date: Thu, 21 Sep 2023 23:59:34 +0530 Subject: [PATCH 132/193] BAEL-5889: Added code for Spy and SpyBean difference implementation --- .../baeldung/spytest/NotificationService.java | 11 +++++ .../main/java/com/baeldung/spytest/Order.java | 41 +++++++++++++++++++ .../com/baeldung/spytest/OrderRepository.java | 19 +++++++++ .../com/baeldung/spytest/OrderService.java | 21 ++++++++++ .../baeldung/spytest/SpyTestApplication.java | 12 ++++++ .../spytest/OrderServiceIntegrationTest.java | 32 +++++++++++++++ .../spytest/OrderServiceUnitTest.java | 39 ++++++++++++++++++ .../RunApplicationIntegrationTest.java | 1 + 8 files changed, 176 insertions(+) create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/NotificationService.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/Order.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderRepository.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderService.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/SpyTestApplication.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceUnitTest.java diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/NotificationService.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/NotificationService.java new file mode 100644 index 0000000000..521e3b076e --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/NotificationService.java @@ -0,0 +1,11 @@ +package com.baeldung.spytest; + +import org.springframework.stereotype.Component; + +@Component +public class NotificationService { + public void notify(Order order){ + System.out.println(order); + } + +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/Order.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/Order.java new file mode 100644 index 0000000000..b7d7fad9e3 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/Order.java @@ -0,0 +1,41 @@ +package com.baeldung.spytest; + +import java.util.UUID; + +public class Order { + + private UUID id; + + private String name; + + private double orderQuantity; + + private String address; + + public Order(UUID id, String name, double orderQuantity, String address) { + this.id = id; + this.name = name; + this.orderQuantity = orderQuantity; + this.address = address; + } + + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + + public String getName() { + return name; + } + + public double getOrderQuantity() { + return orderQuantity; + } + + public String getAddress() { + return address; + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderRepository.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderRepository.java new file mode 100644 index 0000000000..986f7abde2 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderRepository.java @@ -0,0 +1,19 @@ +package com.baeldung.spytest; + +import java.util.HashMap; +import java.util.UUID; + +import org.springframework.stereotype.Component; + +@Component +public class OrderRepository { + + public static final HashMap orders=new HashMap<>(); + + public Order save(Order order) { + UUID orderId = UUID.randomUUID(); + order.setId(orderId); + orders.put(UUID.randomUUID(), order); + return order; + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderService.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderService.java new file mode 100644 index 0000000000..d08c96f5ae --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderService.java @@ -0,0 +1,21 @@ +package com.baeldung.spytest; + +import org.springframework.stereotype.Service; + +@Service +public class OrderService { + + public final OrderRepository orderRepository; + + public final NotificationService notificationService; + + public OrderService(OrderRepository orderRepository, NotificationService notificationService) { + this.orderRepository = orderRepository; + this.notificationService = notificationService; + } + public Order save(Order order) { + order = orderRepository.save(order); + notificationService.notify(order); + return order; + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/SpyTestApplication.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/SpyTestApplication.java new file mode 100644 index 0000000000..bb2d3dc7d2 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/SpyTestApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.spytest; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +@SpringBootApplication +public class SpyTestApplication { + + public static void main(String[] args) { + SpringApplication.run(SpyTestApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceIntegrationTest.java new file mode 100644 index 0000000000..22b0388b13 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceIntegrationTest.java @@ -0,0 +1,32 @@ +package com.baeldung.spytest; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.SpyBean; + +@SpringBootTest +class OrderServiceIntegrationTest { + + @Autowired + OrderRepository orderRepository; + @SpyBean + NotificationService notificationService; + @SpyBean + OrderService orderService; + + @Test + void givenNotificationServiceIsUsingSpyBean_whenOrderServiceIsCalled_thenNotificationServiceSpyBeanShouldBeInvoked() { + + Order orderInput = new Order(null, "Test", 1.0, "17 St Andrews Croft, Leeds ,LS17 7TP"); + Order order = orderService.save(orderInput); + Assertions.assertNotNull(order); + Assertions.assertNotNull(order.getId()); + verify(notificationService).notify(any(Order.class)); + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceUnitTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceUnitTest.java new file mode 100644 index 0000000000..b8f18c804c --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceUnitTest.java @@ -0,0 +1,39 @@ +package com.baeldung.spytest; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.util.UUID; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Spy; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +class OrderServiceUnitTest { + + @Spy + OrderRepository orderRepository; + @Spy + NotificationService notificationService; + @InjectMocks + OrderService orderService; + + @Test + void givenNotificationServiceIsUsingSpy_whenOrderServiceIsCalled_thenNotificationServiceSpyShouldBeInvoked() { + + UUID orderId = UUID.randomUUID(); + Order orderInput = new Order(orderId, "Test", 1.0, "17 St Andrews Croft, Leeds ,LS17 7TP"); + doReturn(orderInput).when(orderRepository) + .save(any()); + Order order = orderService.save(orderInput); + Assertions.assertNotNull(order); + Assertions.assertEquals(orderId, order.getId()); + verify(notificationService).notify(any(Order.class)); + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationIntegrationTest.java index 26a7339f1d..3a8b74829e 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationIntegrationTest.java @@ -1,6 +1,7 @@ package com.baeldung.prevent.commandline.application.runner.execution; import org.junit.jupiter.api.Test; +import org.mockito.Spy; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.SpyBean; From 14f336cf1a3d249f5e4228116e93396f477464e6 Mon Sep 17 00:00:00 2001 From: balasr3 Date: Fri, 22 Sep 2023 00:01:01 +0530 Subject: [PATCH 133/193] BAEL-5889: Removed unnecessary change --- .../runner/execution/RunApplicationIntegrationTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationIntegrationTest.java index 3a8b74829e..26a7339f1d 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationIntegrationTest.java @@ -1,7 +1,6 @@ package com.baeldung.prevent.commandline.application.runner.execution; import org.junit.jupiter.api.Test; -import org.mockito.Spy; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.SpyBean; From f324a501654d71fa3cf1ae04cb4992bae27ba3b8 Mon Sep 17 00:00:00 2001 From: balasr3 Date: Sat, 23 Sep 2023 16:11:32 +0530 Subject: [PATCH 134/193] BAEL-5889: Updated with review comment to add another method inside @Spy which is served through a mock to demonstrate partial mock condition --- .../java/com/baeldung/spytest/ExternalAlertService.java | 6 ++++++ .../java/com/baeldung/spytest/NotificationService.java | 9 ++++++++- .../src/main/java/com/baeldung/spytest/Order.java | 8 ++++++++ .../main/java/com/baeldung/spytest/OrderRepository.java | 2 +- .../src/main/java/com/baeldung/spytest/OrderService.java | 4 ++++ .../java/com/baeldung/spytest/SpyTestApplication.java | 1 + .../baeldung/spytest/OrderServiceIntegrationTest.java | 3 +++ .../java/com/baeldung/spytest/OrderServiceUnitTest.java | 2 ++ 8 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/ExternalAlertService.java diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/ExternalAlertService.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/ExternalAlertService.java new file mode 100644 index 0000000000..fd321a0e68 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/ExternalAlertService.java @@ -0,0 +1,6 @@ +package com.baeldung.spytest; + +public interface ExternalAlertService { + public boolean alert(Order order); + +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/NotificationService.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/NotificationService.java index 521e3b076e..f0b2f92bee 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/NotificationService.java +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/NotificationService.java @@ -4,8 +4,15 @@ import org.springframework.stereotype.Component; @Component public class NotificationService { - public void notify(Order order){ + + private ExternalAlertService externalAlertService; + + public void notify(Order order) { System.out.println(order); } + public boolean raiseAlert(Order order) { + return externalAlertService.alert(order); + } + } diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/Order.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/Order.java index b7d7fad9e3..23f5a05e9d 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/Order.java +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/Order.java @@ -8,6 +8,8 @@ public class Order { private String name; + private OrderType orderType; + private double orderQuantity; private String address; @@ -19,6 +21,10 @@ public class Order { this.address = address; } + public enum OrderType { + INDIVIDUAL, BULK; + } + public UUID getId() { return id; } @@ -39,3 +45,5 @@ public class Order { return address; } } + + diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderRepository.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderRepository.java index 986f7abde2..90fe5ba2b8 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderRepository.java +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderRepository.java @@ -8,7 +8,7 @@ import org.springframework.stereotype.Component; @Component public class OrderRepository { - public static final HashMap orders=new HashMap<>(); + public static final HashMap orders = new HashMap<>(); public Order save(Order order) { UUID orderId = UUID.randomUUID(); diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderService.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderService.java index d08c96f5ae..47647b8721 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderService.java +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/OrderService.java @@ -13,9 +13,13 @@ public class OrderService { this.orderRepository = orderRepository; this.notificationService = notificationService; } + public Order save(Order order) { order = orderRepository.save(order); notificationService.notify(order); + if (!notificationService.raiseAlert(order)) { + throw new RuntimeException("Alert not raised"); + } return order; } } diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/SpyTestApplication.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/SpyTestApplication.java index bb2d3dc7d2..d8d81378df 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/SpyTestApplication.java +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/spytest/SpyTestApplication.java @@ -2,6 +2,7 @@ package com.baeldung.spytest; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; + @SpringBootApplication public class SpyTestApplication { diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceIntegrationTest.java index 22b0388b13..96c7b09dfc 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceIntegrationTest.java @@ -1,6 +1,7 @@ package com.baeldung.spytest; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import org.junit.jupiter.api.Assertions; @@ -23,6 +24,8 @@ class OrderServiceIntegrationTest { void givenNotificationServiceIsUsingSpyBean_whenOrderServiceIsCalled_thenNotificationServiceSpyBeanShouldBeInvoked() { Order orderInput = new Order(null, "Test", 1.0, "17 St Andrews Croft, Leeds ,LS17 7TP"); + doReturn(true).when(notificationService) + .raiseAlert(any(Order.class)); Order order = orderService.save(orderInput); Assertions.assertNotNull(order); Assertions.assertNotNull(order.getId()); diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceUnitTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceUnitTest.java index b8f18c804c..21ae849bcf 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceUnitTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/spytest/OrderServiceUnitTest.java @@ -30,6 +30,8 @@ class OrderServiceUnitTest { Order orderInput = new Order(orderId, "Test", 1.0, "17 St Andrews Croft, Leeds ,LS17 7TP"); doReturn(orderInput).when(orderRepository) .save(any()); + doReturn(true).when(notificationService) + .raiseAlert(any(Order.class)); Order order = orderService.save(orderInput); Assertions.assertNotNull(order); Assertions.assertEquals(orderId, order.getId()); From 87056d13bc8b6a6b423b0c84b568f39cfeb1fd10 Mon Sep 17 00:00:00 2001 From: balasr3 Date: Sun, 1 Oct 2023 07:28:57 +0530 Subject: [PATCH 135/193] BAEL-7032: Improvement to conditional mapping by using @Condition and added tests --- .../baeldung/expression/dto/LicenseDto.java | 10 +++++++ .../expression/mapper/LicenseMapper.java | 12 +++++++- .../baeldung/expression/model/License.java | 16 ++++++++++- .../mapper/LicenseMapperUnitTest.java | 28 +++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/mapstruct/src/main/java/com/baeldung/expression/dto/LicenseDto.java b/mapstruct/src/main/java/com/baeldung/expression/dto/LicenseDto.java index 025df1a4f6..1d7cacaead 100644 --- a/mapstruct/src/main/java/com/baeldung/expression/dto/LicenseDto.java +++ b/mapstruct/src/main/java/com/baeldung/expression/dto/LicenseDto.java @@ -11,6 +11,8 @@ public class LicenseDto { private LocalDateTime endDate; + private String licenseType; + public UUID getId() { return id; } @@ -35,4 +37,12 @@ public class LicenseDto { this.endDate = endDate; } + public String getLicenseType() { + return licenseType; + } + + public void setLicenseType(String licenseType) { + this.licenseType = licenseType; + } + } diff --git a/mapstruct/src/main/java/com/baeldung/expression/mapper/LicenseMapper.java b/mapstruct/src/main/java/com/baeldung/expression/mapper/LicenseMapper.java index 100588b45d..0d8904e220 100644 --- a/mapstruct/src/main/java/com/baeldung/expression/mapper/LicenseMapper.java +++ b/mapstruct/src/main/java/com/baeldung/expression/mapper/LicenseMapper.java @@ -6,6 +6,7 @@ import java.time.OffsetDateTime; import java.time.ZoneOffset; import org.mapstruct.AfterMapping; +import org.mapstruct.Condition; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; @@ -40,4 +41,13 @@ public interface LicenseMapper { .toDays() <= 14; } -} + @Condition + default boolean mapsToExpectedLicenseType(String licenseType) { + try { + return licenseType != null && License.LicenseType.valueOf(licenseType) != null; + } catch (IllegalArgumentException e) { + return false; + } + } + +} \ No newline at end of file diff --git a/mapstruct/src/main/java/com/baeldung/expression/model/License.java b/mapstruct/src/main/java/com/baeldung/expression/model/License.java index 71e4f086c0..550d23eee8 100644 --- a/mapstruct/src/main/java/com/baeldung/expression/model/License.java +++ b/mapstruct/src/main/java/com/baeldung/expression/model/License.java @@ -16,6 +16,8 @@ public class License { private boolean renewalRequired; + private LicenseType licenseType; + public UUID getId() { return id; } @@ -55,4 +57,16 @@ public class License { public void setRenewalRequired(boolean renewalRequired) { this.renewalRequired = renewalRequired; } -} + + public enum LicenseType { + INDIVIDUAL, FAMILY + } + + public LicenseType getLicenseType() { + return licenseType; + } + + public void setLicenseType(LicenseType licenseType) { + this.licenseType = licenseType; + } +} \ No newline at end of file diff --git a/mapstruct/src/test/java/com/baeldung/expression/mapper/LicenseMapperUnitTest.java b/mapstruct/src/test/java/com/baeldung/expression/mapper/LicenseMapperUnitTest.java index dcdda5c1ac..8c015674bc 100644 --- a/mapstruct/src/test/java/com/baeldung/expression/mapper/LicenseMapperUnitTest.java +++ b/mapstruct/src/test/java/com/baeldung/expression/mapper/LicenseMapperUnitTest.java @@ -6,6 +6,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.util.UUID; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mapstruct.factory.Mappers; @@ -74,4 +75,31 @@ class LicenseMapperUnitTest { assertThat(license.getId()).isSameAs(id); } + @Test + void givenLicenseDtoWithoutLicenseTypeString_WhenMapperMethodIsInvoked_ThenLicenseShouldBePopulatedWithoutLicenseType() { + LicenseDto licenseDto = new LicenseDto(); + License license = licenseMapper.toLicense(licenseDto); + assertThat(license).isNotNull(); + Assertions.assertNull(license.getLicenseType()); + } + + @Test + void givenLicenseDtoWithInvalidLicenseTypeString_WhenMapperMethodIsInvoked_ThenLicenseShouldBePopulatedWithoutLicenseType() { + LicenseDto licenseDto = new LicenseDto(); + licenseDto.setLicenseType("invalid_license_type"); + License license = licenseMapper.toLicense(licenseDto); + assertThat(license).isNotNull(); + Assertions.assertNull(license.getLicenseType()); + } + + @Test + void givenLicenseDtoWithValidLicenseTypeString_WhenMapperMethodIsInvoked_ThenLicenseShouldBePopulatedWithMatchingLicenseType() { + LicenseDto licenseDto = new LicenseDto(); + licenseDto.setLicenseType("INDIVIDUAL"); + License license = licenseMapper.toLicense(licenseDto); + assertThat(license).isNotNull(); + Assertions.assertNotNull(license.getLicenseType()); + assertThat(license.getLicenseType()).isEqualTo(License.LicenseType.INDIVIDUAL); + } + } \ No newline at end of file From 96de260e1dbfbcc65495dfac7969cc5ef5abb2d9 Mon Sep 17 00:00:00 2001 From: balasr3 Date: Sun, 1 Oct 2023 07:30:17 +0530 Subject: [PATCH 136/193] BAEL-7032: updated formatting --- .../src/main/java/com/baeldung/expression/model/License.java | 1 - 1 file changed, 1 deletion(-) diff --git a/mapstruct/src/main/java/com/baeldung/expression/model/License.java b/mapstruct/src/main/java/com/baeldung/expression/model/License.java index 550d23eee8..e36e278a57 100644 --- a/mapstruct/src/main/java/com/baeldung/expression/model/License.java +++ b/mapstruct/src/main/java/com/baeldung/expression/model/License.java @@ -3,7 +3,6 @@ package com.baeldung.expression.model; import java.time.OffsetDateTime; import java.util.UUID; - public class License { private UUID id; From 9c17051f2af28123814aba0c811a99e40e0e3681 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Sun, 1 Oct 2023 13:31:41 +0330 Subject: [PATCH 137/193] #BAEL-7076: add indentation --- .../camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java index df7a57a984..ab5993d816 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java @@ -45,8 +45,8 @@ public class FruitArrayJacksonUnmarshalUnitTest { return new RouteBuilder() { @Override public void configure() throws Exception { - from("direct:jsonInput").unmarshal(new ListJacksonDataFormat(Fruit.class)) - .to("mock:marshalledObject"); + from("direct:jsonInput").unmarshal(new ListJacksonDataFormat(Fruit.class)) + .to("mock:marshalledObject"); } }; } From ae29eca0f8188b12b71ea8430ffa429535cf694b Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Sun, 1 Oct 2023 12:22:34 -0300 Subject: [PATCH 138/193] BAEL-6927: Update article "Understanding Kafka Topics and Partitions" (#14837) * consumer config. topic config. driver and calculator classes. * basic app working. test structure * final version * wraping up * optimizing imports * comments changes * addressing improvement changes --- .../TemperatureConsumer.java | 17 +++++------------ ...KafkaTopicsAndPartitionsIntegrationTest.java | 4 +--- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/topicsandpartitions/TemperatureConsumer.java b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/topicsandpartitions/TemperatureConsumer.java index 7cfbdd5fb0..2919ae1d7b 100644 --- a/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/topicsandpartitions/TemperatureConsumer.java +++ b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/topicsandpartitions/TemperatureConsumer.java @@ -8,29 +8,22 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CountDownLatch; @Service public class TemperatureConsumer { - private CountDownLatch latch = new CountDownLatch(1); - Map> consumedRecords = new ConcurrentHashMap<>(); @KafkaListener(topics = "celcius-scale-topic", groupId = "group-1") public void consumer1(ConsumerRecord consumerRecord) { - computeConsumedRecord("consumer-1", consumerRecord.partition()); + trackConsumedPartitions("consumer-1", consumerRecord.partition()); } - private void computeConsumedRecord(String key, int consumerRecord) { - consumedRecords.computeIfAbsent(key, k -> new HashSet<>()); - consumedRecords.computeIfPresent(key, (k, v) -> { - v.add(String.valueOf(consumerRecord)); + private void trackConsumedPartitions(String consumerName, int partitionNumber) { + consumedRecords.computeIfAbsent(consumerName, k -> new HashSet<>()); + consumedRecords.computeIfPresent(consumerName, (k, v) -> { + v.add(String.valueOf(partitionNumber)); return v; }); } - - public CountDownLatch getLatch() { - return latch; - } } diff --git a/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/topicsandpartitions/KafkaTopicsAndPartitionsIntegrationTest.java b/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/topicsandpartitions/KafkaTopicsAndPartitionsIntegrationTest.java index 309c87125a..de720ef955 100644 --- a/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/topicsandpartitions/KafkaTopicsAndPartitionsIntegrationTest.java +++ b/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/topicsandpartitions/KafkaTopicsAndPartitionsIntegrationTest.java @@ -7,8 +7,6 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.kafka.test.EmbeddedKafkaBroker; import org.springframework.kafka.test.context.EmbeddedKafka; -import java.util.concurrent.TimeUnit; - @SpringBootTest(classes = ThermostatApplicationKafkaApp.class) @EmbeddedKafka(partitions = 2, brokerProperties = {"listeners=PLAINTEXT://localhost:9092", "port=9092"}) public class KafkaTopicsAndPartitionsIntegrationTest { @@ -24,7 +22,7 @@ public class KafkaTopicsAndPartitionsIntegrationTest { @Test public void givenTopic_andConsumerGroup_whenConsumersListenToEvents_thenConsumeItCorrectly() throws Exception { service.measureCelsiusAndPublish(10000); - consumer.getLatch().await(1, TimeUnit.SECONDS); + Thread.sleep(1000); System.out.println(consumer.consumedRecords); } } From 9ca51279aee091b53da22a5621cba4239d8e569d Mon Sep 17 00:00:00 2001 From: Maiklins Date: Sun, 1 Oct 2023 21:56:19 +0200 Subject: [PATCH 139/193] Update README.md --- core-java-modules/core-java-collections-array-list-2/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-collections-array-list-2/README.md b/core-java-modules/core-java-collections-array-list-2/README.md index 00c3e8d9b7..dbf5c47edb 100644 --- a/core-java-modules/core-java-collections-array-list-2/README.md +++ b/core-java-modules/core-java-collections-array-list-2/README.md @@ -2,4 +2,5 @@ This module contains articles about the Java ArrayList collection -### Relevant Articles: \ No newline at end of file +### Relevant Articles: +- [Create an ArrayList with Multiple Object Types](https://www.baeldung.com/arraylist-with-multiple-object-types) From 39c353c6aeec68b85418da16a3907a98ef9869ea Mon Sep 17 00:00:00 2001 From: mcasari Date: Sun, 1 Oct 2023 21:58:55 +0200 Subject: [PATCH 140/193] BAEL-6846 - updates due to further discussion about float representation --- .../FloatToBigDecimalUnitTest.java | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java index 2d6d1ab5d0..8895c01575 100644 --- a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java +++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java @@ -16,45 +16,44 @@ class FloatToBigDecimalUnitTest { } @Test - public void whenCreatedFromCertainFloatValues_thenMatches() { - float floatToConvert = 0.5f; - BigDecimal bdFromFloat = new BigDecimal(floatToConvert); - assertEquals("0.5", bdFromFloat.toString()); - } - - @Test - public void whenCreatedFromCertainFloatValues_thenDoesNotMatch() { + public void whenCreatedFromFloat_thenMatchesInternallyStoredValue() { float floatToConvert = 1.1f; BigDecimal bdFromFloat = new BigDecimal(floatToConvert); assertEquals("1.10000002384185791015625", bdFromFloat.toString()); } @Test - public void whenCreatedFromString_thenMatches() { - String floatValue = Float.toString(1.1f); - BigDecimal bdFromString = new BigDecimal(floatValue); + public void whenCreatedFromString_thenPreservesTheOriginal() { + BigDecimal bdFromString = new BigDecimal("1.1"); assertEquals("1.1", bdFromString.toString()); } @Test - public void whenCreatedByValueOfAndIsFloat_thenDoesNotMatch() { - float floatToConvert = 1.1f; - BigDecimal bdByValueOf = BigDecimal.valueOf(floatToConvert); - assertEquals("1.100000023841858", bdByValueOf.toString()); + public void whenCreatedFromFloatConvertedToString_thenFloatInternalValueGetsTruncated() { + String floatValue = Float.toString(1.1f); + BigDecimal bdFromString = new BigDecimal(floatValue); + assertEquals("1.1", floatValue); + assertEquals("1.1", bdFromString.toString()); } @Test - public void whenFloatCastToDouble_thenGotADifferentNumber() { - float floatToConvert = 1.1f; - double doubleCast = floatToConvert; - assertEquals("1.100000023841858", Double.toString(doubleCast)); + public void whenFloatConvertedToString_thenGetsTruncated() { + String floatValue = Float.toString(1.10000002384185791015625f); + assertEquals("1.1", floatValue); } @Test - public void whenCreatedByValueOfAndIsDouble_thenMatches() { - double doubleToConvert = 1.1d; - BigDecimal bdByValueOf = BigDecimal.valueOf(doubleToConvert); - assertEquals("1.1", bdByValueOf.toString()); + public void whenCreatedByValueOf_thenFloatValueGetsTruncated() { + assertEquals("1.100000023841858", BigDecimal.valueOf(1.1f) + .toString()); + assertEquals("1.100000023841858", BigDecimal.valueOf(1.10000002384185791015625f) + .toString()); + } + + @Test + public void whenDoubleConvertsFloatToString_thenFloatValueGetsTruncated() { + assertEquals("1.100000023841858", Double.toString(1.1f)); + assertEquals("1.100000023841858", Double.toString(1.10000002384185791015625f)); } } \ No newline at end of file From 071d0ca2e93c3a49dfa26f9b5a0e2a010ac33c74 Mon Sep 17 00:00:00 2001 From: brokenhardisk Date: Mon, 2 Oct 2023 07:03:58 +0200 Subject: [PATCH 141/193] BAEL-6849 Junit Tests for Interfaces in Java (#14847) * BAEL-6849 Junit Tests for Interfaces in Java * BAEL-6849 Junit Tests for Interfaces in Java * BAEL-6849 Junit Tests for Interfaces in Java * BAEL-6849 JUnit Tests for Interfaces in Java --- .../baeldung/interfaces/unittest/Circle.java | 19 +++++++++++++ .../interfaces/unittest/Rectangle.java | 21 +++++++++++++++ .../baeldung/interfaces/unittest/Shape.java | 6 +++++ .../unittest/CircleExtendsBaseUnitTest.java | 26 ++++++++++++++++++ .../interfaces/unittest/CircleUnitTest.java | 22 +++++++++++++++ .../unittest/ParameterizedUnitTest.java | 27 +++++++++++++++++++ .../RectangleExtendsBaseUnitTest.java | 26 ++++++++++++++++++ .../unittest/RectangleUnitTest.java | 22 +++++++++++++++ .../interfaces/unittest/ShapeUnitTest.java | 21 +++++++++++++++ 9 files changed, 190 insertions(+) create mode 100644 testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Circle.java create mode 100644 testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Rectangle.java create mode 100644 testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Shape.java create mode 100644 testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/CircleExtendsBaseUnitTest.java create mode 100644 testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/CircleUnitTest.java create mode 100644 testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/ParameterizedUnitTest.java create mode 100644 testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/RectangleExtendsBaseUnitTest.java create mode 100644 testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/RectangleUnitTest.java create mode 100644 testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/ShapeUnitTest.java diff --git a/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Circle.java b/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Circle.java new file mode 100644 index 0000000000..b0e63155f4 --- /dev/null +++ b/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Circle.java @@ -0,0 +1,19 @@ +package com.baeldung.interfaces.unittest; + +public class Circle implements Shape { + + private double radius; + + Circle(double radius) { + this.radius = radius; + } + + @Override + public double area() { + return 3.14 * radius * radius; + } + + public double circumference() { + return 2 * 3.14 * radius; + } +} diff --git a/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Rectangle.java b/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Rectangle.java new file mode 100644 index 0000000000..a88233e83b --- /dev/null +++ b/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Rectangle.java @@ -0,0 +1,21 @@ +package com.baeldung.interfaces.unittest; + +public class Rectangle implements Shape { + + private double length; + private double breadth; + + public Rectangle(double length, double breadth) { + this.length = length; + this.breadth = breadth; + } + + @Override + public double area() { + return length * breadth; + } + + public double perimeter() { + return 2 * (length + breadth); + } +} diff --git a/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Shape.java b/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Shape.java new file mode 100644 index 0000000000..bac42fb246 --- /dev/null +++ b/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Shape.java @@ -0,0 +1,6 @@ +package com.baeldung.interfaces.unittest; + +public interface Shape { + + double area(); +} diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/CircleExtendsBaseUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/CircleExtendsBaseUnitTest.java new file mode 100644 index 0000000000..08ce2bc779 --- /dev/null +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/CircleExtendsBaseUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.interfaces.unittest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +class CircleExtendsBaseUnitTest extends ShapeUnitTest { + + @Override + public Map instantiateShapeWithExpectedArea() { + Map shapeAreaMap = new HashMap<>(); + shapeAreaMap.put("shape", new Circle(5)); + shapeAreaMap.put("area", 78.5); + return shapeAreaMap; + } + + @Test + void whenCircumferenceIsCalculated_thenSuccessful() { + Circle circle = new Circle(2); + double circumference = circle.circumference(); + assertEquals(12.56, circumference); + } +} \ No newline at end of file diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/CircleUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/CircleUnitTest.java new file mode 100644 index 0000000000..c0b4eecedc --- /dev/null +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/CircleUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung.interfaces.unittest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class CircleUnitTest { + + @Test + void whenAreaIsCalculated_thenSuccessful() { + Shape circle = new Circle(5); + double area = circle.area(); + assertEquals(78.5, area); + } + + @Test + void whenCircumferenceIsCalculated_thenSuccessful() { + Circle circle = new Circle(2); + double circumference = circle.circumference(); + assertEquals(12.56, circumference); + } +} \ No newline at end of file diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/ParameterizedUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/ParameterizedUnitTest.java new file mode 100644 index 0000000000..6b5cd6b6ab --- /dev/null +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/ParameterizedUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.interfaces.unittest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Arrays; +import java.util.Collection; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class ParameterizedUnitTest { + + @ParameterizedTest + @MethodSource("data") + void givenShapeInstance_whenAreaIsCalculated_thenSuccessful(Shape shapeInstance, double expectedArea) { + double area = shapeInstance.area(); + assertEquals(expectedArea, area); + + } + + private static Collection data() { + return Arrays.asList(new Object[][] { + { new Circle(5), 78.5 }, + { new Rectangle(4, 5), 20 } + }); + } +} diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/RectangleExtendsBaseUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/RectangleExtendsBaseUnitTest.java new file mode 100644 index 0000000000..b6771ad648 --- /dev/null +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/RectangleExtendsBaseUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.interfaces.unittest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +class RectangleExtendsBaseUnitTest extends ShapeUnitTest { + + @Override + public Map instantiateShapeWithExpectedArea() { + Map shapeAreaMap = new HashMap<>(); + shapeAreaMap.put("shape", new Rectangle(5, 4)); + shapeAreaMap.put("area", 20.0); + return shapeAreaMap; + } + + @Test + void whenPerimeterIsCalculated_thenSuccessful() { + Rectangle rectangle = new Rectangle(5, 4); + double perimeter = rectangle.perimeter(); + assertEquals(18, perimeter); + } +} \ No newline at end of file diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/RectangleUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/RectangleUnitTest.java new file mode 100644 index 0000000000..1983353667 --- /dev/null +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/RectangleUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung.interfaces.unittest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class RectangleUnitTest { + + @Test + void whenAreaIsCalculated_thenSuccessful() { + Shape rectangle = new Rectangle(5, 4); + double area = rectangle.area(); + assertEquals(20, area); + } + + @Test + void whenPerimeterIsCalculated_thenSuccessful() { + Rectangle rectangle = new Rectangle(5, 4); + double perimeter = rectangle.perimeter(); + assertEquals(18, perimeter); + } +} \ No newline at end of file diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/ShapeUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/ShapeUnitTest.java new file mode 100644 index 0000000000..a9d318f698 --- /dev/null +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/ShapeUnitTest.java @@ -0,0 +1,21 @@ +package com.baeldung.interfaces.unittest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +public abstract class ShapeUnitTest { + + public abstract Map instantiateShapeWithExpectedArea(); + + @Test + void givenShapeInstance_whenAreaIsCalculated_thenSuccessful() { + Map shapeAreaMap = instantiateShapeWithExpectedArea(); + Shape shape = (Shape) shapeAreaMap.get("shape"); + double expectedArea = (double) shapeAreaMap.get("area"); + double area = shape.area(); + assertEquals(expectedArea, area); + } +} From 2ed008decce1d050044cd79f5f5c3d077c147981 Mon Sep 17 00:00:00 2001 From: mdabrowski-eu <57441874+mdabrowski-eu@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:53:53 +0200 Subject: [PATCH 142/193] BAEL-6911 A Guide to RestClient in Spring Boot (#14893) --- spring-boot-modules/spring-boot-3/pom.xml | 61 +++++++++- .../java/com/baeldung/restclient/Article.java | 34 ++++++ .../restclient/ArticleController.java | 45 +++++++ .../restclient/RestClientApplication.java | 13 ++ .../restclient/RestClientIntegrationTest.java | 114 ++++++++++++++++++ 5 files changed, 266 insertions(+), 1 deletion(-) create mode 100644 spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/Article.java create mode 100644 spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleController.java create mode 100644 spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/RestClientApplication.java create mode 100644 spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/restclient/RestClientIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-3/pom.xml b/spring-boot-modules/spring-boot-3/pom.xml index 7e61ca18af..7dd44c89dc 100644 --- a/spring-boot-modules/spring-boot-3/pom.xml +++ b/spring-boot-modules/spring-boot-3/pom.xml @@ -41,6 +41,27 @@ mockserver-netty ${mockserver.version} + + org.junit.jupiter + junit-jupiter + ${jupiter.version} + + + org.junit.jupiter + junit-jupiter-api + ${jupiter.version} + + + org.junit.jupiter + junit-jupiter-engine + ${jupiter.version} + + + org.junit.jupiter + junit-jupiter-params + ${jupiter.version} + test + org.mock-server mockserver-client-java @@ -187,8 +208,46 @@ 3.0.0-M7 com.baeldung.sample.TodoApplication 5.14.0 - 3.1.0 + 3.2.0-SNAPSHOT 0.2.0 + 5.10.0 + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + false + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + false + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/Article.java b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/Article.java new file mode 100644 index 0000000000..a69d5989af --- /dev/null +++ b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/Article.java @@ -0,0 +1,34 @@ +package com.baeldung.restclient; + +import java.util.Objects; + +public class Article { + Integer id; + String title; + + public Article(Integer id, String title) { + this.id = id; + this.title = title; + } + + public Integer getId() { + return id; + } + + public String getTitle() { + return title; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Article article = (Article) o; + return Objects.equals(id, article.id) && Objects.equals(title, article.title); + } + + @Override + public int hashCode() { + return Objects.hash(id, title); + } +} diff --git a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleController.java b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleController.java new file mode 100644 index 0000000000..62922bdcee --- /dev/null +++ b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleController.java @@ -0,0 +1,45 @@ +package com.baeldung.restclient; + +import org.springframework.web.bind.annotation.*; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@RestController +@RequestMapping("/articles") +public class ArticleController { + Map database = new HashMap<>(); + + @GetMapping + public Collection
getArticles() { + return database.values(); + } + + @GetMapping("/{id}") + public Article getArticle(@PathVariable Integer id) { + return database.get(id); + } + + @PostMapping + public void createArticle(@RequestBody Article article) { + database.put(article.getId(), article); + } + + @PutMapping("/{id}") + public void updateArticle(@PathVariable Integer id, @RequestBody Article article) { + assert Objects.equals(id, article.getId()); + database.remove(id); + database.put(id, article); + } + + @DeleteMapping("/{id}") + public void deleteArticle(@PathVariable Integer id) { + database.remove(id); + } + @DeleteMapping() + public void deleteArticles() { + database.clear(); + } +} diff --git a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/RestClientApplication.java b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/RestClientApplication.java new file mode 100644 index 0000000000..c411a8f74a --- /dev/null +++ b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/RestClientApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.restclient; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class RestClientApplication { + + public static void main(String[] args) { + SpringApplication.run(RestClientApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/restclient/RestClientIntegrationTest.java b/spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/restclient/RestClientIntegrationTest.java new file mode 100644 index 0000000000..92474c88f0 --- /dev/null +++ b/spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/restclient/RestClientIntegrationTest.java @@ -0,0 +1,114 @@ +package com.baeldung.restclient; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.MediaType; +import org.springframework.web.client.RestClient; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class RestClientIntegrationTest { + + @LocalServerPort + private int port; + private String uriBase; + RestClient restClient = RestClient.create(); + + @BeforeAll + public void setup() { + uriBase = "http://localhost:" + port; + } + + @AfterEach + public void teardown() { + restClient.delete() + .uri(uriBase + "/articles") + .retrieve() + .toBodilessEntity(); + } + + @Test + void shouldGetArticlesAndReturnString() { + String articlesAsString = restClient.get() + .uri(uriBase + "/articles") + .retrieve() + .body(String.class); + + assertThat(articlesAsString).isEqualTo("[]"); + } + + @Test + void shouldPostAndGetArticles() { + Article article = new Article(1, "How to use RestClient"); + restClient.post() + .uri(uriBase + "/articles") + .contentType(MediaType.APPLICATION_JSON) + .body(article) + .retrieve() + .toBodilessEntity(); + + List
articles = restClient.get() + .uri(uriBase + "/articles") + .retrieve() + .body(new ParameterizedTypeReference<>() {}); + + assertThat(articles).isEqualTo(List.of(article)); + } + + @Test + void shouldPostAndPutAndGetArticles() { + Article article = new Article(1, "How to use RestClient"); + restClient.post() + .uri(uriBase + "/articles") + .contentType(MediaType.APPLICATION_JSON) + .body(article) + .retrieve() + .toBodilessEntity(); + + Article articleChanged = new Article(1, "How to use RestClient even better"); + restClient.put() + .uri(uriBase + "/articles/1") + .contentType(MediaType.APPLICATION_JSON) + .body(articleChanged) + .retrieve() + .toBodilessEntity(); + + List
articles = restClient.get() + .uri(uriBase + "/articles") + .retrieve() + .body(new ParameterizedTypeReference<>() {}); + + assertThat(articles).isEqualTo(List.of(articleChanged)); + } + + @Test + void shouldPostAndDeleteArticles() { + Article article = new Article(1, "How to use RestClient"); + restClient.post() + .uri(uriBase + "/articles") + .contentType(MediaType.APPLICATION_JSON) + .body(article) + .retrieve() + .toBodilessEntity(); + + restClient.delete() + .uri(uriBase + "/articles") + .retrieve() + .toBodilessEntity(); + + List
articles = restClient.get() + .uri(uriBase + "/articles") + .retrieve() + .body(new ParameterizedTypeReference<>() {}); + + assertThat(articles).isEqualTo(List.of()); + } +} From dc512cc40884797493388ae181956f80a0c40452 Mon Sep 17 00:00:00 2001 From: Alexandru Borza Date: Mon, 2 Oct 2023 16:09:22 +0300 Subject: [PATCH 143/193] BAEL-6971 Unnamed Classes and Instance Main Methods in Java 21 (#14841) * BAEL-6727 Streams vs. Loops in Java * BAEL-6971 - Unnamed Classes and Instance Main Methods in Java 21 * BAEL-6971 - decomment code * BAEL-6971 - add child class * BAEL-6971 - add unnamed class with method --- .../main/java/com/baeldung/unnamedclasses/HelloWorld.java | 3 +++ .../java/com/baeldung/unnamedclasses/HelloWorldChild.java | 7 +++++++ .../java/com/baeldung/unnamedclasses/HelloWorldSuper.java | 7 +++++++ .../com/baeldung/unnamedclasses/HelloWorldWithMethod.java | 6 ++++++ 4 files changed, 23 insertions(+) create mode 100644 core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorld.java create mode 100644 core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldChild.java create mode 100644 core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldSuper.java create mode 100644 core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldWithMethod.java diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorld.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorld.java new file mode 100644 index 0000000000..bf0e2c96c2 --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorld.java @@ -0,0 +1,3 @@ +void main() { + System.out.println("Hello, World!"); +} diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldChild.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldChild.java new file mode 100644 index 0000000000..827be7c788 --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldChild.java @@ -0,0 +1,7 @@ +package com.baeldung.unnamedclasses; + +public class HelloWorldChild extends HelloWorldSuper { + void main() { + System.out.println("Hello, World!"); + } +} diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldSuper.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldSuper.java new file mode 100644 index 0000000000..59c88716a4 --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldSuper.java @@ -0,0 +1,7 @@ +package com.baeldung.unnamedclasses; + +public class HelloWorldSuper { + public static void main(String[] args) { + System.out.println("Hello from the superclass"); + } +} diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldWithMethod.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldWithMethod.java new file mode 100644 index 0000000000..698516544e --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldWithMethod.java @@ -0,0 +1,6 @@ +private String getMessage() { + return "Hello, World!"; +} +void main() { + System.out.println(getMessage()); +} From 99437e5c52683d001cbc8e943a24180e42eaf441 Mon Sep 17 00:00:00 2001 From: Kasra Madadipouya Date: Mon, 2 Oct 2023 19:07:03 +0200 Subject: [PATCH 144/193] JAVA-25344 fix spring-data-cassandra-2 tests (#14799) --- .../ProductRepositoryNestedLiveTest.java | 2 +- .../baeldung/objectmapper/MapperLiveTest.java | 52 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/cassandra/inquery/ProductRepositoryNestedLiveTest.java b/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/cassandra/inquery/ProductRepositoryNestedLiveTest.java index 3d2433814e..3592c8b80d 100644 --- a/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/cassandra/inquery/ProductRepositoryNestedLiveTest.java +++ b/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/cassandra/inquery/ProductRepositoryNestedLiveTest.java @@ -23,7 +23,7 @@ import static org.junit.jupiter.api.Assertions.*; @Testcontainers @SpringBootTest -class ProductRepositoryIntegrationTest { +class ProductRepositoryNestedLiveTest { private static final String KEYSPACE_NAME = "mynamespace"; diff --git a/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/objectmapper/MapperLiveTest.java b/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/objectmapper/MapperLiveTest.java index b61663d622..50681d36c5 100644 --- a/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/objectmapper/MapperLiveTest.java +++ b/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/objectmapper/MapperLiveTest.java @@ -1,7 +1,8 @@ package org.baeldung.objectmapper; -import com.datastax.oss.driver.api.core.CqlIdentifier; -import com.datastax.oss.driver.api.core.CqlSession; +import java.net.InetSocketAddress; +import java.util.List; + import org.baeldung.objectmapper.dao.CounterDao; import org.baeldung.objectmapper.dao.UserDao; import org.baeldung.objectmapper.entity.Counter; @@ -14,7 +15,8 @@ import org.testcontainers.containers.CassandraContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import java.util.List; +import com.datastax.oss.driver.api.core.CqlIdentifier; +import com.datastax.oss.driver.api.core.CqlSession; @Testcontainers @SpringBootTest @@ -23,35 +25,30 @@ public class MapperLiveTest { private static final String KEYSPACE_NAME = "baeldung"; @Container - private static final CassandraContainer cassandra = (CassandraContainer) new CassandraContainer("cassandra:3.11.2") - .withExposedPorts(9042); + private static final CassandraContainer cassandra = (CassandraContainer) new CassandraContainer("cassandra:3.11.2").withExposedPorts(9042); + @BeforeAll static void setupCassandraConnectionProperties() { System.setProperty("spring.data.cassandra.keyspace-name", KEYSPACE_NAME); - System.setProperty("spring.data.cassandra.contact-points", cassandra.getContainerIpAddress()); + System.setProperty("spring.data.cassandra.contact-points", cassandra.getHost()); System.setProperty("spring.data.cassandra.port", String.valueOf(cassandra.getMappedPort(9042))); + setupCassandra(new InetSocketAddress(cassandra.getHost(), cassandra.getMappedPort(9042)), cassandra.getLocalDatacenter()); } static UserDao userDao; static CounterDao counterDao; - @BeforeAll - static void setup() { - setupCassandraConnectionProperties(); - CqlSession session = CqlSession.builder().build(); + static void setupCassandra(InetSocketAddress cassandraEndpoint, String localDataCenter) { + CqlSession session = CqlSession.builder() + .withLocalDatacenter(localDataCenter) + .addContactPoint(cassandraEndpoint) + .build(); - String createKeyspace = "CREATE KEYSPACE IF NOT EXISTS baeldung " + - "WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};"; + String createKeyspace = "CREATE KEYSPACE IF NOT EXISTS baeldung " + "WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};"; String useKeyspace = "USE baeldung;"; - String createUserTable = "CREATE TABLE IF NOT EXISTS user_profile " + - "(id int, username text, user_age int, writetime bigint, PRIMARY KEY (id, user_age)) " + - "WITH CLUSTERING ORDER BY (user_age DESC);"; - String createAdminTable = "CREATE TABLE IF NOT EXISTS admin_profile " + - "(id int, username text, user_age int, role text, writetime bigint, department text, " + - "PRIMARY KEY (id, user_age)) " + - "WITH CLUSTERING ORDER BY (user_age DESC);"; - String createCounter = "CREATE TABLE IF NOT EXISTS counter " + - "(id text, count counter, PRIMARY KEY (id));"; + String createUserTable = "CREATE TABLE IF NOT EXISTS user_profile " + "(id int, username text, user_age int, writetime bigint, PRIMARY KEY (id, user_age)) " + "WITH CLUSTERING ORDER BY (user_age DESC);"; + String createAdminTable = "CREATE TABLE IF NOT EXISTS admin_profile " + "(id int, username text, user_age int, role text, writetime bigint, department text, " + "PRIMARY KEY (id, user_age)) " + "WITH CLUSTERING ORDER BY (user_age DESC);"; + String createCounter = "CREATE TABLE IF NOT EXISTS counter " + "(id text, count counter, PRIMARY KEY (id));"; session.execute(createKeyspace); session.execute(useKeyspace); @@ -75,22 +72,25 @@ public class MapperLiveTest { @Test void givenCounter_whenIncrement_thenIncremented() { Counter users = counterDao.getCounterById("users"); - long initialCount = users != null ? users.getCount(): 0; + long initialCount = users != null ? users.getCount() : 0; counterDao.incrementCounter("users", 1); users = counterDao.getCounterById("users"); - long finalCount = users != null ? users.getCount(): 0; + long finalCount = users != null ? users.getCount() : 0; Assertions.assertEquals(finalCount - initialCount, 1); } @Test void givenUser_whenGetUsersOlderThan_thenRetrieved() { - User user = new User(2, "JaneDoe", 20); + User user = new User(2, "JaneDoe", 32); + User userTwo = new User(3, "JohnDoe", 20); userDao.insertUser(user); - List retrievedUsers = userDao.getUsersOlderThanAge(30).all(); - Assertions.assertEquals(retrievedUsers.size(), 1); + userDao.insertUser(userTwo); + List retrievedUsers = userDao.getUsersOlderThanAge(30) + .all(); + Assertions.assertEquals(1, retrievedUsers.size()); } } \ No newline at end of file From 40c5ed0c6f6ff9e8f0588a6b31e2e9239a0b612c Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Mon, 2 Oct 2023 23:07:36 +0530 Subject: [PATCH 145/193] JAVA-24378 Fix references to parents - Week 35 - 2023 (#14852) --- jenkins-modules/plugins/pom.xml | 1 + spring-boot-modules/spring-boot-keycloak-2/pom.xml | 7 +++---- spring-boot-modules/spring-boot-keycloak-adapters/pom.xml | 7 +++---- spring-boot-modules/spring-boot-keycloak/pom.xml | 7 +++---- spring-boot-modules/spring-boot-logging-log4j2/pom.xml | 7 +++---- spring-boot-modules/spring-boot-mvc-birt/pom.xml | 7 +++---- spring-boot-modules/spring-boot-ssl-bundles/pom.xml | 8 ++++---- ...BundleApplicationTests.java => SpringContextTest.java} | 2 +- 8 files changed, 21 insertions(+), 25 deletions(-) rename spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/{SSLBundleApplicationTests.java => SpringContextTest.java} (85%) diff --git a/jenkins-modules/plugins/pom.xml b/jenkins-modules/plugins/pom.xml index 42add1664e..c2b1408556 100644 --- a/jenkins-modules/plugins/pom.xml +++ b/jenkins-modules/plugins/pom.xml @@ -12,6 +12,7 @@ org.jenkins-ci.plugins plugin 2.33 + diff --git a/spring-boot-modules/spring-boot-keycloak-2/pom.xml b/spring-boot-modules/spring-boot-keycloak-2/pom.xml index 39a7283328..7909e2e153 100644 --- a/spring-boot-modules/spring-boot-keycloak-2/pom.xml +++ b/spring-boot-modules/spring-boot-keycloak-2/pom.xml @@ -11,10 +11,9 @@ This is a simple application demonstrating integration between Keycloak and Spring Boot. - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT diff --git a/spring-boot-modules/spring-boot-keycloak-adapters/pom.xml b/spring-boot-modules/spring-boot-keycloak-adapters/pom.xml index 035c226b6d..34c0653fbd 100644 --- a/spring-boot-modules/spring-boot-keycloak-adapters/pom.xml +++ b/spring-boot-modules/spring-boot-keycloak-adapters/pom.xml @@ -11,10 +11,9 @@ This is a simple application demonstrating integration between Keycloak and Spring Boot. - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT diff --git a/spring-boot-modules/spring-boot-keycloak/pom.xml b/spring-boot-modules/spring-boot-keycloak/pom.xml index 64fb39d085..bada9ab52d 100644 --- a/spring-boot-modules/spring-boot-keycloak/pom.xml +++ b/spring-boot-modules/spring-boot-keycloak/pom.xml @@ -11,10 +11,9 @@ This is a simple application demonstrating integration between Keycloak and Spring Boot. - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT diff --git a/spring-boot-modules/spring-boot-logging-log4j2/pom.xml b/spring-boot-modules/spring-boot-logging-log4j2/pom.xml index b429339417..31c0f4bd02 100644 --- a/spring-boot-modules/spring-boot-logging-log4j2/pom.xml +++ b/spring-boot-modules/spring-boot-logging-log4j2/pom.xml @@ -9,10 +9,9 @@ Demo project for Spring Boot Logging with Log4J2 - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT diff --git a/spring-boot-modules/spring-boot-mvc-birt/pom.xml b/spring-boot-modules/spring-boot-mvc-birt/pom.xml index 274932f06c..cc4b7f8283 100644 --- a/spring-boot-modules/spring-boot-mvc-birt/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-birt/pom.xml @@ -10,10 +10,9 @@ Module For Spring Boot Integration with BIRT - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT diff --git a/spring-boot-modules/spring-boot-ssl-bundles/pom.xml b/spring-boot-modules/spring-boot-ssl-bundles/pom.xml index 056d0308c2..4802e9ec58 100644 --- a/spring-boot-modules/spring-boot-ssl-bundles/pom.xml +++ b/spring-boot-modules/spring-boot-ssl-bundles/pom.xml @@ -4,10 +4,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 3.1.3 - + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 springbootsslbundles spring-boot-ssl-bundles diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SSLBundleApplicationTests.java b/spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SpringContextTest.java similarity index 85% rename from spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SSLBundleApplicationTests.java rename to spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SpringContextTest.java index 876641c8b5..6c9a2fb3f0 100644 --- a/spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SSLBundleApplicationTests.java +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SpringContextTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest -class SSLBundleApplicationTests { +class SpringContextTest { @Test void contextLoads() { From b52e2cc3d1ac74468b8c808b63c0223a45a7f048 Mon Sep 17 00:00:00 2001 From: Somnath Musib <7885767+musibs@users.noreply.github.com> Date: Tue, 3 Oct 2023 01:07:18 +0300 Subject: [PATCH 146/193] BAEL-6527 GraalVM Native Image Docker Image (#14835) * BAEL-6527 GraalVM Native Image Docker Image * BAEL-6527 GraalVM Native Image Docker Image --- spring-boot-modules/pom.xml | 1 + .../spring-boot-graalvm-docker/Dockerfile | 3 ++ .../spring-boot-graalvm-docker/pom.xml | 41 +++++++++++++++++++ .../GraalvmDockerImageApplication.java | 24 +++++++++++ .../src/main/resources/application.properties | 1 + 5 files changed, 70 insertions(+) create mode 100644 spring-boot-modules/spring-boot-graalvm-docker/Dockerfile create mode 100644 spring-boot-modules/spring-boot-graalvm-docker/pom.xml create mode 100644 spring-boot-modules/spring-boot-graalvm-docker/src/main/java/com/baeldung/graalvmdockerimage/GraalvmDockerImageApplication.java create mode 100644 spring-boot-modules/spring-boot-graalvm-docker/src/main/resources/application.properties diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 1c4b2bb38f..2b4a94a7a5 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -104,6 +104,7 @@ spring-boot-springdoc-2 spring-boot-documentation spring-boot-3-url-matching + spring-boot-graalvm-docker diff --git a/spring-boot-modules/spring-boot-graalvm-docker/Dockerfile b/spring-boot-modules/spring-boot-graalvm-docker/Dockerfile new file mode 100644 index 0000000000..91a63074c1 --- /dev/null +++ b/spring-boot-modules/spring-boot-graalvm-docker/Dockerfile @@ -0,0 +1,3 @@ +FROM ubuntu:jammy +COPY target/springboot-graalvm-docker /springboot-graalvm-docker +CMD ["/springboot-graalvm-docker"] diff --git a/spring-boot-modules/spring-boot-graalvm-docker/pom.xml b/spring-boot-modules/spring-boot-graalvm-docker/pom.xml new file mode 100644 index 0000000000..a3a1b148c2 --- /dev/null +++ b/spring-boot-modules/spring-boot-graalvm-docker/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 + + + com.baeldung + spring-boot-graalvm-docker + 1.0.0 + spring-boot-graalvm-docker + Spring Boot GrralVM with Docker + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + org.graalvm.buildtools + native-maven-plugin + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/spring-boot-modules/spring-boot-graalvm-docker/src/main/java/com/baeldung/graalvmdockerimage/GraalvmDockerImageApplication.java b/spring-boot-modules/spring-boot-graalvm-docker/src/main/java/com/baeldung/graalvmdockerimage/GraalvmDockerImageApplication.java new file mode 100644 index 0000000000..53e11aa749 --- /dev/null +++ b/spring-boot-modules/spring-boot-graalvm-docker/src/main/java/com/baeldung/graalvmdockerimage/GraalvmDockerImageApplication.java @@ -0,0 +1,24 @@ +package com.baeldung.graalvmdockerimage; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +public class GraalvmDockerImageApplication { + + public static void main(String[] args) { + SpringApplication.run(GraalvmDockerImageApplication.class, args); + } + +} + +@RestController +class HelloController { + + @GetMapping + public String hello() { + return "Hello GraalVM"; + } +} diff --git a/spring-boot-modules/spring-boot-graalvm-docker/src/main/resources/application.properties b/spring-boot-modules/spring-boot-graalvm-docker/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/spring-boot-modules/spring-boot-graalvm-docker/src/main/resources/application.properties @@ -0,0 +1 @@ + From e331611860dda4255686b440b8afb3cb0a93ce85 Mon Sep 17 00:00:00 2001 From: timis1 <12120641+timis1@users.noreply.github.com> Date: Tue, 3 Oct 2023 07:17:04 +0300 Subject: [PATCH 147/193] JAVA-24463 Fixing Failed tests from spring-5-reactive (#14881) Co-authored-by: timis1 --- .../baeldung/reactive/controller/PathPatternController.java | 4 ++-- .../ExploreSpring5URLPatternUsingRouterFunctions.java | 2 +- ...eSpring5URLPatternUsingRouterFunctionsIntegrationTest.java | 4 ++-- .../PathPatternsUsingHandlerMethodIntegrationTest.java | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/PathPatternController.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/PathPatternController.java index 653c95d566..3c9cb812f2 100644 --- a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/PathPatternController.java +++ b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/PathPatternController.java @@ -22,9 +22,9 @@ public class PathPatternController { return "/spring5/*id"; } - @GetMapping("//**") + @GetMapping("/resources/**") public String wildcardTakingZeroOrMorePathSegments() { - return "//**"; + return "/resources/**"; } @GetMapping("/{baeldung:[a-z]+}") diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java index 60cf85e5da..b7bb53600e 100644 --- a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java +++ b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctions.java @@ -29,7 +29,7 @@ public class ExploreSpring5URLPatternUsingRouterFunctions { .andRoute(GET("/{var1}_{var2}"), serverRequest -> ok().body(fromValue(serverRequest.pathVariable("var1") + " , " + serverRequest.pathVariable("var2")))) .andRoute(GET("/{baeldung:[a-z]+}"), serverRequest -> ok().body(fromValue("/{baeldung:[a-z]+} was accessed and baeldung=" + serverRequest.pathVariable("baeldung")))) .and(RouterFunctions.resources("/files/{*filepaths}", new ClassPathResource("files/"))) - .and(RouterFunctions.resources("//**", new ClassPathResource("/"))); + .and(RouterFunctions.resources("/resources/**", new ClassPathResource("resources/"))); } WebServer start() throws Exception { diff --git a/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java b/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java index 63dfbd44a1..113376318e 100644 --- a/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java +++ b/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java @@ -108,9 +108,9 @@ public class ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest { } @Test - public void givenRouter_whenAccess_thenGot() throws Exception { + public void givenRouter_whenAccess_thenGot() { client.get() - .uri("//test/test.txt") + .uri("/resources/test/test.txt") .exchange() .expectStatus() .isOk() diff --git a/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java b/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java index 8eb8d04cd4..0b4607b54a 100644 --- a/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java +++ b/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/PathPatternsUsingHandlerMethodIntegrationTest.java @@ -72,12 +72,12 @@ public class PathPatternsUsingHandlerMethodIntegrationTest { public void givenHandlerMethod_whenURLWithWildcardTakingZeroOrMorePathSegments_then200() { client.get() - .uri("//baeldung") + .uri("/resources/baeldung") .exchange() .expectStatus() .is2xxSuccessful() .expectBody() - .equals("//**"); + .equals("/resources/**"); } @Test From ca1590cc663ce1c164ee6f66efd06a9438d56ec1 Mon Sep 17 00:00:00 2001 From: timis1 <12120641+timis1@users.noreply.github.com> Date: Tue, 3 Oct 2023 07:25:06 +0300 Subject: [PATCH 148/193] JAVA-25542 Check code of spring-reactive ebook (#14880) Co-authored-by: timis1 --- spring-reactive-modules/spring-reactive-exceptions/README.md | 3 +-- spring-reactive-modules/spring-reactive/README.md | 1 + spring-reactive-modules/spring-reactive/pom.xml | 2 +- .../reactive/errorhandling/ErrorHandlingApplication.java | 2 +- .../reactive/errorhandling/GlobalErrorAttributes.java | 2 +- .../reactive/errorhandling/GlobalErrorWebExceptionHandler.java | 2 +- .../java/com/baeldung}/reactive/errorhandling/Handler.java | 2 +- .../reactive/errorhandling/NameRequiredException.java | 2 +- .../main/java/com/baeldung}/reactive/errorhandling/Router.java | 2 +- .../reactive/errorhandling/ErrorHandlingIntegrationTest.java | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) rename spring-reactive-modules/{spring-reactive-exceptions/src/main/java/com/baeldung/spring => spring-reactive/src/main/java/com/baeldung}/reactive/errorhandling/ErrorHandlingApplication.java (93%) rename spring-reactive-modules/{spring-reactive-exceptions/src/main/java/com/baeldung/spring => spring-reactive/src/main/java/com/baeldung}/reactive/errorhandling/GlobalErrorAttributes.java (93%) rename spring-reactive-modules/{spring-reactive-exceptions/src/main/java/com/baeldung/spring => spring-reactive/src/main/java/com/baeldung}/reactive/errorhandling/GlobalErrorWebExceptionHandler.java (97%) rename spring-reactive-modules/{spring-reactive-exceptions/src/main/java/com/baeldung/spring => spring-reactive/src/main/java/com/baeldung}/reactive/errorhandling/Handler.java (97%) rename spring-reactive-modules/{spring-reactive-exceptions/src/main/java/com/baeldung/spring => spring-reactive/src/main/java/com/baeldung}/reactive/errorhandling/NameRequiredException.java (85%) rename spring-reactive-modules/{spring-reactive-exceptions/src/main/java/com/baeldung/spring => spring-reactive/src/main/java/com/baeldung}/reactive/errorhandling/Router.java (96%) rename spring-reactive-modules/{spring-reactive-exceptions/src/test/java/com/baeldung/spring => spring-reactive/src/test/java/com/baeldung}/reactive/errorhandling/ErrorHandlingIntegrationTest.java (98%) diff --git a/spring-reactive-modules/spring-reactive-exceptions/README.md b/spring-reactive-modules/spring-reactive-exceptions/README.md index f7e2c8cae0..f10774d188 100644 --- a/spring-reactive-modules/spring-reactive-exceptions/README.md +++ b/spring-reactive-modules/spring-reactive-exceptions/README.md @@ -1,4 +1,3 @@ ## Relevant Articles - [How to Resolve Spring Webflux DataBufferLimitException](https://www.baeldung.com/spring-webflux-databufferlimitexception) -- [Custom WebFlux Exceptions in Spring Boot 3](https://www.baeldung.com/spring-boot-custom-webflux-exceptions) -- [Handling Errors in Spring WebFlux](https://www.baeldung.com/spring-webflux-errors) \ No newline at end of file +- [Custom WebFlux Exceptions in Spring Boot 3](https://www.baeldung.com/spring-boot-custom-webflux-exceptions) \ No newline at end of file diff --git a/spring-reactive-modules/spring-reactive/README.md b/spring-reactive-modules/spring-reactive/README.md index 5e52212061..2b707a5d4e 100644 --- a/spring-reactive-modules/spring-reactive/README.md +++ b/spring-reactive-modules/spring-reactive/README.md @@ -14,6 +14,7 @@ This module contains articles describing reactive processing in Spring. - [Spring 5 WebClient](https://www.baeldung.com/spring-5-webclient) - [Spring WebClient vs. RestTemplate](https://www.baeldung.com/spring-webclient-resttemplate) - [Spring WebClient Requests with Parameters](https://www.baeldung.com/webflux-webclient-parameters) +- [Handling Errors in Spring WebFlux](https://www.baeldung.com/spring-webflux-errors) - [Spring Security 5 for Reactive Applications](https://www.baeldung.com/spring-security-5-reactive) - [Concurrency in Spring WebFlux](https://www.baeldung.com/spring-webflux-concurrency) diff --git a/spring-reactive-modules/spring-reactive/pom.xml b/spring-reactive-modules/spring-reactive/pom.xml index 263f29f9b5..f19809e302 100644 --- a/spring-reactive-modules/spring-reactive/pom.xml +++ b/spring-reactive-modules/spring-reactive/pom.xml @@ -9,7 +9,7 @@ com.baeldung parent-boot-3 0.0.1-SNAPSHOT - ../../parent-boot-3/pom.xml + ../../parent-boot-3 diff --git a/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/ErrorHandlingApplication.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/ErrorHandlingApplication.java similarity index 93% rename from spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/ErrorHandlingApplication.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/ErrorHandlingApplication.java index c34f86febd..50579d8721 100644 --- a/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/ErrorHandlingApplication.java +++ b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/ErrorHandlingApplication.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.reactive.errorhandling; +package com.baeldung.reactive.errorhandling; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/GlobalErrorAttributes.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorAttributes.java similarity index 93% rename from spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/GlobalErrorAttributes.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorAttributes.java index 9dce1b3e5b..549ae749f2 100644 --- a/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/GlobalErrorAttributes.java +++ b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorAttributes.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.reactive.errorhandling; +package com.baeldung.reactive.errorhandling; import java.util.Map; diff --git a/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/GlobalErrorWebExceptionHandler.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java similarity index 97% rename from spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/GlobalErrorWebExceptionHandler.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java index bfd3bba2a1..69f9a0420e 100644 --- a/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/GlobalErrorWebExceptionHandler.java +++ b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.reactive.errorhandling; +package com.baeldung.reactive.errorhandling; import java.util.Map; diff --git a/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/Handler.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Handler.java similarity index 97% rename from spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/Handler.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Handler.java index 2956cc1686..f9e4ee4c35 100644 --- a/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/Handler.java +++ b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Handler.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.reactive.errorhandling; +package com.baeldung.reactive.errorhandling; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; diff --git a/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/NameRequiredException.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/NameRequiredException.java similarity index 85% rename from spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/NameRequiredException.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/NameRequiredException.java index 1926d6416a..bdc7771b80 100644 --- a/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/NameRequiredException.java +++ b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/NameRequiredException.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.reactive.errorhandling; +package com.baeldung.reactive.errorhandling; import org.springframework.http.HttpStatus; import org.springframework.web.server.ResponseStatusException; diff --git a/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/Router.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Router.java similarity index 96% rename from spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/Router.java rename to spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Router.java index c65b645f09..aeea202c31 100644 --- a/spring-reactive-modules/spring-reactive-exceptions/src/main/java/com/baeldung/spring/reactive/errorhandling/Router.java +++ b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Router.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.reactive.errorhandling; +package com.baeldung.reactive.errorhandling; import static org.springframework.http.MediaType.TEXT_PLAIN; import static org.springframework.web.reactive.function.server.RequestPredicates.GET; diff --git a/spring-reactive-modules/spring-reactive-exceptions/src/test/java/com/baeldung/spring/reactive/errorhandling/ErrorHandlingIntegrationTest.java b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/errorhandling/ErrorHandlingIntegrationTest.java similarity index 98% rename from spring-reactive-modules/spring-reactive-exceptions/src/test/java/com/baeldung/spring/reactive/errorhandling/ErrorHandlingIntegrationTest.java rename to spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/errorhandling/ErrorHandlingIntegrationTest.java index 972eefa5ac..0068379d61 100644 --- a/spring-reactive-modules/spring-reactive-exceptions/src/test/java/com/baeldung/spring/reactive/errorhandling/ErrorHandlingIntegrationTest.java +++ b/spring-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/errorhandling/ErrorHandlingIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.reactive.errorhandling; +package com.baeldung.reactive.errorhandling; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; From 7e8f6ef9c4ad6c0295c2a5c2f8a856c01b7adf4e Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Tue, 3 Oct 2023 09:56:28 +0530 Subject: [PATCH 149/193] Update README.md (#14894) --- spring-reactive-modules/spring-reactive/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-reactive-modules/spring-reactive/README.md b/spring-reactive-modules/spring-reactive/README.md index 2b707a5d4e..61d781b312 100644 --- a/spring-reactive-modules/spring-reactive/README.md +++ b/spring-reactive-modules/spring-reactive/README.md @@ -1,5 +1,5 @@ -This module contains articles about Spring Reactive that are also part of an Ebook. +This module contains articles about Spring Reactive that **are also part of an Ebook.** ## Spring Reactive @@ -20,4 +20,4 @@ This module contains articles describing reactive processing in Spring. ### NOTE: -Since this is a module tied to an e-book, it should **not** be moved or used to store the code for any further article. \ No newline at end of file +## Since this is a module tied to an e-book, it should **not** be moved or used to store the code for any further article. From 6f085f068a1874b555f971b2109ff88ad78c07e6 Mon Sep 17 00:00:00 2001 From: mcasari Date: Tue, 3 Oct 2023 18:34:40 +0200 Subject: [PATCH 150/193] BAEL-6846 - minor code format fix --- .../floattobigdecimal/FloatToBigDecimalUnitTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java index 8895c01575..fe5dc360e4 100644 --- a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java +++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java @@ -44,10 +44,8 @@ class FloatToBigDecimalUnitTest { @Test public void whenCreatedByValueOf_thenFloatValueGetsTruncated() { - assertEquals("1.100000023841858", BigDecimal.valueOf(1.1f) - .toString()); - assertEquals("1.100000023841858", BigDecimal.valueOf(1.10000002384185791015625f) - .toString()); + assertEquals("1.100000023841858", BigDecimal.valueOf(1.1f).toString()); + assertEquals("1.100000023841858", BigDecimal.valueOf(1.10000002384185791015625f).toString()); } @Test From 3ecaaaec2827f2b06473d578ae8415faf228d029 Mon Sep 17 00:00:00 2001 From: Thiago dos Santos Hora Date: Tue, 3 Oct 2023 22:33:24 +0200 Subject: [PATCH 151/193] Bael 6917/api versioning micronaut (#14868) * BAEL-6917: Micronaut API Versioning * Fix test names --- microservices-modules/micronaut/pom.xml | 163 ++++++++++-------- .../custom/client/BirdCountClient.java | 42 +++++ .../custom/server/BirdCountController.java | 36 ++++ .../custom/server/CustomVersionResolver.java | 31 ++++ .../header/client/DogCountClient.java | 42 +++++ .../header/server/DogCountController.java | 36 ++++ .../param/client/CatCountClient.java | 23 +++ .../param/server/CatCountController.java | 37 ++++ .../url/client/SheepCountClient.java | 39 +++++ .../url/server/SheepCountControllerV1.java | 26 +++ .../url/server/SheepCountControllerV2.java | 27 +++ .../client/ConcreteGreetingClient.java | 15 +- .../controller/AsyncGreetController.java | 4 +- .../server/controller/GreetController.java | 2 +- .../service/EnglishGreetingService.java | 2 +- .../service/SpanishGreetingService.java | 2 +- .../vs/springboot/CompareApplication.java | 6 +- .../client/ArithmeticClientImpl.java | 30 ++-- .../controller/ArithmeticController.java | 2 +- .../springboot/service/ArithmeticService.java | 2 +- .../src/main/resources/application.yml | 22 ++- .../micronaut/src/main/resources/logback.xml | 6 + .../client/BirdCountClientUnitTest.java | 42 +++++ .../header/client/DogCountClientUnitTest.java | 40 +++++ .../param/client/CatCountClientUnitTest.java | 38 ++++ .../url/client/SheepCountClientUnitTest.java | 44 +++++ .../ConcreteGreetingClientUnitTest.java | 32 ++-- .../client/GreetingClientUnitTest.java | 31 ++-- .../springboot/ArithmeticClientUnitTest.java | 37 ++-- 29 files changed, 683 insertions(+), 176 deletions(-) create mode 100644 microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/custom/client/BirdCountClient.java create mode 100644 microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/custom/server/BirdCountController.java create mode 100644 microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/custom/server/CustomVersionResolver.java create mode 100644 microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/header/client/DogCountClient.java create mode 100644 microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/header/server/DogCountController.java create mode 100644 microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/param/client/CatCountClient.java create mode 100644 microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/param/server/CatCountController.java create mode 100644 microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/url/client/SheepCountClient.java create mode 100644 microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/url/server/SheepCountControllerV1.java create mode 100644 microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/url/server/SheepCountControllerV2.java create mode 100644 microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/custom/client/BirdCountClientUnitTest.java create mode 100644 microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/header/client/DogCountClientUnitTest.java create mode 100644 microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/param/client/CatCountClientUnitTest.java create mode 100644 microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/url/client/SheepCountClientUnitTest.java diff --git a/microservices-modules/micronaut/pom.xml b/microservices-modules/micronaut/pom.xml index 716b5497d8..d3f4326a85 100644 --- a/microservices-modules/micronaut/pom.xml +++ b/microservices-modules/micronaut/pom.xml @@ -7,6 +7,7 @@ micronaut 0.1 micronaut + ${packaging} com.baeldung @@ -18,7 +19,7 @@ io.micronaut - bom + micronaut-bom ${micronaut.version} pom import @@ -29,120 +30,136 @@ io.micronaut - http-client + micronaut-runtime + compile + + + io.micronaut + micronaut-jackson-databind + + + + + io.micronaut + micronaut-http-client compile io.micronaut - http-server-netty + micronaut-http-server-netty + compile + + + jakarta.annotation + jakarta.annotation-api compile io.micronaut - inject + micronaut-inject compile io.micronaut - runtime + micronaut-validation compile - - javax.annotation - javax.annotation-api - ${annotation.api.version} - compile - - - io.micronaut - inject-java - provided - ch.qos.logback logback-classic - ${logback.version} runtime - io.projectreactor - reactor-core - ${reactor.version} + io.micronaut.rxjava3 + micronaut-rxjava3 + compile + + + io.micronaut.rxjava3 + micronaut-rxjava3-http-client + compile + + + io.micronaut.serde + micronaut-serde-jackson + compile + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.assertj + assertj-core + test + + + io.micronaut.test + micronaut-test-junit5 + test + + io.micronaut.build + micronaut-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + ${jdk.version} + ${jdk.version} + + -parameters + + + + + + + + io.micronaut + micronaut-inject-java + ${micronaut.version} + + + + io.micronaut + micronaut-http-validation + ${micronaut.version} + + + + + org.apache.maven.plugins maven-shade-plugin ${shade.plugin.version} - package - - shade - - - - - ${exec.mainClass} - - - - + default-shade + none - - org.codehaus.mojo - exec-maven-plugin - - java - - -classpath - - ${exec.mainClass} - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${compiler.plugin.version} - - ${jdk.version} - ${jdk.version} - - -parameters - - - - io.micronaut - inject-java - ${micronaut.version} - - - - - - com.baeldung.micronaut.vs.springboot.CompareApplication - 1.0.0.RC2 + 3.10.1 17 - 1.3.2 - 3.1.6.RELEASE + 17 + jar 3.7.0 - 3.1.0 + netty + 3.2.0 \ No newline at end of file diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/custom/client/BirdCountClient.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/custom/client/BirdCountClient.java new file mode 100644 index 0000000000..d9e09b1c6e --- /dev/null +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/custom/client/BirdCountClient.java @@ -0,0 +1,42 @@ +package com.baeldung.micronaut.apiversioning.custom.client; + +import io.micronaut.core.annotation.Nullable; +import io.micronaut.core.async.annotation.SingleResult; +import io.micronaut.http.HttpHeaders; +import io.micronaut.http.annotation.Get; +import io.micronaut.http.annotation.Header; +import io.micronaut.http.annotation.QueryValue; +import io.micronaut.http.client.annotation.Client; +import io.reactivex.rxjava3.core.Flowable; + +@Client("/") +@Header(name = HttpHeaders.ACCEPT, value = "application/json") +public interface BirdCountClient { + + @Get( + uri = "/bird/count", + consumes = {"application/json"}, + produces = {"application/json"} + ) + @Header(name = "api-key", value = "11") + @SingleResult + Flowable countV1(@QueryValue("max") @Nullable Integer max); + + @Get( + uri = "/bird/count", + consumes = {"application/json"}, + produces = {"application/json"} + ) + @Header(name = "api-key", value = "10") + @SingleResult + Flowable countV2(@QueryValue("max") @Nullable Integer max); + + @Get( + uri = "/bird/count", + consumes = {"application/json"}, + produces = {"application/json"} + ) + @Header(name = "api-key", value = "") + @SingleResult + Flowable countDefault(@QueryValue("max") @Nullable Integer max); +} diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/custom/server/BirdCountController.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/custom/server/BirdCountController.java new file mode 100644 index 0000000000..c836761266 --- /dev/null +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/custom/server/BirdCountController.java @@ -0,0 +1,36 @@ +package com.baeldung.micronaut.apiversioning.custom.server; + +import io.micronaut.core.annotation.NonNull; +import io.micronaut.core.annotation.Nullable; +import io.micronaut.core.version.annotation.Version; +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Get; +import io.micronaut.http.annotation.QueryValue; +import io.reactivex.rxjava3.core.Flowable; + +import java.util.stream.Stream; + +@Controller("/bird") +public class BirdCountController { + + @Get(value = "/count", produces = {"application/json"}) + @Version("1") + public Flowable countV1(@QueryValue("max") @Nullable Integer max) { + return Flowable.fromStream( + Stream.iterate(0, i -> i + 1) + .map(index -> "Bird " + index) + .limit(max == null ? 10 : max) + ); + } + + @Get(value = "/count", produces = {"application/json"}) + @Version("2") + public Flowable countV2(@QueryValue("max") @NonNull Integer max) { + return Flowable.fromStream( + Stream.iterate(0, i -> i + 1) + .map(index -> "Bird " + index) + .limit(max) + ); + } + +} diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/custom/server/CustomVersionResolver.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/custom/server/CustomVersionResolver.java new file mode 100644 index 0000000000..3075a135c8 --- /dev/null +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/custom/server/CustomVersionResolver.java @@ -0,0 +1,31 @@ +package com.baeldung.micronaut.apiversioning.custom.server; + +import io.micronaut.context.annotation.Requires; +import io.micronaut.context.annotation.Value; +import io.micronaut.http.HttpRequest; +import io.micronaut.web.router.version.resolution.RequestVersionResolver; +import jakarta.inject.Inject; +import jakarta.inject.Singleton; + +import java.util.Optional; + +@Singleton +@Requires(property = "my.router.versioning.enabled", value = "true") +public class CustomVersionResolver implements RequestVersionResolver { + + @Inject + @Value("${micronaut.router.versioning.default-version}") + private String defaultVersion; + + @Override + public Optional resolve(HttpRequest request) { + var apiKey = Optional.ofNullable(request.getHeaders().get("api-key")); + + if (apiKey.isPresent() && !apiKey.get().isEmpty()) { + return Optional.of(Integer.parseInt(apiKey.get()) % 2 == 0 ? "2" : "1"); + } + + return Optional.of(defaultVersion); + } + +} diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/header/client/DogCountClient.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/header/client/DogCountClient.java new file mode 100644 index 0000000000..487bff4d57 --- /dev/null +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/header/client/DogCountClient.java @@ -0,0 +1,42 @@ +package com.baeldung.micronaut.apiversioning.header.client; + +import io.micronaut.core.annotation.Nullable; +import io.micronaut.core.async.annotation.SingleResult; +import io.micronaut.core.version.annotation.Version; +import io.micronaut.http.HttpHeaders; +import io.micronaut.http.annotation.Get; +import io.micronaut.http.annotation.Header; +import io.micronaut.http.annotation.QueryValue; +import io.micronaut.http.client.annotation.Client; +import io.reactivex.rxjava3.core.Flowable; + +@Client("/") +@Header(name = HttpHeaders.ACCEPT, value = "application/json") +public interface DogCountClient { + + @Get( + uri = "/dog/count", + consumes = {"application/json"}, + produces = {"application/json"} + ) + @Version("1") + @SingleResult + Flowable countV1(@QueryValue("max") @Nullable Integer max); + + @Get( + uri = "/dog/count", + consumes = {"application/json"}, + produces = {"application/json"} + ) + @Version("2") + @SingleResult + Flowable countV2(@QueryValue("max") @Nullable Integer max); + + @Get( + uri = "/dog/count", + consumes = {"application/json"}, + produces = {"application/json"} + ) + @SingleResult + Flowable countDefault(@QueryValue("max") @Nullable Integer max); +} diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/header/server/DogCountController.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/header/server/DogCountController.java new file mode 100644 index 0000000000..de0f6788cf --- /dev/null +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/header/server/DogCountController.java @@ -0,0 +1,36 @@ +package com.baeldung.micronaut.apiversioning.header.server; + +import io.micronaut.core.annotation.NonNull; +import io.micronaut.core.annotation.Nullable; +import io.micronaut.core.version.annotation.Version; +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Get; +import io.micronaut.http.annotation.QueryValue; +import io.reactivex.rxjava3.core.Flowable; + +import java.util.stream.Stream; + +@Controller("/dog") +public class DogCountController { + + @Get(value = "/count", produces = {"application/json"}) + @Version("1") + public Flowable countV1(@QueryValue("max") @Nullable Integer max) { + return Flowable.fromStream( + Stream.iterate(0, i -> i + 1) + .map(index -> "Dog " + index) + .limit(max == null ? 10 : max) + ); + } + + @Get(value = "/count", produces = {"application/json"}) + @Version("2") + public Flowable countV2(@QueryValue("max") @NonNull Integer max) { + return Flowable.fromStream( + Stream.iterate(0, i -> i + 1) + .map(index -> "Dog " + index) + .limit(max) + ); + } + +} diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/param/client/CatCountClient.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/param/client/CatCountClient.java new file mode 100644 index 0000000000..2332ade98e --- /dev/null +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/param/client/CatCountClient.java @@ -0,0 +1,23 @@ +package com.baeldung.micronaut.apiversioning.param.client; + +import io.micronaut.core.annotation.Nullable; +import io.micronaut.core.async.annotation.SingleResult; +import io.micronaut.http.HttpHeaders; +import io.micronaut.http.annotation.Get; +import io.micronaut.http.annotation.Header; +import io.micronaut.http.annotation.QueryValue; +import io.micronaut.http.client.annotation.Client; +import io.reactivex.rxjava3.core.Flowable; + +@Client("/") +@Header(name = HttpHeaders.ACCEPT, value = "application/json") +public interface CatCountClient { + + @Get( + uri = "/cat/count", + consumes = {"application/json"}, + produces = {"application/json"} + ) + @SingleResult + Flowable count(@QueryValue("max") @Nullable Integer max, @QueryValue(value = "v", defaultValue = "1") @Nullable Integer version); +} diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/param/server/CatCountController.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/param/server/CatCountController.java new file mode 100644 index 0000000000..43a34a2272 --- /dev/null +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/param/server/CatCountController.java @@ -0,0 +1,37 @@ +package com.baeldung.micronaut.apiversioning.param.server; + +import io.micronaut.core.annotation.NonNull; +import io.micronaut.core.annotation.Nullable; +import io.micronaut.core.version.annotation.Version; +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Get; +import io.micronaut.http.annotation.QueryValue; +import io.reactivex.rxjava3.core.Flowable; + +import java.util.stream.Stream; + +@Controller("/cat") +public class CatCountController { + + @Get(value = "/count", produces = {"application/json"}) + @Version("1") + public Flowable countV1(@QueryValue("max") @Nullable Integer max) { + return Flowable.fromStream( + Stream.iterate(0, i -> i + 1) + .map(index -> "Cat " + index) + .limit(max == null ? 10 : max) + ); + } + + + @Get(value = "/count", produces = {"application/json"}) + @Version("2") + public Flowable countV2(@QueryValue("max") @NonNull Integer max) { + return Flowable.fromStream( + Stream.iterate(0, i -> i + 1) + .map(index -> "Cat " + index) + .limit(max) + ); + } + +} diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/url/client/SheepCountClient.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/url/client/SheepCountClient.java new file mode 100644 index 0000000000..cdb344b4e5 --- /dev/null +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/url/client/SheepCountClient.java @@ -0,0 +1,39 @@ +package com.baeldung.micronaut.apiversioning.url.client; + +import io.micronaut.core.annotation.Nullable; +import io.micronaut.core.async.annotation.SingleResult; +import io.micronaut.http.HttpHeaders; +import io.micronaut.http.annotation.Get; +import io.micronaut.http.annotation.Header; +import io.micronaut.http.annotation.QueryValue; +import io.micronaut.http.client.annotation.Client; +import io.reactivex.rxjava3.core.Flowable; + +@Client("/") +@Header(name = HttpHeaders.ACCEPT, value = "application/json") +public interface SheepCountClient { + + @Get( + uri = "/v1/sheep/count", + consumes = {"application/json"}, + produces = {"application/json"} + ) + @SingleResult + Flowable countV1(@QueryValue("max") @Nullable Integer max); + + @Get( + uri = "/v2/sheep/count", + consumes = {"application/json"}, + produces = {"application/json"} + ) + @SingleResult + Flowable countV2(@QueryValue("max") @Nullable Integer max); + + @Get( + uri = "/sheep/count", + consumes = {"application/json"}, + produces = {"application/json"} + ) + @SingleResult + Flowable countDefault(@QueryValue("max") @Nullable Integer max); +} diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/url/server/SheepCountControllerV1.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/url/server/SheepCountControllerV1.java new file mode 100644 index 0000000000..5ee6a2a57d --- /dev/null +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/url/server/SheepCountControllerV1.java @@ -0,0 +1,26 @@ +package com.baeldung.micronaut.apiversioning.url.server; + +import io.micronaut.core.annotation.Nullable; +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Get; +import io.reactivex.rxjava3.core.Flowable; + +import java.util.stream.Stream; + +@Controller("/v1/sheep/count") +public class SheepCountControllerV1 { + + @Get( + uri = "{?max}", + consumes = {"application/json"}, + produces = {"application/json"} + ) + Flowable countV1(@Nullable Integer max) { + return Flowable.fromStream( + Stream.iterate(0, i -> i + 1) + .map(index -> "Sheep " + index) + .limit(max == null ? 10 : max) + ); + } + +} diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/url/server/SheepCountControllerV2.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/url/server/SheepCountControllerV2.java new file mode 100644 index 0000000000..d95f4a3cca --- /dev/null +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/apiversioning/url/server/SheepCountControllerV2.java @@ -0,0 +1,27 @@ +package com.baeldung.micronaut.apiversioning.url.server; + +import io.micronaut.core.annotation.NonNull; +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Get; +import io.micronaut.http.annotation.QueryValue; +import io.reactivex.rxjava3.core.Flowable; + +import java.util.stream.Stream; + +@Controller +public class SheepCountControllerV2 { + + @Get( + uris = {"/v2/sheep/count", "/sheep/count"}, + consumes = {"application/json"}, + produces = {"application/json"} + ) + Flowable countV2(@QueryValue("max") @NonNull Integer max) { + return Flowable.fromStream( + Stream.iterate(0, i -> i + 1) + .map(index -> "Sheep " + index) + .limit(max) + ); + } + +} diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/client/ConcreteGreetingClient.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/client/ConcreteGreetingClient.java index 96bc51f235..943b2f703e 100644 --- a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/client/ConcreteGreetingClient.java +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/client/ConcreteGreetingClient.java @@ -1,28 +1,27 @@ package com.baeldung.micronaut.helloworld.client; import io.micronaut.http.HttpRequest; +import io.micronaut.http.client.HttpClient; import io.micronaut.http.client.annotation.Client; -import io.micronaut.http.client.RxHttpClient; -import io.reactivex.Single; - -import javax.inject.Singleton; +import io.reactivex.rxjava3.core.Single; +import jakarta.inject.Singleton; @Singleton public class ConcreteGreetingClient { - private RxHttpClient httpClient; + private HttpClient httpClient; - public ConcreteGreetingClient(@Client("/") RxHttpClient httpClient) { + public ConcreteGreetingClient(@Client("/") HttpClient httpClient) { this.httpClient = httpClient; } public String greet(String name) { HttpRequest req = HttpRequest.GET("/greet/" + name); - return httpClient.retrieve(req).blockingFirst(); + return Single.fromPublisher(httpClient.retrieve(req)).blockingGet(); } public Single greetAsync(String name) { HttpRequest req = HttpRequest.GET("/async/greet/" + name); - return httpClient.retrieve(req).first("An error as occurred"); + return Single.fromPublisher(httpClient.retrieve(req)); } } diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/controller/AsyncGreetController.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/controller/AsyncGreetController.java index 4d86b9dfed..862a822573 100644 --- a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/controller/AsyncGreetController.java +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/controller/AsyncGreetController.java @@ -3,9 +3,9 @@ package com.baeldung.micronaut.helloworld.server.controller; import com.baeldung.micronaut.helloworld.server.service.GreetingService; import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; -import io.reactivex.Single; -import javax.inject.Inject; +import io.reactivex.rxjava3.core.Single; +import jakarta.inject.Inject; @Controller("/async/greet") public class AsyncGreetController { diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/controller/GreetController.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/controller/GreetController.java index c890c037e4..ba3b6197d8 100644 --- a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/controller/GreetController.java +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/controller/GreetController.java @@ -7,7 +7,7 @@ import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; import io.micronaut.http.annotation.Post; -import javax.inject.Inject; +import jakarta.inject.Inject; @Controller("/greet") public class GreetController { diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/service/EnglishGreetingService.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/service/EnglishGreetingService.java index 8ea5172cf6..865ee0b639 100644 --- a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/service/EnglishGreetingService.java +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/service/EnglishGreetingService.java @@ -2,7 +2,7 @@ package com.baeldung.micronaut.helloworld.server.service; import io.micronaut.context.annotation.Primary; -import javax.inject.Singleton; +import jakarta.inject.Singleton; @Primary @Singleton diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/service/SpanishGreetingService.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/service/SpanishGreetingService.java index 1ec53d8b2d..e426c2911e 100644 --- a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/service/SpanishGreetingService.java +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/helloworld/server/service/SpanishGreetingService.java @@ -1,6 +1,6 @@ package com.baeldung.micronaut.helloworld.server.service; -import javax.inject.Singleton; +import jakarta.inject.Singleton; @Singleton public class SpanishGreetingService implements GreetingService { diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/CompareApplication.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/CompareApplication.java index 4654526b28..0fea9f970b 100644 --- a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/CompareApplication.java +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/CompareApplication.java @@ -1,9 +1,11 @@ package com.baeldung.micronaut.vs.springboot; + import io.micronaut.runtime.Micronaut; public class CompareApplication { + public static void main(String[] args) { - Micronaut.run(CompareApplication.class); + Micronaut.run(CompareApplication.class, args); } -} +} \ No newline at end of file diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/client/ArithmeticClientImpl.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/client/ArithmeticClientImpl.java index 6b7ae900be..95e3157bfe 100644 --- a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/client/ArithmeticClientImpl.java +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/client/ArithmeticClientImpl.java @@ -1,46 +1,46 @@ package com.baeldung.micronaut.vs.springboot.client; -import javax.inject.Singleton; - import io.micronaut.http.HttpRequest; -import io.micronaut.http.client.RxHttpClient; +import io.micronaut.http.client.HttpClient; import io.micronaut.http.client.annotation.Client; +import io.reactivex.rxjava3.core.Single; +import jakarta.inject.Singleton; @Singleton public class ArithmeticClientImpl { - private RxHttpClient httpClient; + private HttpClient httpClient; - public ArithmeticClientImpl(@Client("/") RxHttpClient httpClient) { + public ArithmeticClientImpl(@Client("/") HttpClient httpClient) { this.httpClient = httpClient; } public String sum(float number1, float number2) { HttpRequest req = HttpRequest.GET("/math/sum/" + number1 + "/" + number2); - return httpClient.retrieve(req) - .blockingFirst(); + return Single.fromPublisher(httpClient.retrieve(req)) + .blockingGet(); } public String subtract(float number1, float number2) { HttpRequest req = HttpRequest.GET("/math/subtract/" + number1 + "/" + number2); - return httpClient.retrieve(req) - .blockingFirst(); + return Single.fromPublisher(httpClient.retrieve(req)) + .blockingGet(); } public String multiply(float number1, float number2) { HttpRequest req = HttpRequest.GET("/math/multiply/" + number1 + "/" + number2); - return httpClient.retrieve(req) - .blockingFirst(); + return Single.fromPublisher(httpClient.retrieve(req)) + .blockingGet(); } public String divide(float number1, float number2) { HttpRequest req = HttpRequest.GET("/math/divide/" + number1 + "/" + number2); - return httpClient.retrieve(req) - .blockingFirst(); + return Single.fromPublisher(httpClient.retrieve(req)) + .blockingGet(); } public String memory() { HttpRequest req = HttpRequest.GET("/math/memory"); - return httpClient.retrieve(req) - .blockingFirst(); + return Single.fromPublisher(httpClient.retrieve(req)) + .blockingGet(); } } diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/controller/ArithmeticController.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/controller/ArithmeticController.java index 5bc0e865e1..b774556ece 100644 --- a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/controller/ArithmeticController.java +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/controller/ArithmeticController.java @@ -3,7 +3,7 @@ package com.baeldung.micronaut.vs.springboot.controller; import java.lang.management.ManagementFactory; import java.lang.management.MemoryMXBean; -import javax.inject.Inject; +import jakarta.inject.Inject; import com.baeldung.micronaut.vs.springboot.service.ArithmeticService; diff --git a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/service/ArithmeticService.java b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/service/ArithmeticService.java index e0e4680495..599a6ee4cf 100644 --- a/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/service/ArithmeticService.java +++ b/microservices-modules/micronaut/src/main/java/com/baeldung/micronaut/vs/springboot/service/ArithmeticService.java @@ -1,6 +1,6 @@ package com.baeldung.micronaut.vs.springboot.service; -import javax.inject.Singleton; +import jakarta.inject.Singleton; @Singleton public class ArithmeticService { diff --git a/microservices-modules/micronaut/src/main/resources/application.yml b/microservices-modules/micronaut/src/main/resources/application.yml index 32daacd4aa..b265d245aa 100644 --- a/microservices-modules/micronaut/src/main/resources/application.yml +++ b/microservices-modules/micronaut/src/main/resources/application.yml @@ -1,5 +1,19 @@ +context-path: / + micronaut: - application: - name: hello-world-server - server: - port: ${random.port} \ No newline at end of file + router: + versioning: + enabled: true + default-version: 2 + parameter: + enabled: true + names: 'v,api-version' + header: + enabled: true + names: + - 'X-API-VERSION' + + application: + name: hello-world-server + server: + port: ${random.port} diff --git a/microservices-modules/micronaut/src/main/resources/logback.xml b/microservices-modules/micronaut/src/main/resources/logback.xml index afaebf8e17..4db42a7916 100644 --- a/microservices-modules/micronaut/src/main/resources/logback.xml +++ b/microservices-modules/micronaut/src/main/resources/logback.xml @@ -8,6 +8,12 @@ + + + diff --git a/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/custom/client/BirdCountClientUnitTest.java b/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/custom/client/BirdCountClientUnitTest.java new file mode 100644 index 0000000000..a3a547f9e2 --- /dev/null +++ b/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/custom/client/BirdCountClientUnitTest.java @@ -0,0 +1,42 @@ +package com.baeldung.micronaut.apiversioning.custom.client; + +import io.micronaut.context.annotation.Property; +import io.micronaut.http.client.exceptions.HttpClientResponseException; +import io.micronaut.runtime.EmbeddedApplication; +import io.micronaut.test.extensions.junit5.annotation.MicronautTest; +import jakarta.inject.Inject; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +@MicronautTest +@Property(name = "my.router.versioning.enabled", value = "true") +class BirdCountClientUnitTest { + + @Inject + private EmbeddedApplication application; + + @Inject + private BirdCountClient client; + + @Test + void givenTheCountApi_whenUsingV1ViaCustomStrategy_shouldRouteToProperHandler() { + Assertions.assertEquals(10, client.countV1(null).blockingSingle().split(",").length); + Assertions.assertEquals(4, client.countV1(4).blockingSingle().split(",").length); + } + + @Test + void givenTheCountApi_whenUsingV2ViaCustomStrategy_shouldRouteToProperHandler() { + Assertions.assertThrows(HttpClientResponseException.class, + () -> client.countV2(null).count().blockingGet()); + + Assertions.assertEquals(6, client.countV2(6).blockingSingle().split(",").length); + } + + @Test + void givenTheCountApi_whenUsingDefaultVersionViaCustomStrategy_shouldRouteToProperHandler() { + Assertions.assertThrows(HttpClientResponseException.class, + () -> client.countDefault(null).count().blockingGet()); + + Assertions.assertEquals(6, client.countDefault(6).blockingSingle().split(",").length); + } +} \ No newline at end of file diff --git a/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/header/client/DogCountClientUnitTest.java b/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/header/client/DogCountClientUnitTest.java new file mode 100644 index 0000000000..4a47c76943 --- /dev/null +++ b/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/header/client/DogCountClientUnitTest.java @@ -0,0 +1,40 @@ +package com.baeldung.micronaut.apiversioning.header.client; + +import io.micronaut.http.client.exceptions.HttpClientResponseException; +import io.micronaut.runtime.EmbeddedApplication; +import io.micronaut.test.extensions.junit5.annotation.MicronautTest; +import jakarta.inject.Inject; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +@MicronautTest +class DogCountClientUnitTest { + + @Inject + private EmbeddedApplication application; + + @Inject + private DogCountClient dogCountClient; + + @Test + void givenTheCountApi_whenUsingV1ViaHeaderStrategy_shouldRouteToProperHandler() { + Assertions.assertEquals(10, dogCountClient.countV1(null).blockingSingle().split(",").length); + Assertions.assertEquals(4, dogCountClient.countV1(4).blockingSingle().split(",").length); + } + + @Test + void givenTheCountApi_whenUsingV2ViaHeaderStrategy_shouldRouteToProperHandler() { + Assertions.assertThrows(HttpClientResponseException.class, + () -> dogCountClient.countV2(null).count().blockingGet()); + + Assertions.assertEquals(6, dogCountClient.countV2(6).blockingSingle().split(",").length); + } + + @Test + void givenTheCountApi_whenUsingDefaultVersionViaHeaderStrategy_shouldRouteToProperHandler() { + Assertions.assertThrows(HttpClientResponseException.class, + () -> dogCountClient.countDefault(null).count().blockingGet()); + + Assertions.assertEquals(6, dogCountClient.countDefault(6).blockingSingle().split(",").length); + } +} \ No newline at end of file diff --git a/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/param/client/CatCountClientUnitTest.java b/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/param/client/CatCountClientUnitTest.java new file mode 100644 index 0000000000..266f72eed8 --- /dev/null +++ b/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/param/client/CatCountClientUnitTest.java @@ -0,0 +1,38 @@ +package com.baeldung.micronaut.apiversioning.param.client; + +import io.micronaut.http.client.exceptions.HttpClientResponseException; +import io.micronaut.runtime.EmbeddedApplication; +import io.micronaut.test.extensions.junit5.annotation.MicronautTest; +import jakarta.inject.Inject; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +@MicronautTest +class CatCountClientUnitTest { + + @Inject + private EmbeddedApplication application; + + @Inject + private CatCountClient client; + + @Test + void givenTheCountApi_whenUsingV1ViaParameterStrategy_shouldRouteToProperHandler() { + Assertions.assertEquals(10, client.count(null, 1).blockingSingle().split(",").length); + Assertions.assertEquals(5, client.count(5, 1).blockingSingle().split(",").length); + } + + @Test + void givenTheCountApi_whenUsingV2ViaParameterStrategy_shouldRouteToProperHandler() { + Assertions.assertThrows(HttpClientResponseException.class, + () -> client.count(null, 2).count().blockingGet()); + + Assertions.assertEquals(6, client.count(6, 2).blockingSingle().split(",").length); + } + + @Test + void givenTheCountApi_whenUsingDefaultVersionViaParameterStrategy_shouldRouteToProperHandler() { + Assertions.assertEquals(10, client.count(null, null).blockingSingle().split(",").length); + Assertions.assertEquals(6, client.count(6, null).blockingSingle().split(",").length); + } +} \ No newline at end of file diff --git a/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/url/client/SheepCountClientUnitTest.java b/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/url/client/SheepCountClientUnitTest.java new file mode 100644 index 0000000000..e082793fe1 --- /dev/null +++ b/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/apiversioning/url/client/SheepCountClientUnitTest.java @@ -0,0 +1,44 @@ +package com.baeldung.micronaut.apiversioning.url.client; + +import io.micronaut.http.client.exceptions.HttpClientResponseException; +import io.micronaut.runtime.EmbeddedApplication; +import io.micronaut.test.extensions.junit5.annotation.MicronautTest; +import jakarta.inject.Inject; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.stream.Collectors; + +@MicronautTest +class SheepCountClientUnitTest { + + @Inject + private EmbeddedApplication application; + @Inject + private SheepCountClient client; + + @Test + void givenTheCountApi_whenUsingV1ViaUrlStrategy_shouldRouteToProperHandler() { + Assertions.assertEquals(10, client.countV1(null).blockingSingle().split(",").length); + Assertions.assertEquals(4, client.countV1(4).blockingSingle().split(",").length); + } + + @Test + void givenTheCountApi_whenUsingV2ViaUrlStrategy_shouldRouteToProperHandler() { + Assertions.assertThrows(HttpClientResponseException.class, + () -> client.countV2(null).count().blockingGet()); + + final var actual = client.countV2(4).blockingSingle().split(",").length; + Assertions.assertEquals(4, actual); + } + + @Test + void givenTheCountApi_whenUsingDefaultVersionViaUrlStrategy_shouldRouteToProperHandler() { + Assertions.assertThrows(HttpClientResponseException.class, + () -> client.countDefault(null).count().blockingGet()); + + final var actual = client.countDefault(4).blockingSingle().split(",").length; + Assertions.assertEquals(4, actual); + } +} \ No newline at end of file diff --git a/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/helloworld/client/ConcreteGreetingClientUnitTest.java b/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/helloworld/client/ConcreteGreetingClientUnitTest.java index 336374d5a6..88a9782074 100644 --- a/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/helloworld/client/ConcreteGreetingClientUnitTest.java +++ b/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/helloworld/client/ConcreteGreetingClientUnitTest.java @@ -1,31 +1,19 @@ package com.baeldung.micronaut.helloworld.client; -import io.micronaut.context.ApplicationContext; -import io.micronaut.runtime.server.EmbeddedServer; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import io.micronaut.runtime.EmbeddedApplication; +import io.micronaut.test.extensions.junit5.annotation.MicronautTest; +import jakarta.inject.Inject; +import org.junit.jupiter.api.Test; -import static junit.framework.TestCase.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class ConcreteGreetingClientUnitTest -{ - private EmbeddedServer server; +@MicronautTest +public class ConcreteGreetingClientUnitTest { + @Inject + private EmbeddedApplication application; + @Inject private ConcreteGreetingClient client; - @Before - public void setup() - { - server = ApplicationContext.run(EmbeddedServer.class); - client = server.getApplicationContext().getBean(ConcreteGreetingClient.class); - } - - @After - public void cleanup() - { - server.stop(); - } - @Test public void testGreeting() { assertEquals(client.greet("Mike"), "Hello Mike"); diff --git a/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/helloworld/client/GreetingClientUnitTest.java b/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/helloworld/client/GreetingClientUnitTest.java index c47fb3a31d..5b269531e7 100644 --- a/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/helloworld/client/GreetingClientUnitTest.java +++ b/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/helloworld/client/GreetingClientUnitTest.java @@ -1,30 +1,21 @@ package com.baeldung.micronaut.helloworld.client; -import io.micronaut.context.ApplicationContext; -import io.micronaut.runtime.server.EmbeddedServer; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import io.micronaut.runtime.EmbeddedApplication; +import io.micronaut.test.extensions.junit5.annotation.MicronautTest; +import jakarta.inject.Inject; +import org.junit.jupiter.api.Test; -import static junit.framework.TestCase.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +@MicronautTest public class GreetingClientUnitTest { - private EmbeddedServer server; + + @Inject + private EmbeddedApplication application; + + @Inject private GreetingClient client; - @Before - public void setup() - { - server = ApplicationContext.run(EmbeddedServer.class); - client = server.getApplicationContext().getBean(GreetingClient.class); - } - - @After - public void cleanup() - { - server.stop(); - } - @Test public void testGreeting() { assertEquals(client.greet("Mike"), "Hello Mike"); diff --git a/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/vs/springboot/ArithmeticClientUnitTest.java b/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/vs/springboot/ArithmeticClientUnitTest.java index 9a1b095d22..fa191778f5 100644 --- a/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/vs/springboot/ArithmeticClientUnitTest.java +++ b/microservices-modules/micronaut/src/test/java/com/baeldung/micronaut/vs/springboot/ArithmeticClientUnitTest.java @@ -1,34 +1,21 @@ package com.baeldung.micronaut.vs.springboot; -import static org.junit.Assert.assertEquals; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; - -import io.micronaut.context.ApplicationContext; -import io.micronaut.runtime.server.EmbeddedServer; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - import com.baeldung.micronaut.vs.springboot.client.ArithmeticClientImpl; +import io.micronaut.runtime.EmbeddedApplication; +import io.micronaut.test.extensions.junit5.annotation.MicronautTest; +import jakarta.inject.Inject; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; + +@MicronautTest public class ArithmeticClientUnitTest { - private EmbeddedServer server; + @Inject + private EmbeddedApplication server; + @Inject private ArithmeticClientImpl client; - @Before - public void setup() { - server = ApplicationContext.run(EmbeddedServer.class); - client = server.getApplicationContext() - .getBean(ArithmeticClientImpl.class); - } - - @After - public void cleanup() { - server.stop(); - } - @Test public void givenTwoNumbers_whenAdd_thenCorrectAnswerReturned() { String expected = Float.valueOf(10 + 20).toString(); @@ -56,6 +43,6 @@ public class ArithmeticClientUnitTest { @Test public void whenMemory_thenCorrectAnswerReturned() { String expected = "Initial:"; - assertThat(client.memory(), containsString(expected)); + assertThat(client.memory()).contains(expected); } } From 7e1d5991e61a969ec922f5a7182096ee76002d0f Mon Sep 17 00:00:00 2001 From: mcasari Date: Tue, 3 Oct 2023 23:41:11 +0200 Subject: [PATCH 152/193] BAEL-6846 - tests revision due to article updates --- .../FloatToBigDecimalUnitTest.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java index fe5dc360e4..9d125f557d 100644 --- a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java +++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java @@ -17,40 +17,32 @@ class FloatToBigDecimalUnitTest { @Test public void whenCreatedFromFloat_thenMatchesInternallyStoredValue() { - float floatToConvert = 1.1f; + float floatToConvert = 1.10000002384185791015625f; BigDecimal bdFromFloat = new BigDecimal(floatToConvert); assertEquals("1.10000002384185791015625", bdFromFloat.toString()); } @Test public void whenCreatedFromString_thenPreservesTheOriginal() { - BigDecimal bdFromString = new BigDecimal("1.1"); - assertEquals("1.1", bdFromString.toString()); + BigDecimal bdFromString = new BigDecimal("1.10000002384185791015625"); + assertEquals("1.10000002384185791015625", bdFromString.toString()); } @Test public void whenCreatedFromFloatConvertedToString_thenFloatInternalValueGetsTruncated() { - String floatValue = Float.toString(1.1f); + String floatValue = Float.toString(1.10000002384185791015625f); BigDecimal bdFromString = new BigDecimal(floatValue); assertEquals("1.1", floatValue); assertEquals("1.1", bdFromString.toString()); } - @Test - public void whenFloatConvertedToString_thenGetsTruncated() { - String floatValue = Float.toString(1.10000002384185791015625f); - assertEquals("1.1", floatValue); - } - @Test public void whenCreatedByValueOf_thenFloatValueGetsTruncated() { - assertEquals("1.100000023841858", BigDecimal.valueOf(1.1f).toString()); assertEquals("1.100000023841858", BigDecimal.valueOf(1.10000002384185791015625f).toString()); } @Test public void whenDoubleConvertsFloatToString_thenFloatValueGetsTruncated() { - assertEquals("1.100000023841858", Double.toString(1.1f)); assertEquals("1.100000023841858", Double.toString(1.10000002384185791015625f)); } From d76083ae0473e78f515f1c48d374eb7cb0c04f14 Mon Sep 17 00:00:00 2001 From: Eugene Kovko <37694937+eukovko@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:23:38 +0200 Subject: [PATCH 153/193] BAEL-6828: Finding the Square Root of a BigInteger in Java (#14903) * BAEL-6828: Finding the Square Root of a BigInteger in Java * BAEL-6828: Remove Java 9 annotation from the test * BAEL-6828: Remove Java 9 profile --- core-java-modules/core-java-numbers-6/pom.xml | 7 +- .../bigintegerroot/BenchmarkRunner.java | 8 ++ .../bigintegerroot/BigIntegerHolder.java | 10 ++ .../BigIntegerSquareRootBenchmark.java | 60 ++++++++++ .../bigintegerroot/algorithms/Newton.java | 29 +++++ .../bigintegerroot/algorithms/NewtonPlus.java | 108 ++++++++++++++++++ .../BigIntegerSquareRootUnitTest.java | 39 +++++++ 7 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/BenchmarkRunner.java create mode 100644 core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/BigIntegerHolder.java create mode 100644 core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/BigIntegerSquareRootBenchmark.java create mode 100644 core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/algorithms/Newton.java create mode 100644 core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/algorithms/NewtonPlus.java create mode 100644 core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/bigintegerroot/BigIntegerSquareRootUnitTest.java diff --git a/core-java-modules/core-java-numbers-6/pom.xml b/core-java-modules/core-java-numbers-6/pom.xml index 531f1293d1..7a3b3d4426 100644 --- a/core-java-modules/core-java-numbers-6/pom.xml +++ b/core-java-modules/core-java-numbers-6/pom.xml @@ -25,8 +25,12 @@ ${commons-codec} test + + com.google.guava + guava + ${guava.version} + - core-java-numbers-6 @@ -39,5 +43,6 @@ 1.15 + 32.1.2-jre \ No newline at end of file diff --git a/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/BenchmarkRunner.java b/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/BenchmarkRunner.java new file mode 100644 index 0000000000..2ac57a9c0c --- /dev/null +++ b/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/BenchmarkRunner.java @@ -0,0 +1,8 @@ +package com.baeldung.bigintegerroot; + +public class BenchmarkRunner { + public static void main(String[] args) throws Exception { + org.openjdk.jmh.Main.main(args); + } +} + diff --git a/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/BigIntegerHolder.java b/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/BigIntegerHolder.java new file mode 100644 index 0000000000..c2d2f30827 --- /dev/null +++ b/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/BigIntegerHolder.java @@ -0,0 +1,10 @@ +package com.baeldung.bigintegerroot; + +public class BigIntegerHolder { + + private BigIntegerHolder() { + } + public static final String BIG_NUMBER = "179769313000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; + public static final String VERY_BIG_NUMBER = "32473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834"; + public static final String INSANELY_BIG_NUMBER = "3247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834324739274923749279342847923749237492374987230480128343247392749237492793428479237492374923749872304801283432473927492374927934284792374923749237498723048012834"; +} diff --git a/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/BigIntegerSquareRootBenchmark.java b/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/BigIntegerSquareRootBenchmark.java new file mode 100644 index 0000000000..645e4eb2dd --- /dev/null +++ b/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/BigIntegerSquareRootBenchmark.java @@ -0,0 +1,60 @@ +package com.baeldung.bigintegerroot; + +import static com.baeldung.bigintegerroot.BigIntegerHolder.*; + +import com.baeldung.bigintegerroot.algorithms.Newton; +import com.baeldung.bigintegerroot.algorithms.NewtonPlus; +import com.google.common.math.BigIntegerMath; +import java.math.BigInteger; +import java.math.RoundingMode; +import java.util.concurrent.TimeUnit; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.infra.Blackhole; + +@Warmup(iterations = 1) +@Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MINUTES) +@Fork(1) +@State(Scope.Benchmark) +public class BigIntegerSquareRootBenchmark { + + @Param({BIG_NUMBER, VERY_BIG_NUMBER, INSANELY_BIG_NUMBER}) + public String number; + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void calculateRootWithJava(Blackhole blackhole) { + final BigInteger integer = new BigInteger(number); + final BigInteger root = integer.sqrt(); + blackhole.consume(root); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void calculateRootWithGuava(Blackhole blackhole) { + final BigInteger integer = new BigInteger(number); + final BigInteger root = BigIntegerMath.sqrt(integer, RoundingMode.DOWN); + blackhole.consume(root); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void calculateRootWithNewtonPlus(Blackhole blackhole) { + final BigInteger integer = new BigInteger(number); + final BigInteger root = NewtonPlus.sqrt(integer); + blackhole.consume(root); + } + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void calculateRootWithNewton(Blackhole blackhole) { + final BigInteger integer = new BigInteger(number); + final BigInteger root = Newton.sqrt(integer); + blackhole.consume(root); + } +} diff --git a/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/algorithms/Newton.java b/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/algorithms/Newton.java new file mode 100644 index 0000000000..07acba7537 --- /dev/null +++ b/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/algorithms/Newton.java @@ -0,0 +1,29 @@ +package com.baeldung.bigintegerroot.algorithms; + +import java.math.BigInteger; + +public class Newton { + + private Newton() { + } + + public static BigInteger sqrt(BigInteger n) { + // Initial approximation + BigInteger x = n.divide(BigInteger.TWO); + + // Tolerance level (small positive integer) + BigInteger tolerance = BigInteger.ONE; + + while (true) { + // x_new = 0.5 * (x + n / x) + BigInteger xNew = x.add(n.divide(x)).divide(BigInteger.TWO); + + // Check for convergence within tolerance + if (x.subtract(xNew).abs().compareTo(tolerance) <= 0) { + return xNew; + } + + x = xNew; + } + } +} diff --git a/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/algorithms/NewtonPlus.java b/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/algorithms/NewtonPlus.java new file mode 100644 index 0000000000..80d50c0ca5 --- /dev/null +++ b/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/bigintegerroot/algorithms/NewtonPlus.java @@ -0,0 +1,108 @@ +package com.baeldung.bigintegerroot.algorithms; + +import java.math.BigInteger; + +public class NewtonPlus { + + private NewtonPlus() { + } + + // A fast square root by Ryan Scott White. + public static BigInteger sqrt(BigInteger x) { + if (x.compareTo(BigInteger.valueOf(144838757784765629L)) < 0) { + long xAsLong = x.longValue(); + long vInt = (long)Math.sqrt(xAsLong); + if (vInt * vInt > xAsLong) + vInt--; + return BigInteger.valueOf(vInt); } + + double xAsDub = x.doubleValue(); + BigInteger val; + if (xAsDub < 2.1267e37) // 2.12e37 largest here + // since sqrt(long.max*long.max) > long.max + { + long vInt = (long)Math.sqrt(xAsDub); + val = BigInteger.valueOf + ((vInt + x.divide(BigInteger.valueOf(vInt)).longValue()) >> 1); + } + else if (xAsDub < 4.3322e127) { + // Convert a double to a BigInteger + long bits = Double.doubleToLongBits(Math.sqrt(xAsDub)); + int exp = ((int) (bits >> 52) & 0x7ff) - 1075; + val = BigInteger.valueOf((bits & ((1L << 52)) - 1) | (1L << 52)).shiftLeft(exp); + + val = x.divide(val).add(val).shiftRight(1); + if (xAsDub > 2e63) { + val = x.divide(val).add(val).shiftRight(1); } + } + else // handle large numbers over 4.3322e127 + { + int xLen = x.bitLength(); + int wantedPrecision = ((xLen + 1) / 2); + int xLenMod = xLen + (xLen & 1) + 1; + + //////// Do the first Sqrt on Hardware //////// + long tempX = x.shiftRight(xLenMod - 63).longValue(); + double tempSqrt1 = Math.sqrt(tempX); + long valLong = Double.doubleToLongBits(tempSqrt1) & 0x1fffffffffffffL; + + if (valLong == 0) + valLong = 1L << 53; + + //////// Classic Newton Iterations //////// + val = BigInteger.valueOf(valLong).shiftLeft(53 - 1) + .add((x.shiftRight(xLenMod - + (3 * 53))).divide(BigInteger.valueOf(valLong))); + + int size = 106; + for (; size < 256; size <<= 1) { + val = val.shiftLeft(size - 1).add(x.shiftRight + (xLenMod - (3*size)).divide(val));} + + if (xAsDub > 4e254) { // 4e254 = 1<<845.77 + int numOfNewtonSteps = 31 - + Integer.numberOfLeadingZeros(wantedPrecision / size)+1; + + ////// Apply Starting Size //////// + int wantedSize = (wantedPrecision >> numOfNewtonSteps) + 2; + int needToShiftBy = size - wantedSize; + val = val.shiftRight(needToShiftBy); + + size = wantedSize; + do { + //////// Newton Plus Iteration //////// + int shiftX = xLenMod - (3 * size); + BigInteger valSqrd = val.multiply(val).shiftLeft(size - 1); + BigInteger valSU = x.shiftRight(shiftX).subtract(valSqrd); + val = val.shiftLeft(size).add(valSU.divide(val)); + size *= 2; + } while (size < wantedPrecision); + } + val = val.shiftRight(size - wantedPrecision); + } + + // Detect a round ups. This function can be further optimized - see article. + // For a ~7% speed bump the following line can be removed but round-ups will occur. + if (val.multiply(val).compareTo(x) > 0) + val = val.subtract(BigInteger.ONE); + + // Enabling the below will guarantee an error is stopped for larger numbers. + // Note: As of this writing, there are no known errors. + BigInteger tmp = val.multiply(val); + if (tmp.compareTo(x) > 0) { + System.out.println("val^2(" + val.multiply(val).toString() + + ") ≥ x(" + x.toString()+")"); + System.console().readLine(); + //throw new Exception("Sqrt function had internal error - value too high"); + } + if (tmp.add(val.shiftLeft(1)).add(BigInteger.ONE).compareTo(x) <= 0) { + System.out.println("(val+1)^2(" + + val.add(BigInteger.ONE).multiply(val.add(BigInteger.ONE)).toString() + + ") ≥ x(" + x.toString() + ")"); + System.console().readLine(); + //throw new Exception("Sqrt function had internal error - value too low"); + } + + return val; + } +} diff --git a/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/bigintegerroot/BigIntegerSquareRootUnitTest.java b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/bigintegerroot/BigIntegerSquareRootUnitTest.java new file mode 100644 index 0000000000..edb75b16ef --- /dev/null +++ b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/bigintegerroot/BigIntegerSquareRootUnitTest.java @@ -0,0 +1,39 @@ +package com.baeldung.bigintegerroot; + + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.baeldung.bigintegerroot.algorithms.Newton; +import com.baeldung.bigintegerroot.algorithms.NewtonPlus; +import com.google.common.math.BigIntegerMath; +import java.math.BigInteger; +import java.math.RoundingMode; +import java.util.stream.Stream; +import org.apache.commons.math3.util.Pair; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +class BigIntegerSquareRootUnitTest { + + @ParameterizedTest + @ValueSource(strings = { + BigIntegerHolder.BIG_NUMBER, + BigIntegerHolder.VERY_BIG_NUMBER, + BigIntegerHolder.VERY_BIG_NUMBER + }) + void squareRootTest(String number) { + final BigInteger bigInteger = new BigInteger(number); + final BigInteger javaRoot = bigInteger.sqrt(); + final BigInteger guavaRoot = BigIntegerMath.sqrt(bigInteger, RoundingMode.DOWN); + final BigInteger newtonRoot = Newton.sqrt(bigInteger); + final BigInteger newtonPlusRoot = NewtonPlus.sqrt(bigInteger); + + assertTrue(Stream.of( + new Pair<>(javaRoot, guavaRoot), + new Pair<>(guavaRoot, newtonRoot), + new Pair<>(newtonRoot, newtonPlusRoot) + ).allMatch(pair -> pair.getFirst().equals(pair.getSecond()))); + } +} \ No newline at end of file From 0c0dddef88f18c80646e08a8420446a38f10a0b2 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:31:17 +0800 Subject: [PATCH 154/193] Update README.md [skip ci] --- core-java-modules/core-java-collections-conversions-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-collections-conversions-3/README.md b/core-java-modules/core-java-collections-conversions-3/README.md index f89cd199ff..653f518840 100644 --- a/core-java-modules/core-java-collections-conversions-3/README.md +++ b/core-java-modules/core-java-collections-conversions-3/README.md @@ -3,3 +3,4 @@ This module contains articles about conversions among Collection types in Java. ### Relevant Articles: +- [Converting HashMap Values to an ArrayList in Java](https://www.baeldung.com/java-hashmap-arraylist) From 39f1754fadb605c9d5c1ca1e1a3b5887ce269956 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:38:21 +0800 Subject: [PATCH 155/193] Update README.md [skip ci] --- core-java-modules/core-java-collections-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-collections-5/README.md b/core-java-modules/core-java-collections-5/README.md index 1769d11686..b9fca9e584 100644 --- a/core-java-modules/core-java-collections-5/README.md +++ b/core-java-modules/core-java-collections-5/README.md @@ -5,4 +5,5 @@ ### Relevant Articles: - [Introduction to Roaring Bitmap](https://www.baeldung.com/java-roaring-bitmap-intro) - [Creating Custom Iterator in Java](https://www.baeldung.com/java-creating-custom-iterator) +- [Difference Between Arrays.sort() and Collections.sort()](https://www.baeldung.com/java-arrays-collections-sort-methods) - More articles: [[<-- prev]](/core-java-modules/core-java-collections-4) From 5266e4d218535af94f98f47d948c92aca6295553 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:40:11 +0800 Subject: [PATCH 156/193] Update README.md [skip ci] --- core-java-modules/core-java-char/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-char/README.md b/core-java-modules/core-java-char/README.md index e4af3121c5..56040a3ea5 100644 --- a/core-java-modules/core-java-char/README.md +++ b/core-java-modules/core-java-char/README.md @@ -5,3 +5,4 @@ This module contains articles about Java Character Class ### Relevant Articles: - [Character#isAlphabetic vs. Character#isLetter](https://www.baeldung.com/java-character-isletter-isalphabetic) - [Difference Between Java’s “char” and “String”](https://www.baeldung.com/java-char-vs-string) +- [Increment Character in Java](https://www.baeldung.com/java-char-sequence) From de26c627a75dd0f366fa4e2df65b79b0d872521f Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:45:29 +0800 Subject: [PATCH 157/193] Update README.md [skip ci] --- apache-kafka-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/apache-kafka-2/README.md b/apache-kafka-2/README.md index dc675a0811..40ee701be1 100644 --- a/apache-kafka-2/README.md +++ b/apache-kafka-2/README.md @@ -13,3 +13,4 @@ You can build the project from the command line using: *mvn clean install*, or i - [Read Data From the Beginning Using Kafka Consumer API](https://www.baeldung.com/java-kafka-consumer-api-read) - [Get Partition Count for a Topic in Kafka](https://www.baeldung.com/java-kafka-partition-count-topic) - [bootstrap-server in Kafka Configuration](https://www.baeldung.com/java-kafka-bootstrap-server) +- [Introduction to Apache Kafka](https://www.baeldung.com/apache-kafka) From cfcaee0e0194c9ff60964621f8093bff4ef05e48 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:49:25 +0800 Subject: [PATCH 158/193] Update README.md [skip ci] --- core-java-modules/core-java-os/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-os/README.md b/core-java-modules/core-java-os/README.md index 6d477de70a..81e67e4663 100644 --- a/core-java-modules/core-java-os/README.md +++ b/core-java-modules/core-java-os/README.md @@ -14,5 +14,6 @@ This module contains articles about working with the operating system (OS) in Ja - [How to Run a Shell Command in Java](http://www.baeldung.com/run-shell-command-in-java) - [Taking Screenshots Using Java](https://www.baeldung.com/java-taking-screenshots) - [Java Sound API – Capturing Microphone](https://www.baeldung.com/java-sound-api-capture-mic) +- [How to Detect the Username Using Java](https://www.baeldung.com/java-get-username) This module uses Java 9, so make sure to have the JDK 9 installed to run it. From 7607c700b59ce668f9d8c44ddd75065e842f1109 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:52:15 +0800 Subject: [PATCH 159/193] Update README.md [skip ci] --- core-java-modules/core-java-collections-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-collections-5/README.md b/core-java-modules/core-java-collections-5/README.md index b9fca9e584..e478d87ad0 100644 --- a/core-java-modules/core-java-collections-5/README.md +++ b/core-java-modules/core-java-collections-5/README.md @@ -6,4 +6,5 @@ - [Introduction to Roaring Bitmap](https://www.baeldung.com/java-roaring-bitmap-intro) - [Creating Custom Iterator in Java](https://www.baeldung.com/java-creating-custom-iterator) - [Difference Between Arrays.sort() and Collections.sort()](https://www.baeldung.com/java-arrays-collections-sort-methods) +- [Skipping the First Iteration in Java](https://www.baeldung.com/java-skip-first-iteration) - More articles: [[<-- prev]](/core-java-modules/core-java-collections-4) From d9c845f3d277bcd7f96a788e27cee905821903ce Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:57:02 +0800 Subject: [PATCH 160/193] Update README.md [skip ci] --- core-java-modules/core-java-io-5/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-io-5/README.md b/core-java-modules/core-java-io-5/README.md index 6072e0b6d9..9fb4b967a4 100644 --- a/core-java-modules/core-java-io-5/README.md +++ b/core-java-modules/core-java-io-5/README.md @@ -3,6 +3,6 @@ This module contains articles about core Java input and output (IO) ### Relevant Articles: - +- [Get File Extension From MIME Type in Java](https://www.baeldung.com/java-mime-type-file-extension) - [[<-- Prev]](/core-java-modules/core-java-io-4) From d79e840c9d7e59fecfb8d9cacb10502840b8e5f8 Mon Sep 17 00:00:00 2001 From: Bipin kumar Date: Thu, 5 Oct 2023 13:38:20 +0530 Subject: [PATCH 161/193] JAVA-25433: Fix the failing test in core-java-datetime-conversion (#14878) --- .../EpochTimeToLocalDateTimeConverterUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/epochtolocaldate/EpochTimeToLocalDateTimeConverterUnitTest.java b/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/epochtolocaldate/EpochTimeToLocalDateTimeConverterUnitTest.java index 6e3b250938..80c403bb4e 100644 --- a/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/epochtolocaldate/EpochTimeToLocalDateTimeConverterUnitTest.java +++ b/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/epochtolocaldate/EpochTimeToLocalDateTimeConverterUnitTest.java @@ -12,10 +12,10 @@ public class EpochTimeToLocalDateTimeConverterUnitTest { @Test public void testConvertEpochTimeToLocalDateTime() { long epochTimeMillis = 1624962431000L; // Example epoch time in milliseconds - LocalDateTime expectedDateTime = LocalDateTime.of(2021, 6, 29, 12, 13, 51); + LocalDateTime expectedDateTime = LocalDateTime.of(2021, 6, 29, 10, 27, 11); Instant instant = Instant.ofEpochMilli(epochTimeMillis); - ZoneId zoneId = ZoneId.systemDefault(); + ZoneId zoneId = ZoneId.of("UTC"); LocalDateTime actualDateTime = instant.atZone(zoneId).toLocalDateTime(); assertEquals(expectedDateTime, actualDateTime); From 7073d328c904d783344e58129e02fd22a5758c03 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 5 Oct 2023 16:18:59 +0800 Subject: [PATCH 162/193] Update README.md [skip ci] --- spring-6-rsocket/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-6-rsocket/README.md b/spring-6-rsocket/README.md index 21ab282bd1..ef1f4994f2 100644 --- a/spring-6-rsocket/README.md +++ b/spring-6-rsocket/README.md @@ -3,5 +3,5 @@ This module contains articles about RSocket in Spring Framework 6. ### Relevant articles - -- [Introduction to RSocket](#) \ No newline at end of file +- [RSocket Interface in Spring 6](https://www.baeldung.com/spring-rsocket) +- [Introduction to RSocket](#) From 12809e524b59452290a2ecf0091d9cc210cb6679 Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Thu, 5 Oct 2023 11:54:51 +0300 Subject: [PATCH 163/193] [JAVA-25516] Upgraded spring-boot-actuator module to spring boot 3 (#14874) * [JAVA-25516] Upgraded spring-boot-actuator module to spring boot 3 * [JAVA-25516] Fixed issue related to actuator security --- .../spring-boot-actuator/pom.xml | 17 ++--- .../enabling/SecurityConfiguration.java | 66 ++++++++++++------- .../com/baeldung/endpoints/info/User.java | 8 +-- .../baeldung/metrics/MetricsApplication.java | 2 +- .../baeldung/metrics/filter/MetricFilter.java | 16 ++--- .../EndpointEnablingIntegrationTest.java | 6 +- 6 files changed, 63 insertions(+), 52 deletions(-) diff --git a/spring-boot-modules/spring-boot-actuator/pom.xml b/spring-boot-modules/spring-boot-actuator/pom.xml index 1ccf436bbf..7f630fa96e 100644 --- a/spring-boot-modules/spring-boot-actuator/pom.xml +++ b/spring-boot-modules/spring-boot-actuator/pom.xml @@ -9,9 +9,10 @@ This is simple boot application for Spring boot actuator test - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 @@ -39,16 +40,6 @@ com.h2database h2 - - javax.servlet - javax.servlet-api - provided - - - javax.servlet - jstl - runtime - org.springframework.boot spring-boot-starter-test diff --git a/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/endpoints/enabling/SecurityConfiguration.java b/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/endpoints/enabling/SecurityConfiguration.java index 894c24693e..20ee834d52 100644 --- a/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/endpoints/enabling/SecurityConfiguration.java +++ b/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/endpoints/enabling/SecurityConfiguration.java @@ -1,36 +1,56 @@ package com.baeldung.endpoints.enabling; import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; + import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.crypto.factory.PasswordEncoderFactories; -import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher; +import org.springframework.web.servlet.handler.HandlerMappingIntrospector; -@Configuration @EnableWebSecurity -public class SecurityConfiguration extends WebSecurityConfigurerAdapter { +@Configuration +public class SecurityConfiguration { - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder(); - auth.inMemoryAuthentication() - .withUser("user") - .password(encoder.encode("password")) - .roles("USER") - .and() - .withUser("admin") - .password(encoder.encode("admin")) - .roles("USER", "ADMIN"); + @Bean + MvcRequestMatcher.Builder mvc(HandlerMappingIntrospector introspector) { + return new MvcRequestMatcher.Builder(introspector); } - @Override - protected void configure(HttpSecurity http) throws Exception { - http.requestMatcher(EndpointRequest.toAnyEndpoint()) - .authorizeRequests((requests) -> requests.anyRequest() - .hasRole("ADMIN")); - http.httpBasic(); + @Bean + public SecurityFilterChain filterChain(HttpSecurity http, MvcRequestMatcher.Builder mvc) throws Exception { + http.httpBasic(Customizer.withDefaults()); + http.securityMatcher(EndpointRequest.toAnyEndpoint()); + http.authorizeHttpRequests(authz -> { + authz.requestMatchers(mvc.pattern("/actuator/**")) + .hasRole("ADMIN") + .anyRequest() + .authenticated(); + }); + + return http.build(); + } + + + + @Bean + public InMemoryUserDetailsManager userDetailsService() { + UserDetails user = User.withDefaultPasswordEncoder() + .username("user") + .password("password") + .roles("USER") + .build(); + UserDetails admin = User.withDefaultPasswordEncoder() + .username("admin") + .password("password") + .roles("USER", "ADMIN") + .build(); + return new InMemoryUserDetailsManager(user, admin); } } diff --git a/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/endpoints/info/User.java b/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/endpoints/info/User.java index db4e69127a..88f39d8ccc 100644 --- a/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/endpoints/info/User.java +++ b/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/endpoints/info/User.java @@ -1,9 +1,9 @@ package com.baeldung.endpoints.info; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Table; @Entity @Table(name = "users") diff --git a/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/metrics/MetricsApplication.java b/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/metrics/MetricsApplication.java index 729b3c0b96..ee87412986 100644 --- a/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/metrics/MetricsApplication.java +++ b/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/metrics/MetricsApplication.java @@ -15,7 +15,7 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.web.context.request.RequestContextListener; -import javax.servlet.ServletContext; +import jakarta.servlet.ServletContext; @EnableScheduling @ComponentScan("com.baeldung.metrics") diff --git a/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/metrics/filter/MetricFilter.java b/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/metrics/filter/MetricFilter.java index 0f7579f060..a7aaddf0fb 100644 --- a/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/metrics/filter/MetricFilter.java +++ b/spring-boot-modules/spring-boot-actuator/src/main/java/com/baeldung/metrics/filter/MetricFilter.java @@ -7,14 +7,14 @@ import org.springframework.stereotype.Component; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; @Component public class MetricFilter implements Filter { diff --git a/spring-boot-modules/spring-boot-actuator/src/test/java/com/baeldung/endpoints/enabling/EndpointEnablingIntegrationTest.java b/spring-boot-modules/spring-boot-actuator/src/test/java/com/baeldung/endpoints/enabling/EndpointEnablingIntegrationTest.java index 8274619517..079195714b 100644 --- a/spring-boot-modules/spring-boot-actuator/src/test/java/com/baeldung/endpoints/enabling/EndpointEnablingIntegrationTest.java +++ b/spring-boot-modules/spring-boot-actuator/src/test/java/com/baeldung/endpoints/enabling/EndpointEnablingIntegrationTest.java @@ -13,20 +13,20 @@ import org.springframework.test.web.servlet.MockMvc; @SpringBootTest @AutoConfigureMockMvc -public class EndpointEnablingIntegrationTest { +class EndpointEnablingIntegrationTest { @Autowired private MockMvc mockMvc; @Test @WithMockUser(username = "user", password = "password", roles = "USER") - public void givenWrongAuthentication_whenCallingActuator_thenReturns401() throws Exception { + void givenWrongAuthentication_whenCallingActuator_thenReturns401() throws Exception { mockMvc.perform(get("/actuator")) .andExpect(status().isForbidden()); } @Test @WithMockUser(username = "admin", password = "admin", roles = "ADMIN") - public void givenProperAuthentication_whenCallingActuator_thenReturnsExpectedEndpoints() throws Exception { + void givenProperAuthentication_whenCallingActuator_thenReturnsExpectedEndpoints() throws Exception { mockMvc.perform(get("/actuator")) .andExpect(jsonPath("$._links").exists()) .andExpect(jsonPath("$._links.beans").exists()) From 888734d76028e98957192498483fd3770fdf96c0 Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Thu, 5 Oct 2023 14:12:33 +0300 Subject: [PATCH 164/193] [JAVA-25518] Upgraded spring-boot-mvc-4 module to spring boot 3 (#14860) --- spring-boot-modules/spring-boot-mvc-4/pom.xml | 7 ++++--- .../controller/servlet/HelloWorldServlet.java | 8 ++++---- .../servlet/SpringHelloWorldServlet.java | 8 ++++---- .../SpringHelloServletRegistrationBean.java | 2 +- .../configuration/WebAppInitializer.java | 6 +++--- .../servlets/servlets/GenericCustomServlet.java | 8 ++++---- .../servlets/javaee/AnnotationServlet.java | 10 +++++----- .../servlets/javaee/EEWebXmlServlet.java | 8 ++++---- .../com/baeldung/utils/UtilsApplication.java | 2 +- .../utils/controller/UtilsController.java | 2 +- .../utils/UtilsControllerIntegrationTest.java | 16 +++++++++------- 11 files changed, 40 insertions(+), 37 deletions(-) diff --git a/spring-boot-modules/spring-boot-mvc-4/pom.xml b/spring-boot-modules/spring-boot-mvc-4/pom.xml index dbbb03ad0e..0ae05a764b 100644 --- a/spring-boot-modules/spring-boot-mvc-4/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-4/pom.xml @@ -9,9 +9,10 @@ Module For Spring Boot MVC Web - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 diff --git a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/boot/controller/servlet/HelloWorldServlet.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/boot/controller/servlet/HelloWorldServlet.java index 80c75aa8b5..cedc60bd92 100644 --- a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/boot/controller/servlet/HelloWorldServlet.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/boot/controller/servlet/HelloWorldServlet.java @@ -4,10 +4,10 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.Objects; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; public class HelloWorldServlet extends HttpServlet { private static final long serialVersionUID = 1L; diff --git a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java index f276f94b7c..dbb8ea1b32 100644 --- a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java @@ -4,10 +4,10 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.Objects; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; public class SpringHelloWorldServlet extends HttpServlet { private static final long serialVersionUID = 1L; diff --git a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/common/error/SpringHelloServletRegistrationBean.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/common/error/SpringHelloServletRegistrationBean.java index 3f51a4ab69..b2d6f249a5 100644 --- a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/common/error/SpringHelloServletRegistrationBean.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/common/error/SpringHelloServletRegistrationBean.java @@ -2,7 +2,7 @@ package com.baeldung.common.error; import org.springframework.boot.web.servlet.ServletRegistrationBean; -import javax.servlet.Servlet; +import jakarta.servlet.Servlet; public class SpringHelloServletRegistrationBean extends ServletRegistrationBean { diff --git a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/configuration/WebAppInitializer.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/configuration/WebAppInitializer.java index eadd40355a..7fd83fd59a 100644 --- a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/configuration/WebAppInitializer.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/configuration/WebAppInitializer.java @@ -4,9 +4,9 @@ import org.springframework.web.WebApplicationInitializer; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.context.support.XmlWebApplicationContext; import org.springframework.web.servlet.DispatcherServlet; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRegistration; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRegistration; public class WebAppInitializer implements WebApplicationInitializer { diff --git a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/GenericCustomServlet.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/GenericCustomServlet.java index 49dd9404b7..ee70a142be 100644 --- a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/GenericCustomServlet.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/GenericCustomServlet.java @@ -1,9 +1,9 @@ package com.baeldung.servlets.servlets; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; diff --git a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/javaee/AnnotationServlet.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/javaee/AnnotationServlet.java index 992976ca0e..62706be348 100644 --- a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/javaee/AnnotationServlet.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/javaee/AnnotationServlet.java @@ -1,10 +1,10 @@ package com.baeldung.servlets.servlets.javaee; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet(name = "AnnotationServlet", description = "Example Servlet Using Annotations", urlPatterns = { "/annotationservlet" }) diff --git a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/javaee/EEWebXmlServlet.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/javaee/EEWebXmlServlet.java index c7b373064f..299a1b5d95 100644 --- a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/javaee/EEWebXmlServlet.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/servlets/servlets/javaee/EEWebXmlServlet.java @@ -1,9 +1,9 @@ package com.baeldung.servlets.servlets.javaee; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; diff --git a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/utils/UtilsApplication.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/utils/UtilsApplication.java index ce3eae7ce0..eab5869cd5 100644 --- a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/utils/UtilsApplication.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/utils/UtilsApplication.java @@ -1,6 +1,6 @@ package com.baeldung.utils; -import javax.annotation.security.RolesAllowed; +import jakarta.annotation.security.RolesAllowed; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/utils/controller/UtilsController.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/utils/controller/UtilsController.java index 8c7f2f932a..40acc1801f 100644 --- a/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/utils/controller/UtilsController.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/utils/controller/UtilsController.java @@ -1,6 +1,6 @@ package com.baeldung.utils.controller; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; diff --git a/spring-boot-modules/spring-boot-mvc-4/src/test/java/com/baeldung/utils/UtilsControllerIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-4/src/test/java/com/baeldung/utils/UtilsControllerIntegrationTest.java index 080f660c40..f59d00f871 100644 --- a/spring-boot-modules/spring-boot-mvc-4/src/test/java/com/baeldung/utils/UtilsControllerIntegrationTest.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/test/java/com/baeldung/utils/UtilsControllerIntegrationTest.java @@ -1,32 +1,34 @@ package com.baeldung.utils; import com.baeldung.utils.controller.UtilsController; -import org.junit.Before; -import org.junit.Test; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; -import org.mockito.MockitoAnnotations; + import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import static org.mockito.MockitoAnnotations.openMocks; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -public class UtilsControllerIntegrationTest { +class UtilsControllerIntegrationTest { @InjectMocks private UtilsController utilsController; private MockMvc mockMvc; - @Before + @BeforeEach public void setup() { - MockitoAnnotations.initMocks(this); + openMocks(this); this.mockMvc = MockMvcBuilders.standaloneSetup(utilsController).build(); } @Test - public void givenParameter_setRequestParam_andSetSessionAttribute() throws Exception { + void givenParameter_setRequestParam_andSetSessionAttribute() throws Exception { String param = "testparam"; this.mockMvc.perform(post("/setParam").param("param", param).sessionAttr("parameter", param)).andExpect(status().isOk()); } From bcc3050383893834f448f0d369281d86a78bc6e9 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 5 Oct 2023 19:20:51 +0800 Subject: [PATCH 165/193] Update README.md [skip ci] --- testing-modules/junit-5-advanced/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/junit-5-advanced/README.md b/testing-modules/junit-5-advanced/README.md index a89bcd2de2..873ab0835b 100644 --- a/testing-modules/junit-5-advanced/README.md +++ b/testing-modules/junit-5-advanced/README.md @@ -9,3 +9,4 @@ - [JUnit – Testing Methods That Call System.exit()](https://www.baeldung.com/junit-system-exit) - [Single Assert Call for Multiple Properties in Java Unit Testing](https://www.baeldung.com/java-testing-single-assert-multiple-properties) - [Creating a Test Suite With JUnit](https://www.baeldung.com/java-junit-test-suite) +- [Testing Interface Contract in Java](https://www.baeldung.com/java-junit-verify-interface-contract) From 06f1bfb9df0b893d5baf5be8b8bab1cac098192c Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Thu, 5 Oct 2023 16:51:31 +0530 Subject: [PATCH 166/193] JAVA-25096 Upgrade parent-spring-6 to the latest version of Spring (#14854) --- parent-spring-6/pom.xml | 2 +- spring-6-rsocket/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/parent-spring-6/pom.xml b/parent-spring-6/pom.xml index 7b61ac524b..7b28afc9b1 100644 --- a/parent-spring-6/pom.xml +++ b/parent-spring-6/pom.xml @@ -35,7 +35,7 @@ - 6.0.10 + 6.0.12 diff --git a/spring-6-rsocket/README.md b/spring-6-rsocket/README.md index 21ab282bd1..2a8a197670 100644 --- a/spring-6-rsocket/README.md +++ b/spring-6-rsocket/README.md @@ -4,4 +4,4 @@ This module contains articles about RSocket in Spring Framework 6. ### Relevant articles -- [Introduction to RSocket](#) \ No newline at end of file +- [Introduction to RSocket](https://www.baeldung.com/spring-rsocket) From 11cea0a95623fae168a78a2f45efc24991e0f564 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 5 Oct 2023 19:26:10 +0800 Subject: [PATCH 167/193] Update README.md [skip ci] --- core-java-modules/core-java-21/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-21/README.md b/core-java-modules/core-java-21/README.md index 2c51db275a..b2e6aa6442 100644 --- a/core-java-modules/core-java-21/README.md +++ b/core-java-modules/core-java-21/README.md @@ -1,3 +1,4 @@ ## Relevant Articles - [Sequenced Collections in Java 21](https://www.baeldung.com/java-21-sequenced-collections) - [String Templates in Java 21](https://www.baeldung.com/java-21-string-templates) +- [Unnamed Classes and Instance Main Methods in Java 21](https://www.baeldung.com/java-21-unnamed-class-instance-main) From fb0ff7be4935c743000688ae5fd1ed4655986b52 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 5 Oct 2023 19:29:36 +0800 Subject: [PATCH 168/193] Create README.md [skip ci] --- spring-boot-modules/spring-boot-graalvm-docker/README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 spring-boot-modules/spring-boot-graalvm-docker/README.md diff --git a/spring-boot-modules/spring-boot-graalvm-docker/README.md b/spring-boot-modules/spring-boot-graalvm-docker/README.md new file mode 100644 index 0000000000..10a764053e --- /dev/null +++ b/spring-boot-modules/spring-boot-graalvm-docker/README.md @@ -0,0 +1,2 @@ +## Relevant Articles +- [Create a GraalVM Docker Image](https://www.baeldung.com/java-graalvm-docker-image) From 4151a02bb68b1937db57152e57fc80e1ccc4a6f7 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 5 Oct 2023 19:34:57 +0800 Subject: [PATCH 169/193] Update README.md [skip ci] --- core-java-modules/core-java-21/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-21/README.md b/core-java-modules/core-java-21/README.md index b2e6aa6442..ffb999a4ba 100644 --- a/core-java-modules/core-java-21/README.md +++ b/core-java-modules/core-java-21/README.md @@ -2,3 +2,4 @@ - [Sequenced Collections in Java 21](https://www.baeldung.com/java-21-sequenced-collections) - [String Templates in Java 21](https://www.baeldung.com/java-21-string-templates) - [Unnamed Classes and Instance Main Methods in Java 21](https://www.baeldung.com/java-21-unnamed-class-instance-main) +- [Unnamed Patterns and Variables in Java 21](https://www.baeldung.com/java-unnamed-patterns-variables) From cb0bccfbd419a74e9735617ab94ec674f9909b70 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 5 Oct 2023 21:39:55 +0800 Subject: [PATCH 170/193] Update README.md [skip ci] --- core-java-modules/core-java-regex-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-regex-2/README.md b/core-java-modules/core-java-regex-2/README.md index 02e470cce5..404b33b65f 100644 --- a/core-java-modules/core-java-regex-2/README.md +++ b/core-java-modules/core-java-regex-2/README.md @@ -9,4 +9,5 @@ - [Regular Expression: \z vs \Z Anchors in Java](https://www.baeldung.com/java-regular-expression-z-vs-z-anchors) - [Extract Text Between Square Brackets](https://www.baeldung.com/java-get-content-between-square-brackets) - [Get the Indexes of Regex Pattern Matches in Java](https://www.baeldung.com/java-indexes-regex-pattern-matches) +- [Check if a String is Strictly Alphanumeric With Java](https://www.baeldung.com/java-check-string-contains-only-letters-numbers) - More articles: [[<-- prev]](/core-java-modules/core-java-regex) From a9e906aa69fc00c7200b9d10df5363bfb68aa298 Mon Sep 17 00:00:00 2001 From: edizor <113095366+edizor@users.noreply.github.com> Date: Thu, 5 Oct 2023 21:43:16 +0800 Subject: [PATCH 171/193] Update README.md [skip ci] --- core-java-modules/core-java-collections-array-list-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-collections-array-list-2/README.md b/core-java-modules/core-java-collections-array-list-2/README.md index dbf5c47edb..575e0dbb07 100644 --- a/core-java-modules/core-java-collections-array-list-2/README.md +++ b/core-java-modules/core-java-collections-array-list-2/README.md @@ -3,4 +3,4 @@ This module contains articles about the Java ArrayList collection ### Relevant Articles: -- [Create an ArrayList with Multiple Object Types](https://www.baeldung.com/arraylist-with-multiple-object-types) +- [Create an ArrayList with Multiple Object Types](https://www.baeldung.com/java-arraylist-multiple-object-types) From 68fd94288d141c87381ca9deeca3284dfd54cce9 Mon Sep 17 00:00:00 2001 From: mcasari Date: Fri, 6 Oct 2023 21:57:56 +0200 Subject: [PATCH 172/193] change string constructor test case in simpler form --- .../baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java index 9d125f557d..f783d00976 100644 --- a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java +++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floattobigdecimal/FloatToBigDecimalUnitTest.java @@ -24,8 +24,8 @@ class FloatToBigDecimalUnitTest { @Test public void whenCreatedFromString_thenPreservesTheOriginal() { - BigDecimal bdFromString = new BigDecimal("1.10000002384185791015625"); - assertEquals("1.10000002384185791015625", bdFromString.toString()); + BigDecimal bdFromString = new BigDecimal("1.1"); + assertEquals("1.1", bdFromString.toString()); } @Test From 5dcd7e88d0e13e86789120053206f9586d37daf6 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 6 Oct 2023 20:00:28 -0400 Subject: [PATCH 173/193] implementing BAEL-6833 (#14912) Co-authored-by: technoddy --- libraries-io/pom.xml | 21 +++++ .../java/io/pojotocsv/Application.java | 4 + .../pojotocsv/ApplicationWithAnnotation.java | 8 ++ .../baeldung/java/io/pojotocsv/BeanToCsv.java | 55 +++++++++++++ .../CustomColumnPositionStrategy.java | 12 +++ .../io/pojotocsv/CustomHeaderStrategy.java | 16 ++++ .../src/main/resources/application.csv | 4 + .../src/main/resources/application2.csv | 4 + .../src/main/resources/application3.csv | 3 + .../src/main/resources/application4.csv | 4 + .../java/io/pojotocsv/BeanToCsvUnitTest.java | 80 +++++++++++++++++++ 11 files changed, 211 insertions(+) create mode 100644 libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/Application.java create mode 100644 libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/ApplicationWithAnnotation.java create mode 100644 libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/BeanToCsv.java create mode 100644 libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/CustomColumnPositionStrategy.java create mode 100644 libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/CustomHeaderStrategy.java create mode 100644 libraries-io/src/main/resources/application.csv create mode 100644 libraries-io/src/main/resources/application2.csv create mode 100644 libraries-io/src/main/resources/application3.csv create mode 100644 libraries-io/src/main/resources/application4.csv create mode 100644 libraries-io/src/test/java/com/baeldung/java/io/pojotocsv/BeanToCsvUnitTest.java diff --git a/libraries-io/pom.xml b/libraries-io/pom.xml index e92f6e11e1..fa89ebeabe 100644 --- a/libraries-io/pom.xml +++ b/libraries-io/pom.xml @@ -5,6 +5,18 @@ 4.0.0 libraries-io libraries-io + + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + + + + com.baeldung @@ -34,6 +46,11 @@ zip4j ${zip4j.version} + + com.opencsv + opencsv + ${opencsv.version} + @@ -42,6 +59,10 @@ 0.27.0 2.4 2.9.0 + 5.7.1 + 17 + 17 + UTF-8 \ No newline at end of file diff --git a/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/Application.java b/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/Application.java new file mode 100644 index 0000000000..b84da6229b --- /dev/null +++ b/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/Application.java @@ -0,0 +1,4 @@ +package com.baeldung.java.io.pojotocsv; + +public record Application(String id, String name, Integer age, String created_at) { +} diff --git a/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/ApplicationWithAnnotation.java b/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/ApplicationWithAnnotation.java new file mode 100644 index 0000000000..a0cd158843 --- /dev/null +++ b/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/ApplicationWithAnnotation.java @@ -0,0 +1,8 @@ +package com.baeldung.java.io.pojotocsv; + +import com.opencsv.bean.CsvBindByName; +import com.opencsv.bean.CsvBindByPosition; + +public record ApplicationWithAnnotation(@CsvBindByName(column = "id", required = true) @CsvBindByPosition(position = 1) String id, @CsvBindByName(column = "name", required = true) @CsvBindByPosition(position = 0) String name, + @CsvBindByName(column = "age", required = true) @CsvBindByPosition(position = 2) Integer age, @CsvBindByName(column = "position", required = true) @CsvBindByPosition(position = 3) String created_at) { +} \ No newline at end of file diff --git a/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/BeanToCsv.java b/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/BeanToCsv.java new file mode 100644 index 0000000000..f66c16beda --- /dev/null +++ b/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/BeanToCsv.java @@ -0,0 +1,55 @@ +package com.baeldung.java.io.pojotocsv; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; + +import com.opencsv.CSVWriter; +import com.opencsv.bean.StatefulBeanToCsvBuilder; +import com.opencsv.exceptions.CsvDataTypeMismatchException; +import com.opencsv.exceptions.CsvRequiredFieldEmptyException; + +public class BeanToCsv { + + public void beanToCSVWithDefault(List applications) throws Exception { + try (FileWriter writer = new FileWriter("src/main/resources/application.csv")) { + var builder = new StatefulBeanToCsvBuilder(writer).withQuotechar(CSVWriter.NO_QUOTE_CHARACTER) + .withSeparator(',') + .build(); + builder.write(applications); + } + } + + public void beanToCSVWithCustomHeaderStrategy(List applications) throws IOException, CsvRequiredFieldEmptyException, CsvDataTypeMismatchException { + try (FileWriter writer = new FileWriter("src/main/resources/application2.csv")) { + var mappingStrategy = new CustomHeaderStrategy(); + mappingStrategy.setType(Application.class); + + var builder = new StatefulBeanToCsvBuilder(writer).withQuotechar(CSVWriter.NO_QUOTE_CHARACTER) + .withMappingStrategy(mappingStrategy) + .build(); + builder.write(applications); + } + } + + public void beanToCSVWithCustomPositionStrategy(List applications) throws Exception { + try (FileWriter writer = new FileWriter("src/main/resources/application3.csv")) { + var builder = new StatefulBeanToCsvBuilder(writer).withQuotechar(CSVWriter.NO_QUOTE_CHARACTER) + .build(); + builder.write(applications); + } + } + + public void beanToCSVWithCustomHeaderAndPositionStrategy(List applications) throws IOException, CsvRequiredFieldEmptyException, CsvDataTypeMismatchException { + try (FileWriter writer = new FileWriter("src/main/resources/application4.csv")) { + var mappingStrategy = new CustomColumnPositionStrategy(); + mappingStrategy.setType(ApplicationWithAnnotation.class); + + var builder = new StatefulBeanToCsvBuilder(writer).withQuotechar(CSVWriter.NO_QUOTE_CHARACTER) + .withMappingStrategy(mappingStrategy) + .build(); + builder.write(applications); + } + } + +} diff --git a/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/CustomColumnPositionStrategy.java b/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/CustomColumnPositionStrategy.java new file mode 100644 index 0000000000..204bf3f917 --- /dev/null +++ b/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/CustomColumnPositionStrategy.java @@ -0,0 +1,12 @@ +package com.baeldung.java.io.pojotocsv; + +import com.opencsv.bean.ColumnPositionMappingStrategy; +import com.opencsv.exceptions.CsvRequiredFieldEmptyException; + +public class CustomColumnPositionStrategy extends ColumnPositionMappingStrategy { + @Override + public String[] generateHeader(T bean) throws CsvRequiredFieldEmptyException { + super.generateHeader(bean); + return super.getColumnMapping(); + } +} diff --git a/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/CustomHeaderStrategy.java b/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/CustomHeaderStrategy.java new file mode 100644 index 0000000000..8e81c8ec28 --- /dev/null +++ b/libraries-io/src/main/java/com/baeldung/java/io/pojotocsv/CustomHeaderStrategy.java @@ -0,0 +1,16 @@ +package com.baeldung.java.io.pojotocsv; + +import java.util.Arrays; + +import com.opencsv.bean.HeaderColumnNameMappingStrategy; +import com.opencsv.exceptions.CsvRequiredFieldEmptyException; + +public class CustomHeaderStrategy extends HeaderColumnNameMappingStrategy { + @Override + public String[] generateHeader(T bean) throws CsvRequiredFieldEmptyException { + String[] header = super.generateHeader(bean); + return Arrays.stream(header) + .map(String::toLowerCase) + .toArray(String[]::new); + } +} diff --git a/libraries-io/src/main/resources/application.csv b/libraries-io/src/main/resources/application.csv new file mode 100644 index 0000000000..d4040e18e1 --- /dev/null +++ b/libraries-io/src/main/resources/application.csv @@ -0,0 +1,4 @@ +AGE,CREATED_AT,ID,NAME +34,2023-08-11,123,Sam +44,2023-02-11,456,Tam +54,2023-03-11,890,Jam diff --git a/libraries-io/src/main/resources/application2.csv b/libraries-io/src/main/resources/application2.csv new file mode 100644 index 0000000000..92bbced703 --- /dev/null +++ b/libraries-io/src/main/resources/application2.csv @@ -0,0 +1,4 @@ +age,created_at,id,name +34,2023-08-11,123,Sam +44,2023-02-11,456,Tam +54,2023-03-11,890,Jam diff --git a/libraries-io/src/main/resources/application3.csv b/libraries-io/src/main/resources/application3.csv new file mode 100644 index 0000000000..165107b103 --- /dev/null +++ b/libraries-io/src/main/resources/application3.csv @@ -0,0 +1,3 @@ +Sam,123,34,2023-08-11 +Tam,456,44,2023-02-11 +Jam,789,54,2023-03-11 diff --git a/libraries-io/src/main/resources/application4.csv b/libraries-io/src/main/resources/application4.csv new file mode 100644 index 0000000000..b7999ae227 --- /dev/null +++ b/libraries-io/src/main/resources/application4.csv @@ -0,0 +1,4 @@ +name,id,age,created_at +Sam,123,34,2023-08-11 +Tam,456,44,2023-02-11 +Jam,789,54,2023-03-11 diff --git a/libraries-io/src/test/java/com/baeldung/java/io/pojotocsv/BeanToCsvUnitTest.java b/libraries-io/src/test/java/com/baeldung/java/io/pojotocsv/BeanToCsvUnitTest.java new file mode 100644 index 0000000000..50cd1b1e0e --- /dev/null +++ b/libraries-io/src/test/java/com/baeldung/java/io/pojotocsv/BeanToCsvUnitTest.java @@ -0,0 +1,80 @@ +package com.baeldung.java.io.pojotocsv; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import java.io.BufferedReader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class BeanToCsvUnitTest { + + List applications = new ArrayList<>(); + List applicationsWithAnnotation = new ArrayList<>(); + + @BeforeEach + public void beforeEach() { + applications = List.of(new Application("123", "Sam", 34, "2023-08-11"), new Application("456", "Tam", 44, "2023-02-11"), new Application("890", "Jam", 54, "2023-03-11")); + + applicationsWithAnnotation = List.of(new ApplicationWithAnnotation("123", "Sam", 34, "2023-08-11"), new ApplicationWithAnnotation("456", "Tam", 44, "2023-02-11"), new ApplicationWithAnnotation("789", "Jam", 54, "2023-03-11")); + } + + @Test + public void givenApplicationPOJO_whenUsingDefaultStrategy_thenReceiveCSVFormatWithAscendingOrderOfField() throws Exception { + BeanToCsv beanToCsv = new BeanToCsv(); + beanToCsv.beanToCSVWithDefault(applications); + try (BufferedReader bufferedReader = Files.newBufferedReader(Path.of("src/main/resources/application.csv"))) { + List content = bufferedReader.lines() + .toList(); + assertThat(content.get(0)).isEqualTo("AGE,CREATED_AT,ID,NAME"); + assertThat(content.get(1)).isEqualTo("34,2023-08-11,123,Sam"); + assertThat(content.get(2)).isEqualTo("44,2023-02-11,456,Tam"); + assertThat(content.get(3)).isEqualTo("54,2023-03-11,890,Jam"); + } + } + + @Test + public void givenApplicationPOJO_whenUsingCustomHeaderStrategy_thenReceiveCSVFormatWithCustomHeaders() throws Exception { + BeanToCsv beanToCsv = new BeanToCsv(); + beanToCsv.beanToCSVWithCustomHeaderStrategy(applications); + try (BufferedReader bufferedReader = Files.newBufferedReader(Path.of("src/main/resources/application2.csv"))) { + List content = bufferedReader.lines() + .toList(); + assertThat(content.get(0)).isEqualTo("age,created_at,id,name"); + assertThat(content.get(1)).isEqualTo("34,2023-08-11,123,Sam"); + assertThat(content.get(2)).isEqualTo("44,2023-02-11,456,Tam"); + assertThat(content.get(3)).isEqualTo("54,2023-03-11,890,Jam"); + } + } + + @Test + public void givenApplicationPOJOWithAnnotation_whenUsingCustomPositionStrategy_thenReceiveCSVFormatWithCustomPosition() throws Exception { + BeanToCsv beanToCsv = new BeanToCsv(); + beanToCsv.beanToCSVWithCustomPositionStrategy(applicationsWithAnnotation); + try (BufferedReader bufferedReader = Files.newBufferedReader(Path.of("src/main/resources/application3.csv"))) { + List content = bufferedReader.lines() + .toList(); + assertThat(content.get(0)).isEqualTo("Sam,123,34,2023-08-11"); + assertThat(content.get(1)).isEqualTo("Tam,456,44,2023-02-11"); + assertThat(content.get(2)).isEqualTo("Jam,789,54,2023-03-11"); + } + } + + @Test + public void givenApplicationPOJOWithAnnotation_whenUsingCustomHeaderPositionStrategy_thenReceiveCSVFormatWithCustomHeaderPosition() throws Exception { + BeanToCsv beanToCsv = new BeanToCsv(); + beanToCsv.beanToCSVWithCustomHeaderAndPositionStrategy(applicationsWithAnnotation); + try (BufferedReader bufferedReader = Files.newBufferedReader(Path.of("src/main/resources/application4.csv"))) { + List content = bufferedReader.lines() + .toList(); + assertThat(content.get(0)).isEqualTo("name,id,age,created_at"); + assertThat(content.get(1)).isEqualTo("Sam,123,34,2023-08-11"); + assertThat(content.get(2)).isEqualTo("Tam,456,44,2023-02-11"); + assertThat(content.get(3)).isEqualTo("Jam,789,54,2023-03-11"); + } + } +} From 5aea5d5c296ed1471436de74fb57a603ab98dd44 Mon Sep 17 00:00:00 2001 From: etrandafir93 <75391049+etrandafir93@users.noreply.github.com> Date: Sat, 7 Oct 2023 06:11:47 +0200 Subject: [PATCH 174/193] BAEL-6782: partitioning streams (#14833) * BAEL-6782: partitioning streams * BAEL-6782: code reivew * BAEL-6782: line continuations --- core-java-modules/core-java-streams-5/pom.xml | 6 ++ .../streams/partitioning/PartitionStream.java | 90 +++++++++++++++++++ .../PartitionStreamsUnitTest.java | 82 +++++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 core-java-modules/core-java-streams-5/src/main/java/com/baeldung/streams/partitioning/PartitionStream.java create mode 100644 core-java-modules/core-java-streams-5/src/test/java/com/baeldung/partitioning/PartitionStreamsUnitTest.java diff --git a/core-java-modules/core-java-streams-5/pom.xml b/core-java-modules/core-java-streams-5/pom.xml index dc97d81b3d..d7baf84d30 100644 --- a/core-java-modules/core-java-streams-5/pom.xml +++ b/core-java-modules/core-java-streams-5/pom.xml @@ -43,6 +43,11 @@ vavr ${vavr.version} + + com.google.guava + guava + ${guava.version} + @@ -72,6 +77,7 @@ 12 12 0.10.2 + 32.1.2-jre \ No newline at end of file diff --git a/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/streams/partitioning/PartitionStream.java b/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/streams/partitioning/PartitionStream.java new file mode 100644 index 0000000000..1ef3fa7707 --- /dev/null +++ b/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/streams/partitioning/PartitionStream.java @@ -0,0 +1,90 @@ +package com.baeldung.streams.partitioning; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.BiConsumer; +import java.util.function.BinaryOperator; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collector; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import com.google.common.collect.Iterables; + +public class PartitionStream { + + public static Stream> partitionList(List source, int batchSize) { + if (batchSize <= 0) { + throw new IllegalArgumentException(String.format("Expected the batchSize to be greater than ZERO, actual value was: %s", batchSize)); + } + if (source.isEmpty()) { + return Stream.empty(); + } + int nrOfFullBatches = (source.size() - 1) / batchSize; + return IntStream.rangeClosed(0, nrOfFullBatches) + .mapToObj(batch -> { + int startIndex = batch * batchSize; + int endIndex = (batch == nrOfFullBatches) ? source.size() : (batch + 1) * batchSize; + return source.subList(startIndex, endIndex); + }); + } + + public static Iterable> partitionUsingGuava(Stream source, int batchSize) { + return Iterables.partition(source::iterator, batchSize); + } + + public static List> partitionStream(Stream source, int batchSize) { + return source.collect(partitionBySize(batchSize, Collectors.toList())); + } + + public static Collector partitionBySize(int batchSize, Collector, A, R> downstream) { + Supplier> supplier = () -> new Accumulator<>( + batchSize, + downstream.supplier().get(), + downstream.accumulator()::accept + ); + + BiConsumer, T> accumulator = (acc, value) -> acc.add(value); + + BinaryOperator> combiner = (acc1, acc2) -> acc1.combine(acc2, downstream.combiner()); + + Function, R> finisher = acc -> { + if (!acc.values.isEmpty()) { + downstream.accumulator().accept(acc.downstreamAccumulator, acc.values); + } + return downstream.finisher().apply(acc.downstreamAccumulator); + }; + + return Collector.of(supplier, accumulator, combiner, finisher, Collector.Characteristics.UNORDERED); + } + + static class Accumulator { + private final List values = new ArrayList<>(); + private final int batchSize; + private A downstreamAccumulator; + private final BiConsumer> batchFullListener; + + Accumulator(int batchSize, A accumulator, BiConsumer> onBatchFull) { + this.batchSize = batchSize; + this.downstreamAccumulator = accumulator; + this.batchFullListener = onBatchFull; + } + + void add(T value) { + values.add(value); + if (values.size() == batchSize) { + batchFullListener.accept(downstreamAccumulator, new ArrayList<>(values)); + values.clear(); + } + } + + Accumulator combine(Accumulator other, BinaryOperator accumulatorCombiner) { + this.downstreamAccumulator = accumulatorCombiner.apply(downstreamAccumulator, other.downstreamAccumulator); + other.values.forEach(this::add); + return this; + } + } + +} diff --git a/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/partitioning/PartitionStreamsUnitTest.java b/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/partitioning/PartitionStreamsUnitTest.java new file mode 100644 index 0000000000..df75e69783 --- /dev/null +++ b/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/partitioning/PartitionStreamsUnitTest.java @@ -0,0 +1,82 @@ +package com.baeldung.partitioning; + +import static com.baeldung.streams.partitioning.PartitionStream.partitionList; +import static com.baeldung.streams.partitioning.PartitionStream.partitionStream; +import static com.baeldung.streams.partitioning.PartitionStream.partitionUsingGuava; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.atIndex; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.api.Test; + +public class PartitionStreamsUnitTest { + + @Test + void whenPartitionList_thenReturnThreeSubLists() { + List source = List.of(1, 2, 3, 4, 5, 6, 7, 8); + + Stream> result = partitionList(source, 3); + + assertThat(result) + .containsExactlyInAnyOrder( + List.of(1, 2, 3), + List.of(4, 5, 6), + List.of(7, 8) + ); + } + + @Test + void whenPartitionEmptyList_thenReturnEmptyStream() { + Stream> result = partitionList(Collections.emptyList(), 3); + + assertThat(result).isEmpty(); + } + + @Test + void whenPartitionListWithNegativeBatchSize_thenThrowException() { + assertThatThrownBy(() -> partitionList(List.of(1,2,3), -1)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Expected the batchSize to be greater than ZERO, actual value was: -1"); + } + + @Test + void whenPartitionParallelStream_thenReturnThreeSubLists() { + Stream source = Stream.of(1, 2, 3, 4, 5, 6, 7, 8).parallel(); + + List> result = partitionStream(source, 3); + + assertThat(result) + .hasSize(3) + .satisfies(batch -> assertThat(batch).hasSize(3), atIndex(0)) + .satisfies(batch -> assertThat(batch).hasSize(3), atIndex(1)) + .satisfies(batch -> assertThat(batch).hasSize(2), atIndex(2)); + } + + @Test + void whenPartitionEmptyParallelStream_thenReturnEmptyList() { + Stream source = Stream.empty().parallel(); + + List> result = partitionStream(source, 3); + + assertThat(result).isEmpty(); + } + + @Test + void whenPartitionParallelStreamWithGuava_thenReturnThreeSubLists() { + Stream source = Stream.of(1, 2, 3, 4, 5, 6, 7, 8).parallel(); + + Iterable> result = partitionUsingGuava(source, 3); + + assertThat(result) + .map(ArrayList::new) + .hasSize(3) + .satisfies(batch -> assertThat(batch).asList().hasSize(3), atIndex(0)) + .satisfies(batch -> assertThat(batch).asList().hasSize(3), atIndex(1)) + .satisfies(batch -> assertThat(batch).asList().hasSize(2), atIndex(2)); + } +} From ed2f3234e6574f814adb24323ae3bedc6b1b29d7 Mon Sep 17 00:00:00 2001 From: Constantin <50400363+constantinurs@users.noreply.github.com> Date: Sat, 7 Oct 2023 07:21:30 +0300 Subject: [PATCH 175/193] BAEL-6612: How to subscribe a Kafka consumer to multiple topics (#14800) * BAEL-6612: Subscribe consumer to multiple topics using Spring Kafka * BAEL-6612: Subscribe consumer to multiple topics using Apache Kafka * BAEL-6612: Revert README files * BAEL-6612: Fix identation; remove static qualifier * BAEL-6612: Fix identation; remove static qualifier --- .../MultipleTopicsLiveTest.java | 103 ++++++++++++++++++ .../multipletopics/KafkaConsumerConfig.java | 36 ++++++ .../KafkaMultipleTopicsApplication.java | 13 +++ .../multipletopics/KafkaProducerConfig.java | 34 ++++++ .../kafka/multipletopics/PaymentData.java | 54 +++++++++ .../multipletopics/PaymentDataListener.java | 18 +++ .../KafkaMultipleTopicsIntegrationTest.java | 78 +++++++++++++ 7 files changed, 336 insertions(+) create mode 100644 apache-kafka-2/src/test/java/com/baeldung/kafka/multipletopics/MultipleTopicsLiveTest.java create mode 100644 spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/KafkaConsumerConfig.java create mode 100644 spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/KafkaMultipleTopicsApplication.java create mode 100644 spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/KafkaProducerConfig.java create mode 100644 spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/PaymentData.java create mode 100644 spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/PaymentDataListener.java create mode 100644 spring-kafka-2/src/test/java/com/baeldung/spring/kafka/multipletopics/KafkaMultipleTopicsIntegrationTest.java diff --git a/apache-kafka-2/src/test/java/com/baeldung/kafka/multipletopics/MultipleTopicsLiveTest.java b/apache-kafka-2/src/test/java/com/baeldung/kafka/multipletopics/MultipleTopicsLiveTest.java new file mode 100644 index 0000000000..653456a678 --- /dev/null +++ b/apache-kafka-2/src/test/java/com/baeldung/kafka/multipletopics/MultipleTopicsLiveTest.java @@ -0,0 +1,103 @@ +package com.baeldung.kafka.multipletopics; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; +import java.util.Arrays; +import java.util.Properties; +import java.util.concurrent.ExecutionException; + +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.apache.kafka.clients.producer.KafkaProducer; +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.apache.kafka.common.serialization.StringDeserializer; +import org.apache.kafka.common.serialization.StringSerializer; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.KafkaContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; + +// This live test needs a Docker Daemon running so that a kafka container can be created + +@Testcontainers +public class MultipleTopicsLiveTest { + + private final Logger log = LoggerFactory.getLogger(MultipleTopicsLiveTest.class); + + private static final String CARD_PAYMENTS_TOPIC = "card-payments"; + private static final String BANK_TRANSFERS_TOPIC = "bank-transfers"; + private static KafkaProducer producer; + private static KafkaConsumer consumer; + + @Container + private static final KafkaContainer KAFKA_CONTAINER = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:latest")); + + @BeforeAll + static void setup() { + KAFKA_CONTAINER.addExposedPort(9092); + producer = new KafkaProducer<>(getProducerProperties()); + consumer = new KafkaConsumer<>(getConsumerProperties()); + } + + @AfterAll + static void destroy() { + KAFKA_CONTAINER.stop(); + } + + private static Properties getProducerProperties() { + Properties producerProperties = new Properties(); + producerProperties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, KAFKA_CONTAINER.getBootstrapServers()); + producerProperties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); + producerProperties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); + return producerProperties; + } + + private static Properties getConsumerProperties() { + Properties consumerProperties = new Properties(); + consumerProperties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, KAFKA_CONTAINER.getBootstrapServers()); + consumerProperties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); + consumerProperties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); + consumerProperties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); + consumerProperties.put(ConsumerConfig.GROUP_ID_CONFIG, "payments"); + return consumerProperties; + } + + @Test + void whenSendingMessagesOnTwoTopics_thenConsumerReceivesMessages() throws Exception { + publishMessages(); + + consumer.subscribe(Arrays.asList(CARD_PAYMENTS_TOPIC, BANK_TRANSFERS_TOPIC)); + + int eventsProcessed = 0; + for (ConsumerRecord record : consumer.poll(Duration.ofSeconds(10))) { + log.info("Event on topic={}, payload={}", record.topic(), record.value()); + eventsProcessed++; + } + + assertThat(eventsProcessed).isEqualTo(2); + } + + private void publishMessages() throws ExecutionException, InterruptedException { + ProducerRecord cardPayment = new ProducerRecord<>(CARD_PAYMENTS_TOPIC, createCardPayment()); + producer.send(cardPayment).get(); + + ProducerRecord bankTransfer = new ProducerRecord<>(BANK_TRANSFERS_TOPIC, createBankTransfer()); + producer.send(bankTransfer).get(); + } + + private String createCardPayment() { + return "{\"paymentReference\":\"A184028KM0013790\", \"type\":\"card\", \"amount\":\"275\", \"currency\":\"GBP\"}"; + } + + private String createBankTransfer() { + return "{\"paymentReference\":\"19ae2-18mk73-009\", \"type\":\"bank\", \"amount\":\"150\", \"currency\":\"EUR\"}"; + } +} diff --git a/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/KafkaConsumerConfig.java b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/KafkaConsumerConfig.java new file mode 100644 index 0000000000..741fb6bba4 --- /dev/null +++ b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/KafkaConsumerConfig.java @@ -0,0 +1,36 @@ +package com.baeldung.spring.kafka.multipletopics; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.common.serialization.StringDeserializer; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; +import org.springframework.kafka.core.ConsumerFactory; +import org.springframework.kafka.core.DefaultKafkaConsumerFactory; +import org.springframework.kafka.support.serializer.JsonDeserializer; + +@Configuration +public class KafkaConsumerConfig { + + @Value(value = "${spring.kafka.bootstrap-servers}") + private String bootstrapServers; + + @Bean + public ConsumerFactory consumerFactory() { + Map config = new HashMap<>(); + config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); + + return new DefaultKafkaConsumerFactory<>(config, new StringDeserializer(), new JsonDeserializer<>(PaymentData.class)); + } + + @Bean + public ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory() { + ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>(); + factory.setConsumerFactory(consumerFactory()); + return factory; + } +} \ No newline at end of file diff --git a/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/KafkaMultipleTopicsApplication.java b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/KafkaMultipleTopicsApplication.java new file mode 100644 index 0000000000..2135a27f39 --- /dev/null +++ b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/KafkaMultipleTopicsApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.spring.kafka.multipletopics; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.kafka.annotation.EnableKafka; + +@EnableKafka +@SpringBootApplication +public class KafkaMultipleTopicsApplication { + public static void main(String[] args) { + SpringApplication.run(KafkaMultipleTopicsApplication.class, args); + } +} \ No newline at end of file diff --git a/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/KafkaProducerConfig.java b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/KafkaProducerConfig.java new file mode 100644 index 0000000000..2cb0117bf1 --- /dev/null +++ b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/KafkaProducerConfig.java @@ -0,0 +1,34 @@ +package com.baeldung.spring.kafka.multipletopics; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.kafka.common.serialization.StringSerializer; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.kafka.core.DefaultKafkaProducerFactory; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.core.ProducerFactory; +import org.springframework.kafka.support.serializer.JsonSerializer; + +@Configuration +public class KafkaProducerConfig { + + @Value(value = "${spring.kafka.bootstrap-servers}") + private String bootstrapServers; + + @Bean + public ProducerFactory producerFactory() { + Map config = new HashMap<>(); + config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); + + return new DefaultKafkaProducerFactory<>(config, new StringSerializer(), new JsonSerializer<>()); + } + + @Bean + public KafkaTemplate kafkaProducer() { + return new KafkaTemplate<>(producerFactory()); + } +} \ No newline at end of file diff --git a/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/PaymentData.java b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/PaymentData.java new file mode 100644 index 0000000000..e81138c089 --- /dev/null +++ b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/PaymentData.java @@ -0,0 +1,54 @@ +package com.baeldung.spring.kafka.multipletopics; + +import java.math.BigDecimal; +import java.util.Currency; +import java.util.StringJoiner; + +public class PaymentData { + private String paymentReference; + private String type; + private BigDecimal amount; + private Currency currency; + + public String getPaymentReference() { + return paymentReference; + } + + public void setPaymentReference(String paymentReference) { + this.paymentReference = paymentReference; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public BigDecimal getAmount() { + return amount; + } + + public void setAmount(BigDecimal amount) { + this.amount = amount; + } + + public Currency getCurrency() { + return currency; + } + + public void setCurrency(Currency currency) { + this.currency = currency; + } + + @Override + public String toString() { + return new StringJoiner(", ", PaymentData.class.getSimpleName() + "[", "]") + .add("paymentReference='" + paymentReference + "'") + .add("type='" + type + "'") + .add("amount=" + amount) + .add("currency=" + currency) + .toString(); + } +} \ No newline at end of file diff --git a/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/PaymentDataListener.java b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/PaymentDataListener.java new file mode 100644 index 0000000000..fb640cca25 --- /dev/null +++ b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/multipletopics/PaymentDataListener.java @@ -0,0 +1,18 @@ +package com.baeldung.spring.kafka.multipletopics; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.kafka.support.KafkaHeaders; +import org.springframework.messaging.handler.annotation.Header; +import org.springframework.stereotype.Service; + +@Service +public class PaymentDataListener { + private final Logger log = LoggerFactory.getLogger(PaymentDataListener.class); + + @KafkaListener(topics = { "card-payments", "bank-transfers" }, groupId = "payments") + public void handlePaymentEvents(PaymentData paymentData, @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) { + log.info("Event on topic={}, payload={}", topic, paymentData); + } +} \ No newline at end of file diff --git a/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/multipletopics/KafkaMultipleTopicsIntegrationTest.java b/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/multipletopics/KafkaMultipleTopicsIntegrationTest.java new file mode 100644 index 0000000000..345e84b65b --- /dev/null +++ b/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/multipletopics/KafkaMultipleTopicsIntegrationTest.java @@ -0,0 +1,78 @@ +package com.baeldung.spring.kafka.multipletopics; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doAnswer; + +import java.math.BigDecimal; +import java.util.Currency; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.kafka.config.KafkaListenerEndpointRegistry; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.listener.MessageListenerContainer; +import org.springframework.kafka.test.context.EmbeddedKafka; +import org.springframework.kafka.test.utils.ContainerTestUtils; + +@SpringBootTest(classes = KafkaMultipleTopicsApplication.class) +@EmbeddedKafka(partitions = 1, brokerProperties = { "listeners=PLAINTEXT://localhost:9092", "port=9092" }) +public class KafkaMultipleTopicsIntegrationTest { + private static final String CARD_PAYMENTS_TOPIC = "card-payments"; + private static final String BANK_TRANSFERS_TOPIC = "bank-transfers"; + + @Autowired + private KafkaListenerEndpointRegistry kafkaListenerEndpointRegistry; + + @Autowired + private KafkaTemplate kafkaProducer; + + @SpyBean + private PaymentDataListener paymentsConsumer; + + @BeforeEach + void setUp() { + // wait for embedded Kafka + for (MessageListenerContainer messageListenerContainer : kafkaListenerEndpointRegistry.getListenerContainers()) { + ContainerTestUtils.waitForAssignment(messageListenerContainer, 2); + } + } + + @Test + public void whenSendingMessagesOnTwoTopics_thenConsumerReceivesMessages() throws Exception { + CountDownLatch countDownLatch = new CountDownLatch(2); + doAnswer(invocation -> { + countDownLatch.countDown(); + return null; + }).when(paymentsConsumer) + .handlePaymentEvents(any(), any()); + + kafkaProducer.send(CARD_PAYMENTS_TOPIC, createCardPayment()); + kafkaProducer.send(BANK_TRANSFERS_TOPIC, createBankTransfer()); + + assertThat(countDownLatch.await(5, TimeUnit.SECONDS)).isTrue(); + } + + private PaymentData createCardPayment() { + PaymentData cardPayment = new PaymentData(); + cardPayment.setAmount(BigDecimal.valueOf(275)); + cardPayment.setPaymentReference("A184028KM0013790"); + cardPayment.setCurrency(Currency.getInstance("GBP")); + cardPayment.setType("card"); + return cardPayment; + } + + private PaymentData createBankTransfer() { + PaymentData bankTransfer = new PaymentData(); + bankTransfer.setAmount(BigDecimal.valueOf(150)); + bankTransfer.setPaymentReference("19ae2-18mk73-009"); + bankTransfer.setCurrency(Currency.getInstance("EUR")); + bankTransfer.setType("bank"); + return bankTransfer; + } +} \ No newline at end of file From e62aba145b71066dbf8d6cf7a0490e7df73292ef Mon Sep 17 00:00:00 2001 From: Mo Helmy <135069400+BenHelmyBen@users.noreply.github.com> Date: Sat, 7 Oct 2023 15:53:38 +0300 Subject: [PATCH 176/193] This commit related to the article BAEL-6877 (#14899) This commit aims to add a new Java module "core-java-collections-maps-7" --- .../core-java-collections-maps-7/README.md | 1 + .../core-java-collections-maps-7/pom.xml | 78 +++++++++++++++++++ ...MapStringToHashMapObjectUsingtoString.java | 60 ++++++++++++++ ...gToHashMapObjectUsingtoStringUnitTest.java | 31 ++++++++ 4 files changed, 170 insertions(+) create mode 100644 core-java-modules/core-java-collections-maps-7/README.md create mode 100644 core-java-modules/core-java-collections-maps-7/pom.xml create mode 100644 core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/ConvertHashMapStringToHashMapObjectUsingtoString.java create mode 100644 core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/ConvertHashMapStringToHashMapObjectUsingtoStringUnitTest.java diff --git a/core-java-modules/core-java-collections-maps-7/README.md b/core-java-modules/core-java-collections-maps-7/README.md new file mode 100644 index 0000000000..c63f3b360b --- /dev/null +++ b/core-java-modules/core-java-collections-maps-7/README.md @@ -0,0 +1 @@ +## Relevant Articles \ No newline at end of file diff --git a/core-java-modules/core-java-collections-maps-7/pom.xml b/core-java-modules/core-java-collections-maps-7/pom.xml new file mode 100644 index 0000000000..bb7c6e9fb5 --- /dev/null +++ b/core-java-modules/core-java-collections-maps-7/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + core-java-collections-maps-7 + core-java-collections-maps-7 + jar + + + core-java-modules + com.baeldung.core-java-modules + 0.0.1-SNAPSHOT + + + + 5.2.5.RELEASE + + + + com.fasterxml.jackson.core + jackson-databind + 2.12.4 + + + org.openjdk.jmh + jmh-core + 1.36 + + + com.google.code.gson + gson + 2.8.9 + + + org.json + json + 20230227 + + + junit + junit + 4.13.1 + test + + + org.junit.jupiter + junit-jupiter + 5.8.1 + test + + + org.junit.jupiter + junit-jupiter + 5.8.1 + test + + + junit + junit + 4.13.1 + test + + + org.junit.jupiter + junit-jupiter + 5.8.1 + test + + + junit + junit + 4.13.1 + test + + + + \ No newline at end of file diff --git a/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/ConvertHashMapStringToHashMapObjectUsingtoString.java b/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/ConvertHashMapStringToHashMapObjectUsingtoString.java new file mode 100644 index 0000000000..2b3d6db89c --- /dev/null +++ b/core-java-modules/core-java-collections-maps-7/src/main/java/com/baeldung/map/ConvertHashMapStringToHashMapObjectUsingtoString.java @@ -0,0 +1,60 @@ +package com.baeldung.map; + +import java.util.HashMap; +import java.util.Map; + +public class ConvertHashMapStringToHashMapObjectUsingtoString { + public String name; + public int age; + + public ConvertHashMapStringToHashMapObjectUsingtoString(String name, int age) { + this.name = name; + this.age = age; + } + + public static ConvertHashMapStringToHashMapObjectUsingtoString deserializeCustomObject(String valueString) { + if (valueString.startsWith("{") && valueString.endsWith("}")) { + valueString = valueString.substring(1, valueString.length() - 1); + String[] parts = valueString.split(","); + String name = null; + int age = -1; + for (String part : parts) { + String[] keyValue = part.split("="); + if (keyValue.length == 2) { + String key = keyValue[0].trim(); + String val = keyValue[1].trim(); + if (key.equals("name")) { + name = val; + } else if (key.equals("age")) { + age = Integer.parseInt(val); + } + } + } + if (name != null && age >= 0) { + return new ConvertHashMapStringToHashMapObjectUsingtoString(name, age); + } + } + return new ConvertHashMapStringToHashMapObjectUsingtoString("", -1); + } + + public static void main(String[] args) { + String hashMapString = "{key1={name=John, age=30}, key2={name=Alice, age=25}}"; + String keyValuePairs = hashMapString.replaceAll("[{}\\s]", ""); + String[] pairs = keyValuePairs.split(","); + Map actualHashMap = new HashMap<>(); + for (String pair : pairs) { + String[] keyValue = pair.split("="); + if (keyValue.length == 2) { + String key = keyValue[0]; + ConvertHashMapStringToHashMapObjectUsingtoString value = deserializeCustomObject(keyValue[1]); + actualHashMap.put(key, value); + } + } + System.out.println(actualHashMap); + } + + @Override + public String toString() { + return "{name=" + name + ", age=" + age + "}"; + } +} diff --git a/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/ConvertHashMapStringToHashMapObjectUsingtoStringUnitTest.java b/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/ConvertHashMapStringToHashMapObjectUsingtoStringUnitTest.java new file mode 100644 index 0000000000..7d31402131 --- /dev/null +++ b/core-java-modules/core-java-collections-maps-7/src/test/java/com/baeldung/map/ConvertHashMapStringToHashMapObjectUsingtoStringUnitTest.java @@ -0,0 +1,31 @@ +package com.baeldung.map; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class ConvertHashMapStringToHashMapObjectUsingtoStringUnitTest { + + @Test + void givenValidCustomObject_whenSerializing_thenSerializedStringIsCorrect() { + ConvertHashMapStringToHashMapObjectUsingtoString customObject = new ConvertHashMapStringToHashMapObjectUsingtoString("John", 30); + String expectedSerializedString = "{name=John, age=30}"; + assertEquals(expectedSerializedString, customObject.toString()); + } + + @Test + void givenValidSerializedString_whenDeserializing_thenCustomObjectIsCorrect() { + String serializedString = "{name=Alice, age=25}"; + ConvertHashMapStringToHashMapObjectUsingtoString customObject = ConvertHashMapStringToHashMapObjectUsingtoString.deserializeCustomObject(serializedString); + assertEquals("Alice", customObject.name); + assertEquals(25, customObject.age); + } + + @Test + void givenInvalidSerializedString_whenDeserializing_thenDefaultCustomObjectIsCreated() { + String invalidSerializedString = "{invalidString}"; + ConvertHashMapStringToHashMapObjectUsingtoString customObject = ConvertHashMapStringToHashMapObjectUsingtoString.deserializeCustomObject(invalidSerializedString); + assertEquals("", customObject.name); + assertEquals(-1, customObject.age); + } +} From 3a816d6b3d134c06a5d8f9cbe8250b7511a02cfb Mon Sep 17 00:00:00 2001 From: vunamtien Date: Sat, 7 Oct 2023 20:04:59 +0700 Subject: [PATCH 177/193] BAEL-6967-decode-unicode-in-string (#14901) * BAEL-6967-decode-unicode-in-string * update unit test --------- Co-authored-by: tienvn --- libraries-apache-commons-2/pom.xml | 6 +++ .../convertunicode/UnicodeConverterUtil.java | 29 ++++++++++++++ .../UnicodeConverterUnitTest.java | 39 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 libraries-apache-commons-2/src/main/java/com/baeldung/commons/convertunicode/UnicodeConverterUtil.java create mode 100644 libraries-apache-commons-2/src/test/java/com/baeldung/commons/convertunicode/UnicodeConverterUnitTest.java diff --git a/libraries-apache-commons-2/pom.xml b/libraries-apache-commons-2/pom.xml index d771aac9ab..ee9b51e6cc 100644 --- a/libraries-apache-commons-2/pom.xml +++ b/libraries-apache-commons-2/pom.xml @@ -28,12 +28,18 @@ commons-vfs2 ${commons-vfs2.version} + + org.apache.commons + commons-text + ${apache-commons-text.version} + 1.23.0 1.10.13 2.9.0 + 1.10.0 \ No newline at end of file diff --git a/libraries-apache-commons-2/src/main/java/com/baeldung/commons/convertunicode/UnicodeConverterUtil.java b/libraries-apache-commons-2/src/main/java/com/baeldung/commons/convertunicode/UnicodeConverterUtil.java new file mode 100644 index 0000000000..c788f6ee61 --- /dev/null +++ b/libraries-apache-commons-2/src/main/java/com/baeldung/commons/convertunicode/UnicodeConverterUtil.java @@ -0,0 +1,29 @@ +package com.baeldung.commons.convertunicode; + +import org.apache.commons.text.StringEscapeUtils; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class UnicodeConverterUtil { + + public static String decodeWithApacheCommons(String input) { + return StringEscapeUtils.unescapeJava(input); + } + + public static String decodeWithPlainJava(String input) { + Pattern pattern = Pattern.compile("\\\\u[0-9a-fA-F]{4}"); + Matcher matcher = pattern.matcher(input); + + StringBuilder decodedString = new StringBuilder(); + + while (matcher.find()) { + String unicodeSequence = matcher.group(); + char unicodeChar = (char) Integer.parseInt(unicodeSequence.substring(2), 16); + matcher.appendReplacement(decodedString, Character.toString(unicodeChar)); + } + + matcher.appendTail(decodedString); + return decodedString.toString(); + } +} diff --git a/libraries-apache-commons-2/src/test/java/com/baeldung/commons/convertunicode/UnicodeConverterUnitTest.java b/libraries-apache-commons-2/src/test/java/com/baeldung/commons/convertunicode/UnicodeConverterUnitTest.java new file mode 100644 index 0000000000..f4a9bbcb77 --- /dev/null +++ b/libraries-apache-commons-2/src/test/java/com/baeldung/commons/convertunicode/UnicodeConverterUnitTest.java @@ -0,0 +1,39 @@ +package com.baeldung.commons.convertunicode; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class UnicodeConverterUnitTest { + + @Test + public void whenInputHaveUnicodeSequences_ThenDecode() { + String encodedString = "\\u0048\\u0065\\u006C\\u006C\\u006F World"; + String expectedDecodedString = "Hello World"; + assertEquals(expectedDecodedString, UnicodeConverterUtil.decodeWithApacheCommons(encodedString)); + assertEquals(expectedDecodedString, UnicodeConverterUtil.decodeWithPlainJava(encodedString)); + } + + @Test + public void whenInputHaveNoUnicodeSequences_ThenDoNothing() { + String inputString = "Hello World"; + assertEquals(inputString, UnicodeConverterUtil.decodeWithApacheCommons(inputString)); + assertEquals(inputString, UnicodeConverterUtil.decodeWithPlainJava(inputString)); + } + + @Test + public void whenInputHaveUnicodeSequencesInMiddle_ThenDecode() { + String encodedString = "This is a test \\u0069\\u006E the middle."; + String expectedDecodedString = "This is a test in the middle."; + assertEquals(expectedDecodedString, UnicodeConverterUtil.decodeWithApacheCommons(encodedString)); + assertEquals(expectedDecodedString, UnicodeConverterUtil.decodeWithPlainJava(encodedString)); + } + + @Test + public void whenInputHaveMultipleUnicodeSequences_ThenDecode() { + String encodedString = "Unicode: \\u0048\\u0065\\u006C\\u006C\\u006F \\u0057\\u006F\\u0072\\u006C\\u0064"; + String expectedDecodedString = "Unicode: Hello World"; + assertEquals(expectedDecodedString, UnicodeConverterUtil.decodeWithApacheCommons(encodedString)); + assertEquals(expectedDecodedString, UnicodeConverterUtil.decodeWithPlainJava(encodedString)); + } +} From 131d6757719ac3e603f94160ffcfde5346d5f292 Mon Sep 17 00:00:00 2001 From: balasr3 Date: Sat, 7 Oct 2023 14:48:34 +0100 Subject: [PATCH 178/193] BAEL-7032: updated with review comment on test --- .../baeldung/expression/mapper/LicenseMapperUnitTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mapstruct/src/test/java/com/baeldung/expression/mapper/LicenseMapperUnitTest.java b/mapstruct/src/test/java/com/baeldung/expression/mapper/LicenseMapperUnitTest.java index 8c015674bc..d7521e81f5 100644 --- a/mapstruct/src/test/java/com/baeldung/expression/mapper/LicenseMapperUnitTest.java +++ b/mapstruct/src/test/java/com/baeldung/expression/mapper/LicenseMapperUnitTest.java @@ -76,7 +76,7 @@ class LicenseMapperUnitTest { } @Test - void givenLicenseDtoWithoutLicenseTypeString_WhenMapperMethodIsInvoked_ThenLicenseShouldBePopulatedWithoutLicenseType() { + void givenLicenseDtoWithoutLicenseTypeString_whenMapperMethodIsInvoked_thenLicenseShouldBePopulatedWithoutLicenseType() { LicenseDto licenseDto = new LicenseDto(); License license = licenseMapper.toLicense(licenseDto); assertThat(license).isNotNull(); @@ -84,7 +84,7 @@ class LicenseMapperUnitTest { } @Test - void givenLicenseDtoWithInvalidLicenseTypeString_WhenMapperMethodIsInvoked_ThenLicenseShouldBePopulatedWithoutLicenseType() { + void givenLicenseDtoWithInvalidLicenseTypeString_whenMapperMethodIsInvoked_thenLicenseShouldBePopulatedWithoutLicenseType() { LicenseDto licenseDto = new LicenseDto(); licenseDto.setLicenseType("invalid_license_type"); License license = licenseMapper.toLicense(licenseDto); @@ -93,7 +93,7 @@ class LicenseMapperUnitTest { } @Test - void givenLicenseDtoWithValidLicenseTypeString_WhenMapperMethodIsInvoked_ThenLicenseShouldBePopulatedWithMatchingLicenseType() { + void givenLicenseDtoWithValidLicenseTypeString_whenMapperMethodIsInvoked_thenLicenseShouldBePopulatedWithMatchingLicenseType() { LicenseDto licenseDto = new LicenseDto(); licenseDto.setLicenseType("INDIVIDUAL"); License license = licenseMapper.toLicense(licenseDto); From b7f3161bc517278aec132fedbd799c63bd896973 Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Mon, 9 Oct 2023 04:30:55 +0200 Subject: [PATCH 179/193] [bin-int-to-str] zero-padded binary string representation (#14885) --- .../IntegerToBinaryUnitTest.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-numbers-3/src/test/java/com/baeldung/integerToBinary/IntegerToBinaryUnitTest.java b/core-java-modules/core-java-numbers-3/src/test/java/com/baeldung/integerToBinary/IntegerToBinaryUnitTest.java index 38ae79f2f5..9439f012e3 100644 --- a/core-java-modules/core-java-numbers-3/src/test/java/com/baeldung/integerToBinary/IntegerToBinaryUnitTest.java +++ b/core-java-modules/core-java-numbers-3/src/test/java/com/baeldung/integerToBinary/IntegerToBinaryUnitTest.java @@ -1,6 +1,8 @@ package com.baeldung.integerToBinary; +import org.apache.commons.lang3.StringUtils; import org.junit.Test; + import static org.junit.Assert.assertEquals; public class IntegerToBinaryUnitTest { @@ -24,4 +26,18 @@ public class IntegerToBinaryUnitTest { String binaryString = Integer.toString(n, 2); assertEquals("111", binaryString); } -} + + @Test + public void givenAnInteger_whenFormatAndReplaceCalled_thenZeroPaddedBinaryString() { + int n = 7; + String binaryString = String.format("%8s", Integer.toBinaryString(n)).replace(" ", "0"); + assertEquals("00000111", binaryString); + } + + @Test + public void givenAnInteger_whenUsingApacheStringUtils_thenZeroPaddedBinaryString() { + int n = 7; + String binaryString = StringUtils.leftPad(Integer.toBinaryString(n), 8, "0"); + assertEquals("00000111", binaryString); + } +} \ No newline at end of file From 0e7c032aa8c67fcd06a8e4a5d217ad2f8c4e3e22 Mon Sep 17 00:00:00 2001 From: Rufina Uche <102101377+Finniki@users.noreply.github.com> Date: Mon, 9 Oct 2023 08:53:46 +0100 Subject: [PATCH 180/193] Javadoublevsbigdecimal (#14862) * Create BigDecimalConversionUnitTest.java * Add files via upload * Update BigDecimalConversionUnitTest.java * Update BigDecimalConversionUnitTest.java * Update BigDecimalConversionUnitTest.java --- .../BigDecimalConversionUnitTest.java | 28 +++++++++++++ .../BigDecimalUnitTest.java | 42 +++++++++++++++++++ .../JavaDoubleUnitTest.java | 15 +++++++ 3 files changed, 85 insertions(+) create mode 100644 core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/javadoublevsbigdecimal/BigDecimalConversionUnitTest.java create mode 100644 core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/javadoublevsbigdecimal/BigDecimalUnitTest.java create mode 100644 core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/javadoublevsbigdecimal/JavaDoubleUnitTest.java diff --git a/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/javadoublevsbigdecimal/BigDecimalConversionUnitTest.java b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/javadoublevsbigdecimal/BigDecimalConversionUnitTest.java new file mode 100644 index 0000000000..76c218d85f --- /dev/null +++ b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/javadoublevsbigdecimal/BigDecimalConversionUnitTest.java @@ -0,0 +1,28 @@ +package com.baeldung.javadoublevsbigdecimal; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +import org.junit.jupiter.api.Test; + +public class BigDecimalConversionUnitTest { + + @Test + void whenConvertingDoubleToBigDecimal_thenConversionIsCorrect() { + double doubleValue = 123.456; + BigDecimal bigDecimalValue = BigDecimal.valueOf(doubleValue); + BigDecimal expected = new BigDecimal("123.456").setScale(3, RoundingMode.HALF_UP); + assertEquals(expected, bigDecimalValue.setScale(3, RoundingMode.HALF_UP)); + } + + @Test + void givenDecimalPlacesGreaterThan15_whenConvertingBigDecimalToDouble_thenPrecisionIsLost() { + BigDecimal bigDecimalValue = new BigDecimal("789.1234567890123456"); + double doubleValue = bigDecimalValue.doubleValue(); + BigDecimal convertedBackToBigDecimal = BigDecimal.valueOf(doubleValue); + assertNotEquals(bigDecimalValue, convertedBackToBigDecimal); + } +} diff --git a/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/javadoublevsbigdecimal/BigDecimalUnitTest.java b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/javadoublevsbigdecimal/BigDecimalUnitTest.java new file mode 100644 index 0000000000..3ee611f315 --- /dev/null +++ b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/javadoublevsbigdecimal/BigDecimalUnitTest.java @@ -0,0 +1,42 @@ +package com.baeldung.javadoublevsbigdecimal; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +import org.junit.jupiter.api.Test; + +public class BigDecimalUnitTest { + + private BigDecimal bigDecimal1 = new BigDecimal("124567890.0987654321"); + private BigDecimal bigDecimal2 = new BigDecimal("987654321.123456789"); + + @Test + public void givenTwoBigDecimals_whenAdd_thenCorrect() { + BigDecimal expected = new BigDecimal("1112222211.2222222211"); + BigDecimal actual = bigDecimal1.add(bigDecimal2); + assertEquals(expected, actual); + } + + @Test + public void givenTwoBigDecimals_whenMultiply_thenCorrect() { + BigDecimal expected = new BigDecimal("123030014929277547.5030955772112635269"); + BigDecimal actual = bigDecimal1.multiply(bigDecimal2); + assertEquals(expected, actual); + } + + @Test + public void givenTwoBigDecimals_whenSubtract_thenCorrect() { + BigDecimal expected = new BigDecimal("-863086431.0246913569"); + BigDecimal actual = bigDecimal1.subtract(bigDecimal2); + assertEquals(expected, actual); + } + + @Test + public void givenTwoBigDecimals_whenDivide_thenCorrect() { + BigDecimal expected = new BigDecimal("0.13"); + BigDecimal actual = bigDecimal1.divide(bigDecimal2, 2, RoundingMode.HALF_UP); + assertEquals(expected, actual); + } +} diff --git a/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/javadoublevsbigdecimal/JavaDoubleUnitTest.java b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/javadoublevsbigdecimal/JavaDoubleUnitTest.java new file mode 100644 index 0000000000..8697e1bfce --- /dev/null +++ b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/javadoublevsbigdecimal/JavaDoubleUnitTest.java @@ -0,0 +1,15 @@ +package com.baeldung.javadoublevsbigdecimal; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +public class JavaDoubleUnitTest { + + @Test + public void givenDoubleLiteral_whenAssigningToDoubleVariable_thenValueIsNotExactlyEqual() { + double doubleValue = 0.1; + double epsilon = 0.0000000000000001; + assertEquals(0.1, doubleValue, epsilon); + } +} From 901951bff763b3cc4df554d077f6d5930425a5e4 Mon Sep 17 00:00:00 2001 From: Harry9656 Date: Mon, 9 Oct 2023 09:53:54 +0200 Subject: [PATCH 181/193] BAEL-6898: Add Debug property for ssl Handshakes (#14822) --- .../java/com/baeldung/ssl/SecureConnection.java | 14 +++++++------- .../com/baeldung/ssl/example/SimpleClient.java | 7 +++---- .../com/baeldung/ssl/example/SimpleServer.java | 8 ++++---- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/SecureConnection.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/SecureConnection.java index 36dee603eb..6f2e3250fc 100644 --- a/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/SecureConnection.java +++ b/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/SecureConnection.java @@ -7,7 +7,7 @@ import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; public class SecureConnection { - + public static void main(String[] args) { if (args.length != 2) { System.out.println("Use: SecureConnection host port"); @@ -20,20 +20,20 @@ public class SecureConnection { SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(host, port); InputStream in = sslsocket.getInputStream(); OutputStream out = sslsocket.getOutputStream(); - + out.write(1); - + while (in.available() > 0) { System.out.print(in.read()); } - + System.out.println("Secured connection performed successfully"); - + } catch (Exception exception) { exception.printStackTrace(); } } - + /** * Get the host from arguments * @param args the arguments @@ -42,7 +42,7 @@ public class SecureConnection { private static String getHost(String[] args) { return args[0]; } - + /** * Get the port from arguments * @param args the arguments diff --git a/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/example/SimpleClient.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/example/SimpleClient.java index d6efc34c3e..cf9a76b39a 100644 --- a/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/example/SimpleClient.java +++ b/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/example/SimpleClient.java @@ -15,10 +15,8 @@ public class SimpleClient { SocketFactory factory = SSLSocketFactory.getDefault(); try (Socket connection = factory.createSocket(host, port)) { - ((SSLSocket) connection).setEnabledCipherSuites( - new String[] { "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256"}); - ((SSLSocket) connection).setEnabledProtocols( - new String[] { "TLSv1.2"}); + ((SSLSocket) connection).setEnabledCipherSuites(new String[] { "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256" }); + ((SSLSocket) connection).setEnabledProtocols(new String[] { "TLSv1.2" }); SSLParameters sslParams = new SSLParameters(); sslParams.setEndpointIdentificationAlgorithm("HTTPS"); ((SSLSocket) connection).setSSLParameters(sslParams); @@ -28,6 +26,7 @@ public class SimpleClient { } public static void main(String[] args) throws IOException { + System.setProperty("javax.net.debug", "ssl:handshake"); System.out.println(startClient("localhost", 8443)); } } diff --git a/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/example/SimpleServer.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/example/SimpleServer.java index 27d15d04d7..83946ccc1f 100644 --- a/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/example/SimpleServer.java +++ b/core-java-modules/core-java-security/src/main/java/com/baeldung/ssl/example/SimpleServer.java @@ -14,11 +14,10 @@ public class SimpleServer { ServerSocketFactory factory = SSLServerSocketFactory.getDefault(); try (ServerSocket listener = factory.createServerSocket(port)) { + System.setProperty("javax.net.debug", "ssl:handshake"); ((SSLServerSocket) listener).setNeedClientAuth(true); - ((SSLServerSocket) listener).setEnabledCipherSuites( - new String[] { "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256"}); - ((SSLServerSocket) listener).setEnabledProtocols( - new String[] { "TLSv1.2"}); + ((SSLServerSocket) listener).setEnabledCipherSuites(new String[] { "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256" }); + ((SSLServerSocket) listener).setEnabledProtocols(new String[] { "TLSv1.2" }); while (true) { try (Socket socket = listener.accept()) { PrintWriter out = new PrintWriter(socket.getOutputStream(), true); @@ -29,6 +28,7 @@ public class SimpleServer { } public static void main(String[] args) throws IOException { + System.setProperty("javax.net.debug", "ssl:handshake"); startServer(8443); } } \ No newline at end of file From 52f4344bceeece2e05d4a515bac46d7d8fcfb313 Mon Sep 17 00:00:00 2001 From: Azhwani <13301425+azhwani@users.noreply.github.com> Date: Mon, 9 Oct 2023 09:55:29 +0200 Subject: [PATCH 182/193] BAEL-7057: How to convert CharSequence to String? (#14892) --- .../CharSequenceVsStringUnitTest.java | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-string-apis/src/test/java/com/baeldung/charsequence/CharSequenceVsStringUnitTest.java b/core-java-modules/core-java-string-apis/src/test/java/com/baeldung/charsequence/CharSequenceVsStringUnitTest.java index aa15345bcb..13a0407a98 100644 --- a/core-java-modules/core-java-string-apis/src/test/java/com/baeldung/charsequence/CharSequenceVsStringUnitTest.java +++ b/core-java-modules/core-java-string-apis/src/test/java/com/baeldung/charsequence/CharSequenceVsStringUnitTest.java @@ -1,11 +1,11 @@ package com.baeldung.charsequence; -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; +import org.junit.Test; + public class CharSequenceVsStringUnitTest { @Test @@ -44,4 +44,43 @@ public class CharSequenceVsStringUnitTest { assertEquals(firstAddressOfTest, secondAddressOfTest); } + + @Test + public void givenCharSequenceAsString_whenConvertingUsingCasting_thenCorrect() { + String expected = "baeldung"; + CharSequence charSequence = "baeldung"; + String explicitCastedString = (String) charSequence; + + assertEquals(expected, charSequence); + assertEquals(expected, explicitCastedString); + } + + @Test(expected = ClassCastException.class) + public void givenCharSequenceAsStringBuiler_whenConvertingUsingCasting_thenThrowException() { + CharSequence charSequence = new StringBuilder("baeldung"); + String castedString = (String) charSequence; + } + + @Test + public void givenCharSequence_whenConvertingUsingToString_thenCorrect() { + String expected = "baeldung"; + CharSequence charSequence1 = "baeldung"; + CharSequence charSequence2 = new StringBuilder("baeldung"); + + assertEquals(expected, charSequence1.toString()); + assertEquals(expected, charSequence2.toString()); + } + + @Test + public void givenCharSequence_whenConvertingUsingValueOf_thenCorrect() { + String expected = "baeldung"; + CharSequence charSequence1 = "baeldung"; + CharSequence charSequence2 = new StringBuilder("baeldung"); + CharSequence charSequence3 = null; + + assertEquals(expected, String.valueOf(charSequence1)); + assertEquals(expected, String.valueOf(charSequence2)); + assertEquals("null", String.valueOf(charSequence3)); + } + } From 1f3252df75b2381fd8d11016b5925c8d1910ed12 Mon Sep 17 00:00:00 2001 From: Azhwani <13301425+azhwani@users.noreply.github.com> Date: Mon, 9 Oct 2023 09:57:03 +0200 Subject: [PATCH 183/193] BAEL-6714: Convert Char Array to Int Array in Java (#14875) --- .../conversions/CharArrayToIntArrayUtils.java | 67 +++++++++++++++++++ .../CharArrayToIntArrayUtilsUnitTest.java | 54 +++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 core-java-modules/core-java-arrays-convert/src/main/java/com/baeldung/array/conversions/CharArrayToIntArrayUtils.java create mode 100644 core-java-modules/core-java-arrays-convert/src/test/java/com/baeldung/array/conversions/CharArrayToIntArrayUtilsUnitTest.java diff --git a/core-java-modules/core-java-arrays-convert/src/main/java/com/baeldung/array/conversions/CharArrayToIntArrayUtils.java b/core-java-modules/core-java-arrays-convert/src/main/java/com/baeldung/array/conversions/CharArrayToIntArrayUtils.java new file mode 100644 index 0000000000..fbd76a0113 --- /dev/null +++ b/core-java-modules/core-java-arrays-convert/src/main/java/com/baeldung/array/conversions/CharArrayToIntArrayUtils.java @@ -0,0 +1,67 @@ +package com.baeldung.array.conversions; + +import java.util.Arrays; + +public class CharArrayToIntArrayUtils { + + static int[] usingGetNumericValueMethod(char[] chars) { + if (chars == null) { + return null; + } + + int[] ints = new int[chars.length]; + for (int i = 0; i < chars.length; i++) { + ints[i] = Character.getNumericValue(chars[i]); + } + + return ints; + } + + static int[] usingDigitMethod(char[] chars) { + if (chars == null) { + return null; + } + + int[] ints = new int[chars.length]; + for (int i = 0; i < chars.length; i++) { + ints[i] = Character.digit(chars[i], 10); + } + + return ints; + } + + static int[] usingStreamApiMethod(char[] chars) { + if (chars == null) { + return null; + } + + return new String(chars).chars() + .map(c -> c - 48) + .toArray(); + } + + static int[] usingParseIntMethod(char[] chars) { + if (chars == null) { + return null; + } + + int[] ints = new int[chars.length]; + for (int i = 0; i < chars.length; i++) { + ints[i] = Integer.parseInt(String.valueOf(chars[i])); + } + + return ints; + } + + static int[] usingArraysSetAllMethod(char[] chars) { + if (chars == null) { + return null; + } + + int[] ints = new int[chars.length]; + Arrays.setAll(ints, i -> Character.getNumericValue(chars[i])); + + return ints; + } + +} diff --git a/core-java-modules/core-java-arrays-convert/src/test/java/com/baeldung/array/conversions/CharArrayToIntArrayUtilsUnitTest.java b/core-java-modules/core-java-arrays-convert/src/test/java/com/baeldung/array/conversions/CharArrayToIntArrayUtilsUnitTest.java new file mode 100644 index 0000000000..534dc3893f --- /dev/null +++ b/core-java-modules/core-java-arrays-convert/src/test/java/com/baeldung/array/conversions/CharArrayToIntArrayUtilsUnitTest.java @@ -0,0 +1,54 @@ +package com.baeldung.array.conversions; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + +import org.junit.jupiter.api.Test; + +class CharArrayToIntArrayUtilsUnitTest { + + @Test + void givenCharArray_whenUsingGetNumericValueMethod_shouldGetIntArray() { + int[] expected = { 2, 3, 4, 5 }; + char[] chars = { '2', '3', '4', '5' }; + int[] result = CharArrayToIntArrayUtils.usingGetNumericValueMethod(chars); + + assertArrayEquals(expected, result); + } + + @Test + void givenCharArray_whenUsingDigitMethod_shouldGetIntArray() { + int[] expected = { 1, 2, 3, 6 }; + char[] chars = { '1', '2', '3', '6' }; + int[] result = CharArrayToIntArrayUtils.usingDigitMethod(chars); + + assertArrayEquals(expected, result); + } + + @Test + void givenCharArray_whenUsingStreamApi_shouldGetIntArray() { + int[] expected = { 9, 8, 7, 6 }; + char[] chars = { '9', '8', '7', '6' }; + int[] result = CharArrayToIntArrayUtils.usingStreamApiMethod(chars); + + assertArrayEquals(expected, result); + } + + @Test + void givenCharArray_whenUsingParseIntMethod_shouldGetIntArray() { + int[] expected = { 9, 8, 7, 6 }; + char[] chars = { '9', '8', '7', '6' }; + int[] result = CharArrayToIntArrayUtils.usingParseIntMethod(chars); + + assertArrayEquals(expected, result); + } + + @Test + void givenCharArray_whenUsingArraysSetAllMethod_shouldGetIntArray() { + int[] expected = { 4, 9, 2, 3 }; + char[] chars = { '4', '9', '2', '3' }; + int[] result = CharArrayToIntArrayUtils.usingArraysSetAllMethod(chars); + + assertArrayEquals(expected, result); + } + +} From bb29bb9dcd1582376ac8bdd67c3d67c192ff39c7 Mon Sep 17 00:00:00 2001 From: Mo Helmy <135069400+BenHelmyBen@users.noreply.github.com> Date: Mon, 9 Oct 2023 14:17:30 +0300 Subject: [PATCH 184/193] Adding the new module to the main pom (#14924) * This commit related to the article BAEL-6877 This commit aims to add a new Java module "core-java-collections-maps-7" * Update pom.xml --- core-java-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index cd31bb5845..ae9ff59222 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -83,6 +83,7 @@ core-java-collections-maps core-java-collections-maps-2 core-java-collections-maps-3 + core-java-collections-maps-7 core-java-compiler core-java-concurrency-2 core-java-concurrency-advanced From ff6d3e73935c9ad1243ff4e7c49a087d84ca9a28 Mon Sep 17 00:00:00 2001 From: mdabrowski-eu <57441874+mdabrowski-eu@users.noreply.github.com> Date: Mon, 9 Oct 2023 13:33:39 +0200 Subject: [PATCH 185/193] BAEL-6911 fix dependencies issues, add missing snipets (#14935) --- spring-boot-modules/spring-boot-3/pom.xml | 8 ++- .../java/com/baeldung/restclient/Article.java | 10 +++ .../restclient/ArticleController.java | 19 ++++-- .../restclient/ArticleNotFoundException.java | 6 ++ .../InvalidArticleResponseException.java | 6 ++ .../restclient/RestClientIntegrationTest.java | 66 +++++++++++++++++-- 6 files changed, 101 insertions(+), 14 deletions(-) create mode 100644 spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleNotFoundException.java create mode 100644 spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/InvalidArticleResponseException.java diff --git a/spring-boot-modules/spring-boot-3/pom.xml b/spring-boot-modules/spring-boot-3/pom.xml index 7dd44c89dc..bb8c5dd53c 100644 --- a/spring-boot-modules/spring-boot-3/pom.xml +++ b/spring-boot-modules/spring-boot-3/pom.xml @@ -60,7 +60,11 @@ org.junit.jupiter junit-jupiter-params ${jupiter.version} - test + + + org.junit.platform + junit-platform-commons + 1.10.0 org.mock-server @@ -204,7 +208,7 @@ 19 1.5.2.Final - 2.0.0 + 2.2.0 3.0.0-M7 com.baeldung.sample.TodoApplication 5.14.0 diff --git a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/Article.java b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/Article.java index a69d5989af..892cf3b5ae 100644 --- a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/Article.java +++ b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/Article.java @@ -6,6 +6,8 @@ public class Article { Integer id; String title; + public Article() {} + public Article(Integer id, String title) { this.id = id; this.title = title; @@ -19,6 +21,14 @@ public class Article { return title; } + public void setId(Integer id) { + this.id = id; + } + + public void setTitle(String title) { + this.title = title; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleController.java b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleController.java index 62922bdcee..5e1dff6fd7 100644 --- a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleController.java +++ b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleController.java @@ -1,5 +1,6 @@ package com.baeldung.restclient; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.Collection; @@ -13,13 +14,21 @@ public class ArticleController { Map database = new HashMap<>(); @GetMapping - public Collection
getArticles() { - return database.values(); + public ResponseEntity> getArticles() { + Collection
values = database.values(); + if (values.isEmpty()) { + return ResponseEntity.noContent().build(); + } + return ResponseEntity.ok(values); } @GetMapping("/{id}") - public Article getArticle(@PathVariable Integer id) { - return database.get(id); + public ResponseEntity
getArticle(@PathVariable("id") Integer id) { + Article article = database.get(id); + if (article == null) { + return ResponseEntity.notFound().build(); + } + return ResponseEntity.ok(article); } @PostMapping @@ -28,7 +37,7 @@ public class ArticleController { } @PutMapping("/{id}") - public void updateArticle(@PathVariable Integer id, @RequestBody Article article) { + public void updateArticle(@PathVariable("id") Integer id, @RequestBody Article article) { assert Objects.equals(id, article.getId()); database.remove(id); database.put(id, article); diff --git a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleNotFoundException.java b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleNotFoundException.java new file mode 100644 index 0000000000..cdd13b8330 --- /dev/null +++ b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleNotFoundException.java @@ -0,0 +1,6 @@ +package com.baeldung.restclient; + +public class ArticleNotFoundException extends RuntimeException { + public ArticleNotFoundException() { + } +} diff --git a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/InvalidArticleResponseException.java b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/InvalidArticleResponseException.java new file mode 100644 index 0000000000..26ca75036e --- /dev/null +++ b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/InvalidArticleResponseException.java @@ -0,0 +1,6 @@ +package com.baeldung.restclient; + +public class InvalidArticleResponseException extends RuntimeException { + public InvalidArticleResponseException() { + } +} diff --git a/spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/restclient/RestClientIntegrationTest.java b/spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/restclient/RestClientIntegrationTest.java index 92474c88f0..1a615faf4e 100644 --- a/spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/restclient/RestClientIntegrationTest.java +++ b/spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/restclient/RestClientIntegrationTest.java @@ -1,17 +1,23 @@ package com.baeldung.restclient; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestClient; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -22,7 +28,10 @@ public class RestClientIntegrationTest { private String uriBase; RestClient restClient = RestClient.create(); - @BeforeAll + @Autowired + ObjectMapper objectMapper; + + @BeforeEach public void setup() { uriBase = "http://localhost:" + port; } @@ -42,7 +51,7 @@ public class RestClientIntegrationTest { .retrieve() .body(String.class); - assertThat(articlesAsString).isEqualTo("[]"); + assertThat(articlesAsString).isEqualTo(""); } @Test @@ -63,6 +72,48 @@ public class RestClientIntegrationTest { assertThat(articles).isEqualTo(List.of(article)); } + @Test + void shouldPostAndGetArticlesWithExchange() { + assertThatThrownBy(this::getArticlesWithExchange).isInstanceOf(ArticleNotFoundException.class); + + Article article = new Article(1, "How to use RestClient"); + restClient.post() + .uri(uriBase + "/articles") + .contentType(MediaType.APPLICATION_JSON) + .body(article) + .retrieve() + .toBodilessEntity(); + + List
articles = getArticlesWithExchange(); + + assertThat(articles).isEqualTo(List.of(article)); + } + + private List
getArticlesWithExchange() { + return restClient.get() + .uri(uriBase + "/articles") + .exchange((request, response) -> { + if (response.getStatusCode().isSameCodeAs(HttpStatusCode.valueOf(204))) { + throw new ArticleNotFoundException(); + } else if (response.getStatusCode().isSameCodeAs(HttpStatusCode.valueOf(200))) { + return objectMapper.readValue(response.getBody(), new TypeReference<>() {}); + } else { + throw new InvalidArticleResponseException(); + } + }); + } + + @Test + void shouldPostAndGetArticlesWithErrorHandling() { + assertThatThrownBy(() -> { + restClient.get() + .uri(uriBase + "/articles/1234") + .retrieve() + .onStatus(status -> status.value() == 404, (request, response) -> { throw new ArticleNotFoundException(); }) + .body(new ParameterizedTypeReference<>() {}); + }).isInstanceOf(ArticleNotFoundException.class); + } + @Test void shouldPostAndPutAndGetArticles() { Article article = new Article(1, "How to use RestClient"); @@ -79,7 +130,7 @@ public class RestClientIntegrationTest { .contentType(MediaType.APPLICATION_JSON) .body(articleChanged) .retrieve() - .toBodilessEntity(); + .toBodilessEntity(); List
articles = restClient.get() .uri(uriBase + "/articles") @@ -104,11 +155,12 @@ public class RestClientIntegrationTest { .retrieve() .toBodilessEntity(); - List
articles = restClient.get() + ResponseEntity entity = restClient.get() .uri(uriBase + "/articles") + .accept(MediaType.APPLICATION_JSON) .retrieve() - .body(new ParameterizedTypeReference<>() {}); + .toBodilessEntity(); - assertThat(articles).isEqualTo(List.of()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatusCode.valueOf(204)); } } From 8ffbb095da59585553a065426dc43ea227cf9a75 Mon Sep 17 00:00:00 2001 From: Bhaskar Ghosh Dastidar Date: Tue, 10 Oct 2023 01:29:52 +0530 Subject: [PATCH 186/193] [BAEL-6955] finalization deprcation (#14932) Co-authored-by: Bhaskar --- core-java-modules/core-java-18/README.md | 0 core-java-modules/core-java-18/pom.xml | 55 +++++++++++++++++++ .../FinalizationExamples.java | 27 +++++++++ .../MyCleanerResourceClass.java | 48 ++++++++++++++++ .../MyCloseableResourceClass.java | 25 +++++++++ .../MyFinalizableResourceClass.java | 24 ++++++++ .../core-java-18/src/main/resources/file.txt | 1 + .../FinalizationCloseableCleanerUnitTest.java | 36 ++++++++++++ 8 files changed, 216 insertions(+) create mode 100644 core-java-modules/core-java-18/README.md create mode 100644 core-java-modules/core-java-18/pom.xml create mode 100644 core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/FinalizationExamples.java create mode 100644 core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/MyCleanerResourceClass.java create mode 100644 core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/MyCloseableResourceClass.java create mode 100644 core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/MyFinalizableResourceClass.java create mode 100644 core-java-modules/core-java-18/src/main/resources/file.txt create mode 100644 core-java-modules/core-java-18/src/test/java/com/baeldung/finalization_closeable_cleaner/FinalizationCloseableCleanerUnitTest.java diff --git a/core-java-modules/core-java-18/README.md b/core-java-modules/core-java-18/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/core-java-modules/core-java-18/pom.xml b/core-java-modules/core-java-18/pom.xml new file mode 100644 index 0000000000..7af6258497 --- /dev/null +++ b/core-java-modules/core-java-18/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + core-java-18 + core-java-18 + jar + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../../ + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.release} + --enable-preview + ${maven.compiler.source.version} + ${maven.compiler.target.version} + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + 1 + + + + org.apache.maven.surefire + surefire-api + ${surefire.plugin.version} + + + + + + + + 18 + 18 + 18 + 3.0.0-M5 + + + \ No newline at end of file diff --git a/core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/FinalizationExamples.java b/core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/FinalizationExamples.java new file mode 100644 index 0000000000..3ff77c37d6 --- /dev/null +++ b/core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/FinalizationExamples.java @@ -0,0 +1,27 @@ +package com.baeldung.finalization_closeable_cleaner; + +import java.io.FileInputStream; +import java.io.IOException; + +public class FinalizationExamples { + FileInputStream fis = null; + + public void readFileOperationWithFinalization() throws IOException { + try { + fis = new FileInputStream("input.txt"); + // perform operation on the file + System.out.println(fis.readAllBytes().length); + + } finally { + if (fis != null) + fis.close(); + } + } + + public void readFileOperationWithTryWith() throws IOException { + try (FileInputStream fis = new FileInputStream("input.txt")) { + // perform operations + System.out.println(fis.readAllBytes().length); + } + } +} diff --git a/core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/MyCleanerResourceClass.java b/core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/MyCleanerResourceClass.java new file mode 100644 index 0000000000..1dcdd216cb --- /dev/null +++ b/core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/MyCleanerResourceClass.java @@ -0,0 +1,48 @@ +package com.baeldung.finalization_closeable_cleaner; + +import java.lang.ref.Cleaner; + +public class MyCleanerResourceClass implements AutoCloseable { + private static Resource resource; + + private static final Cleaner cleaner = Cleaner.create(); + private final Cleaner.Cleanable cleanable; + + public MyCleanerResourceClass() { + resource = new Resource(); + this.cleanable = cleaner.register(this, new CleaningState()); + } + + public void useResource() { + // using the resource here + resource.use(); + } + + @Override + public void close() { + // perform actions to close all underlying resources + this.cleanable.clean(); + } + + static class CleaningState implements Runnable { + CleaningState() { + // constructor + } + + @Override + public void run() { + // some cleanup action + System.out.println("Cleanup done"); + } + } + + static class Resource { + void use() { + System.out.println("Using the resource"); + } + + void close() { + System.out.println("Cleanup done"); + } + } +} diff --git a/core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/MyCloseableResourceClass.java b/core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/MyCloseableResourceClass.java new file mode 100644 index 0000000000..b11cb4e49e --- /dev/null +++ b/core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/MyCloseableResourceClass.java @@ -0,0 +1,25 @@ +package com.baeldung.finalization_closeable_cleaner; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + +public class MyCloseableResourceClass implements AutoCloseable { + + private final FileInputStream fis; + + public MyCloseableResourceClass() throws FileNotFoundException { + this.fis = new FileInputStream("src/main/resources/file.txt"); + + } + + public int getByteLength() throws IOException { + System.out.println("Some operation"); + return this.fis.readAllBytes().length; + } + @Override + public void close() throws IOException { + System.out.println("Finalized object"); + this.fis.close(); + } +} diff --git a/core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/MyFinalizableResourceClass.java b/core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/MyFinalizableResourceClass.java new file mode 100644 index 0000000000..a2c6a123b4 --- /dev/null +++ b/core-java-modules/core-java-18/src/main/java/com/baeldung/finalization_closeable_cleaner/MyFinalizableResourceClass.java @@ -0,0 +1,24 @@ +package com.baeldung.finalization_closeable_cleaner; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + +public class MyFinalizableResourceClass { + private FileInputStream fis; + + public MyFinalizableResourceClass() throws FileNotFoundException { + this.fis = new FileInputStream("src/main/resources/file.txt"); + } + + public int getByteLength() throws IOException { + System.out.println("Some operation"); + return this.fis.readAllBytes().length; + } + + @Override + protected void finalize() throws Throwable { + System.out.println("Finalized object"); + this.fis.close(); + } +} diff --git a/core-java-modules/core-java-18/src/main/resources/file.txt b/core-java-modules/core-java-18/src/main/resources/file.txt new file mode 100644 index 0000000000..af27ff4986 --- /dev/null +++ b/core-java-modules/core-java-18/src/main/resources/file.txt @@ -0,0 +1 @@ +This is a test file. \ No newline at end of file diff --git a/core-java-modules/core-java-18/src/test/java/com/baeldung/finalization_closeable_cleaner/FinalizationCloseableCleanerUnitTest.java b/core-java-modules/core-java-18/src/test/java/com/baeldung/finalization_closeable_cleaner/FinalizationCloseableCleanerUnitTest.java new file mode 100644 index 0000000000..22ff228227 --- /dev/null +++ b/core-java-modules/core-java-18/src/test/java/com/baeldung/finalization_closeable_cleaner/FinalizationCloseableCleanerUnitTest.java @@ -0,0 +1,36 @@ +package com.baeldung.finalization_closeable_cleaner; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import java.io.IOException; + +import org.junit.Assert; +import org.junit.Test; + +public class FinalizationCloseableCleanerUnitTest { + + @Test + public void givenMyFinalizationResource_whenUsingFinalize_thenShouldClean() { + assertDoesNotThrow(() -> { + MyFinalizableResourceClass mfr = new MyFinalizableResourceClass(); + mfr.getByteLength(); + }); + } + @Test + public void givenMyCleanerResource_whenUsingCleanerAPI_thenShouldClean() { + assertDoesNotThrow(() -> { + try (MyCleanerResourceClass myCleanerResourceClass = new MyCleanerResourceClass()) { + myCleanerResourceClass.useResource(); + } + }); + } + + @Test + public void givenCloseableResource_whenUsingTryWith_thenShouldClose() throws IOException { + int length = 0; + try (MyCloseableResourceClass mcr = new MyCloseableResourceClass()) { + length = mcr.getByteLength(); + } + Assert.assertEquals(20, length); + } +} From 150efcec722ddc89b098202593f0015ab86dde3b Mon Sep 17 00:00:00 2001 From: ACHRAF TAITAI <43656331+achraftt@users.noreply.github.com> Date: Mon, 9 Oct 2023 22:01:20 +0200 Subject: [PATCH 187/193] BAEL-6984: Deprecate URL Public Constructors in Java 20 (#14934) --- .../baeldung/networking/url/UrlUnitTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/url/UrlUnitTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/url/UrlUnitTest.java index 87d9d7a620..ca04263689 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/url/UrlUnitTest.java +++ b/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/url/UrlUnitTest.java @@ -2,10 +2,15 @@ package com.baeldung.networking.url; import static java.util.stream.Collectors.toList; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Map; import org.apache.http.client.utils.URIBuilder; @@ -149,4 +154,24 @@ public class UrlUnitTest { assertEquals("http://baeldung.com:9090/articles?topic=java&version=8", url.toString()); } + @Test + public void givenURI_whenConvertingToURL_thenCorrect() throws IOException, URISyntaxException { + String aURIString = "http://courses.baeldung.com"; + URI uri = new URI(aURIString); + URL url = uri.toURL(); + assertNotNull(url); + assertEquals(aURIString, url.toString()); + } + + @Test + public void givenPath_whenConvertingToURIAndThenURL_thenCorrect() throws IOException, URISyntaxException { + String finalPath = "file:/D:/baeldung/java-url"; + Path path = Paths.get("/baeldung/java-url"); + URI uri = path.toUri(); + URL url = uri.toURL(); + assertNotNull(url); + // Adapt the finalPath value to match your own path + // assertEquals(finalPath, url.toString()); + } + } \ No newline at end of file From 3bd2e7eb3ef9451ce624723f92194d3c293be51e Mon Sep 17 00:00:00 2001 From: Anton Dalagan Date: Mon, 9 Oct 2023 22:05:03 +0200 Subject: [PATCH 188/193] Bael 6962 convert double to float in java (#14936) * Commit 1 - Anton Dalagan Code for Evaluation article. Contains Unit tests, domain class, and App main method. * BAEL-6962 - Created unit test, and updated pom.xml * BAEL-6962 - Removed files unrelated to the article * BAEL-6962 - Added a declartions for float and double in diff class. Updated unit tests. * BAEL-6962 - Made changes into the unit tests. Removed printlns, and updated isinstance with assertequals --- .../FloatDoubleConversionsTest.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsTest.java index 10e9fd4c36..9c6b01e9de 100644 --- a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsTest.java +++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsTest.java @@ -9,25 +9,21 @@ public class FloatDoubleConversionsTest { public void whenDoubleType_thenFloatTypeSuccess(){ double interestRatesYearly = 13.333333333333334; float interest = (float) interestRatesYearly; - System.out.println(interest); //13.333333 - Assert.assertTrue(Float.class.isInstance(interest));//true + Assert.assertEquals(13.333333f, interest, 0.000004f); Double monthlyRates = 2.111111111111112; float rates = monthlyRates.floatValue(); - System.out.println(rates); //2.1111112 - Assert.assertTrue(Float.class.isInstance(rates));//true + Assert.assertEquals(2.1111112f, rates, 0.00000013); } @Test public void whenFloatType_thenDoubleTypeSuccess(){ float gradeAverage =2.05f; double average = gradeAverage; - System.out.println(average); //2.049999952316284 - Assert.assertTrue(Double.class.isInstance(average));//true + Assert.assertEquals(2.05, average, 0.06); Float monthlyRates = 2.1111112f; Double rates = monthlyRates.doubleValue(); - System.out.println(rates); //2.1111112 - Assert.assertTrue(Double.class.isInstance(rates));//true + Assert.assertEquals(2.11111112, rates, 0.0000002);//true } } From a3148b3dd29e283df74e9f47a83826598732ca45 Mon Sep 17 00:00:00 2001 From: Bhaskar Ghosh Dastidar Date: Tue, 10 Oct 2023 01:38:57 +0530 Subject: [PATCH 189/193] [BAEL-7035] improvement to value based class (#14938) Co-authored-by: Bhaskar --- .../main/java/com/baeldung/value_based_class/Point.java | 5 +++++ .../value_based_class/ValueBasedClassUnitTest.java | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-16/src/main/java/com/baeldung/value_based_class/Point.java b/core-java-modules/core-java-16/src/main/java/com/baeldung/value_based_class/Point.java index 13e2238274..a3055985af 100644 --- a/core-java-modules/core-java-16/src/main/java/com/baeldung/value_based_class/Point.java +++ b/core-java-modules/core-java-16/src/main/java/com/baeldung/value_based_class/Point.java @@ -30,6 +30,11 @@ public final class Point { return new Point(x, y, z); } + @Override + public String toString() { + return "Point{" + "x=" + x + ", y=" + y + ", z=" + z + '}'; + } + @Override public boolean equals(Object other) { if (other == null || getClass() != other.getClass()) diff --git a/core-java-modules/core-java-16/src/test/java/com/baeldung/value_based_class/ValueBasedClassUnitTest.java b/core-java-modules/core-java-16/src/test/java/com/baeldung/value_based_class/ValueBasedClassUnitTest.java index 781f368982..fe031a652f 100644 --- a/core-java-modules/core-java-16/src/test/java/com/baeldung/value_based_class/ValueBasedClassUnitTest.java +++ b/core-java-modules/core-java-16/src/test/java/com/baeldung/value_based_class/ValueBasedClassUnitTest.java @@ -1,14 +1,17 @@ package com.baeldung.value_based_class; +import java.util.ArrayList; +import java.util.List; + import org.junit.Assert; import org.junit.Test; public class ValueBasedClassUnitTest { @Test public void givenAutoboxedAndPrimitive_whenCompared_thenReturnEquals() { - int primitive_a = 125; - Integer obj_a = 125; // this is autoboxed - Assert.assertSame(primitive_a, obj_a); + List list = new ArrayList<>(); + list.add(1); // this is autoboxed + Assert.assertEquals(list.get(0), Integer.valueOf(1)); } @Test From a74415a7c7698e6412a7573bbc02062741627fc6 Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Tue, 10 Oct 2023 02:08:53 +0200 Subject: [PATCH 190/193] [rm-linebreaks-inFile] How to Remove Line Breaks From a File in Java (#14917) --- .../RemoveLinebreaksUnitTest.java | 72 +++++++++++++++++++ .../src/test/resources/multiple-line-1.txt | 6 ++ .../src/test/resources/multiple-line-2.txt | 4 ++ 3 files changed, 82 insertions(+) create mode 100644 core-java-modules/core-java-io-5/src/test/java/com/baeldung/rmlinebreaks/RemoveLinebreaksUnitTest.java create mode 100644 core-java-modules/core-java-io-5/src/test/resources/multiple-line-1.txt create mode 100644 core-java-modules/core-java-io-5/src/test/resources/multiple-line-2.txt diff --git a/core-java-modules/core-java-io-5/src/test/java/com/baeldung/rmlinebreaks/RemoveLinebreaksUnitTest.java b/core-java-modules/core-java-io-5/src/test/java/com/baeldung/rmlinebreaks/RemoveLinebreaksUnitTest.java new file mode 100644 index 0000000000..7cfc7ede79 --- /dev/null +++ b/core-java-modules/core-java-io-5/src/test/java/com/baeldung/rmlinebreaks/RemoveLinebreaksUnitTest.java @@ -0,0 +1,72 @@ +package com.baeldung.rmlinebreaks; + +import org.junit.jupiter.api.Test; + +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +public class RemoveLinebreaksUnitTest { + + private Path file1Path() throws Exception { + return Paths.get(this.getClass().getClassLoader().getResource("multiple-line-1.txt").toURI()); + } + + private Path file2Path() throws Exception { + return Paths.get(this.getClass().getClassLoader().getResource("multiple-line-2.txt").toURI()); + } + + @Test + void whenRemovingLineSeparatorFromFile1_thenGetTheExpectedResult() throws Exception { + String content = Files.readString(file1Path(), StandardCharsets.UTF_8); + + String result = content.replace(System.getProperty("line.separator"), ""); + assertEquals("A, B, C, D, E, F", result); + } + + @Test + void whenRemovingLineSeparatorFromFile2_thenNotGetTheExpectedResult() throws Exception { + String content = Files.readString(file2Path(), StandardCharsets.UTF_8); + + String result = content.replace(System.getProperty("line.separator"), ""); + assertNotEquals("A, B, C, D, E, F", result); // <-- NOT equals assertion! + } + + @Test + void whenRemovingAllLinebreaks_thenGetTheExpectedResult() throws Exception { + String content1 = Files.readString(file1Path(), StandardCharsets.UTF_8); + + // file contains CRLF + String content2 = Files.readString(file2Path(), StandardCharsets.UTF_8); + + String result1 = content1.replace("\r", "").replace("\n", ""); + String result2 = content2.replace("\r", "").replace("\n", ""); + + assertEquals("A, B, C, D, E, F", result1); + assertEquals("A, B, C, D, E, F", result2); + + String resultReplaceAll = content2.replaceAll("[\\n\\r]", ""); + assertEquals("A, B, C, D, E, F", resultReplaceAll); + + } + + @Test + void whenUsingReadAllLinesAndJoin_thenGetExpectedResult() throws Exception { + List lines1 = Files.readAllLines(file1Path(), StandardCharsets.UTF_8); + + // file contains CRLF + List lines2 = Files.readAllLines(file2Path(), StandardCharsets.UTF_8); + + String result1 = String.join("", lines1); + String result2 = String.join("", lines2); + + assertEquals("A, B, C, D, E, F", result1); + assertEquals("A, B, C, D, E, F", result2); + } + +} \ No newline at end of file diff --git a/core-java-modules/core-java-io-5/src/test/resources/multiple-line-1.txt b/core-java-modules/core-java-io-5/src/test/resources/multiple-line-1.txt new file mode 100644 index 0000000000..42e87e734e --- /dev/null +++ b/core-java-modules/core-java-io-5/src/test/resources/multiple-line-1.txt @@ -0,0 +1,6 @@ +A, + B, + C, + D, + E, + F diff --git a/core-java-modules/core-java-io-5/src/test/resources/multiple-line-2.txt b/core-java-modules/core-java-io-5/src/test/resources/multiple-line-2.txt new file mode 100644 index 0000000000..4fe5d5f4ed --- /dev/null +++ b/core-java-modules/core-java-io-5/src/test/resources/multiple-line-2.txt @@ -0,0 +1,4 @@ +A, B, + C, + D, E, + F From 91b80094fc7aaad90d161934a7d3fc3322822fd6 Mon Sep 17 00:00:00 2001 From: timis1 <12120641+timis1@users.noreply.github.com> Date: Tue, 10 Oct 2023 13:02:45 +0300 Subject: [PATCH 191/193] JAVA-25517 Upgrade spring-boot-bootstrap to Spring Boot 3 (#14896) --- spring-boot-modules/spring-boot-bootstrap/pom.xml | 15 ++++++++------- .../java/com/baeldung/config/SecurityConfig.java | 12 ++++++------ .../java/com/baeldung/persistence/model/Book.java | 10 +++++----- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/spring-boot-modules/spring-boot-bootstrap/pom.xml b/spring-boot-modules/spring-boot-bootstrap/pom.xml index 4ceae26f60..da16f79a2a 100644 --- a/spring-boot-modules/spring-boot-bootstrap/pom.xml +++ b/spring-boot-modules/spring-boot-bootstrap/pom.xml @@ -9,9 +9,10 @@ Demo project for Spring Boot - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 @@ -47,13 +48,12 @@ io.rest-assured rest-assured - ${rest-assured.version} test - javax.servlet - javax.servlet-api - ${servlet.version} + org.springframework.boot + spring-boot-starter-cloud-connectors + ${spring-boot-cloud-connectors.version} @@ -332,6 +332,7 @@ 4.0.0 Greenwich.RELEASE 1.0.0.RELEASE + 2.2.13.RELEASE \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-bootstrap/src/main/java/com/baeldung/config/SecurityConfig.java b/spring-boot-modules/spring-boot-bootstrap/src/main/java/com/baeldung/config/SecurityConfig.java index ecb21cdf4b..c876e1c3d4 100644 --- a/spring-boot-modules/spring-boot-bootstrap/src/main/java/com/baeldung/config/SecurityConfig.java +++ b/spring-boot-modules/spring-boot-bootstrap/src/main/java/com/baeldung/config/SecurityConfig.java @@ -4,6 +4,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.web.SecurityFilterChain; @Configuration @@ -12,12 +13,11 @@ public class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - http.authorizeRequests() - .anyRequest() - .permitAll() - .and() - .csrf() - .disable(); + http.authorizeHttpRequests(expressionInterceptUrlRegistry -> + expressionInterceptUrlRegistry + .anyRequest() + .permitAll()) + .csrf(AbstractHttpConfigurer::disable); return http.build(); } } diff --git a/spring-boot-modules/spring-boot-bootstrap/src/main/java/com/baeldung/persistence/model/Book.java b/spring-boot-modules/spring-boot-bootstrap/src/main/java/com/baeldung/persistence/model/Book.java index 6be27d4cf0..d599c64567 100644 --- a/spring-boot-modules/spring-boot-bootstrap/src/main/java/com/baeldung/persistence/model/Book.java +++ b/spring-boot-modules/spring-boot-bootstrap/src/main/java/com/baeldung/persistence/model/Book.java @@ -1,10 +1,10 @@ package com.baeldung.persistence.model; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; @Entity public class Book { From 25263d41258b6ce022b5e9577af618b5cb8ee896 Mon Sep 17 00:00:00 2001 From: Thiago dos Santos Hora Date: Tue, 10 Oct 2023 17:13:55 +0200 Subject: [PATCH 192/193] NO-JIRA: Fix docker test for shardingphere @thiagohora (#14704) * [BAEL-4897] Shardingshere * [BAEL-4897] Fixes * NO-JIRA: Fix docker test for shardingphere --- .../OrderServiceManualTest.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 persistence-modules/spring-data-shardingsphere/src/test/java/com/baeldung/shardingsphere/OrderServiceManualTest.java diff --git a/persistence-modules/spring-data-shardingsphere/src/test/java/com/baeldung/shardingsphere/OrderServiceManualTest.java b/persistence-modules/spring-data-shardingsphere/src/test/java/com/baeldung/shardingsphere/OrderServiceManualTest.java new file mode 100644 index 0000000000..895dd52afb --- /dev/null +++ b/persistence-modules/spring-data-shardingsphere/src/test/java/com/baeldung/shardingsphere/OrderServiceManualTest.java @@ -0,0 +1,90 @@ +package com.baeldung.shardingsphere; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.testcontainers.containers.MySQLContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import java.math.BigDecimal; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.time.LocalDate; +import java.util.List; + + +/** + * This Manual test requires: Docker service running. + */ +@Testcontainers +@SpringBootTest +class OrderServiceManualTest { + + @Container + static MySQLContainer mySQLContainer1 = new MySQLContainer<>("mysql:8.0.23") + .withDatabaseName("ds0") + .withUsername("test") + .withPassword("test"); + + @Container + static MySQLContainer mySQLContainer2 = new MySQLContainer<>("mysql:8.0.23") + .withDatabaseName("ds1") + .withUsername("test") + .withPassword("test"); + + static { + mySQLContainer2.setPortBindings(List.of("13307:3306")); + mySQLContainer1.setPortBindings(List.of("13306:3306")); + } + @Autowired + private OrderService orderService; + + @Autowired + private OrderRepository orderRepository; + + @DynamicPropertySource + static void setProperties(DynamicPropertyRegistry registry) { + registry.add("spring.jpa.hibernate.ddl-auto", () -> "create-drop"); + } + + @Test + void shouldFindOrderInCorrectShard() { + // given + Order order1 = new Order(1L, 1L, BigDecimal.TEN, Status.PROCESSING, LocalDate.now(), "123 Main St"); + Order order2 = new Order(2L, 2L, BigDecimal.valueOf(12.5), Status.SHIPPED, LocalDate.now(), "456 Main St"); + + // when + Order savedOrder1 = orderService.createOrder(order1); + Order savedOrder2 = orderService.createOrder(order2); + + // then + // Assuming the sharding strategy is based on the order id, data for order1 should be present only in ds0 + // and data for order2 should be present only in ds1 + Assertions.assertThat(orderService.getOrder(savedOrder1.getOrderId())).isEqualTo(savedOrder1); + Assertions.assertThat(orderService.getOrder(savedOrder2.getOrderId())).isEqualTo(savedOrder2); + + // Verify that the orders are not present in the wrong shards. + // You would need to implement these methods in your OrderService. + // They should use a JdbcTemplate or EntityManager to execute SQL directly against each shard. + Assertions.assertThat(assertOrderInShard(savedOrder1, mySQLContainer2)).isTrue(); + Assertions.assertThat(assertOrderInShard(savedOrder2, mySQLContainer1)).isTrue(); + } + + private boolean assertOrderInShard(Order order, MySQLContainer container) { + try (Connection conn = DriverManager.getConnection(container.getJdbcUrl(), container.getUsername(), container.getPassword())) { + PreparedStatement stmt = conn.prepareStatement("SELECT * FROM `order` WHERE order_id = ?"); + stmt.setLong(1, order.getOrderId()); + ResultSet rs = stmt.executeQuery(); + return rs.next(); + } catch (SQLException ex) { + throw new RuntimeException("Error querying order in shard", ex); + } + } +} From d5b2f61ea084112760fcb8d8ec5ba22cb4f754b7 Mon Sep 17 00:00:00 2001 From: lucaCambi77 Date: Wed, 11 Oct 2023 03:35:10 +0200 Subject: [PATCH 193/193] BAEL-6913 - Rotate array in java (#14861) * feat: rotate array in java * fix: When to when --- .../algorithms/rotatearray/RotateArray.java | 102 ++++++++++++++ .../rotatearray/RotateArrayUnitTest.java | 124 ++++++++++++++++++ 2 files changed, 226 insertions(+) create mode 100644 algorithms-modules/algorithms-miscellaneous-7/src/main/java/com/baeldung/algorithms/rotatearray/RotateArray.java create mode 100644 algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/rotatearray/RotateArrayUnitTest.java diff --git a/algorithms-modules/algorithms-miscellaneous-7/src/main/java/com/baeldung/algorithms/rotatearray/RotateArray.java b/algorithms-modules/algorithms-miscellaneous-7/src/main/java/com/baeldung/algorithms/rotatearray/RotateArray.java new file mode 100644 index 0000000000..36490d4899 --- /dev/null +++ b/algorithms-modules/algorithms-miscellaneous-7/src/main/java/com/baeldung/algorithms/rotatearray/RotateArray.java @@ -0,0 +1,102 @@ +package com.baeldung.algorithms.rotatearray; + +/** + * To speed up the rotation, we narrow k rotations to the remainder of k divided by the array length, or k module the array length. + * Therefore, a large rotation number will be translated into the relative smallest rotation. + * All solutions replace the original array, although they might use an extra array to compute the rotation. + */ +public class RotateArray { + + private RotateArray() { + throw new IllegalStateException("Rotate array algorithm utility methods class"); + } + + /** + * + * @param arr array to apply rotation to + * @param k number of rotations + */ + public static void bruteForce(int[] arr, int k) { + checkInvalidInput(arr, k); + + k %= arr.length; + int temp; + int previous; + for (int i = 0; i < k; i++) { + previous = arr[arr.length - 1]; + for (int j = 0; j < arr.length; j++) { + temp = arr[j]; + arr[j] = previous; + previous = temp; + } + } + } + + /** + * + * @param arr array to apply rotation to + * @param k number of rotations + */ + public static void withExtraArray(int[] arr, int k) { + checkInvalidInput(arr, k); + + int[] extraArray = new int[arr.length]; + for (int i = 0; i < arr.length; i++) { + extraArray[(i + k) % arr.length] = arr[i]; + } + System.arraycopy(extraArray, 0, arr, 0, arr.length); + } + + /** + * + * @param arr array to apply rotation to + * @param k number of rotations + */ + public static void cyclicReplacement(int[] arr, int k) { + checkInvalidInput(arr, k); + + k = k % arr.length; + int count = 0; + for (int start = 0; count < arr.length; start++) { + int current = start; + int prev = arr[start]; + do { + int next = (current + k) % arr.length; + int temp = arr[next]; + arr[next] = prev; + prev = temp; + current = next; + count++; + } while (start != current); + } + } + + /** + * + * @param arr array to apply rotation to + * @param k number of rotations + */ + public static void reverse(int[] arr, int k) { + checkInvalidInput(arr, k); + + k %= arr.length; + reverse(arr, 0, arr.length - 1); + reverse(arr, 0, k - 1); + reverse(arr, k, arr.length - 1); + } + + private static void reverse(int[] nums, int start, int end) { + while (start < end) { + int temp = nums[start]; + nums[start] = nums[end]; + nums[end] = temp; + start++; + end--; + } + } + + private static void checkInvalidInput(int[] arr, int rotation) { + if (rotation < 1 || arr == null) + throw new IllegalArgumentException("Rotation must be greater than zero or array must be not null"); + } +} diff --git a/algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/rotatearray/RotateArrayUnitTest.java b/algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/rotatearray/RotateArrayUnitTest.java new file mode 100644 index 0000000000..4a98acdb75 --- /dev/null +++ b/algorithms-modules/algorithms-miscellaneous-7/src/test/java/com/baeldung/algorithms/rotatearray/RotateArrayUnitTest.java @@ -0,0 +1,124 @@ +package com.baeldung.algorithms.rotatearray; + +import static com.baeldung.algorithms.rotatearray.RotateArray.bruteForce; +import static com.baeldung.algorithms.rotatearray.RotateArray.cyclicReplacement; +import static com.baeldung.algorithms.rotatearray.RotateArray.reverse; +import static com.baeldung.algorithms.rotatearray.RotateArray.withExtraArray; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +class RotateArrayUnitTest { + + private final int[] arr = { 1, 2, 3, 4, 5, 6 }; + private final int rotationLtArrayLength = 1; + private final int rotationGtArrayLength = arr.length + 2; + private final int[] ltArrayLengthRotation = { 6, 1, 2, 3, 4, 5 }; + private final int[] gtArrayLengthRotation = { 5, 6, 1, 2, 3, 4 }; + + @Test + void givenInputArray_whenNoRotationOrEmptyArray_thenThrowIllegalArgumentException() { + final int noRotation = 0; + final int someRotation = arr.length - 1; + + assertThrows(IllegalArgumentException.class, () -> bruteForce(arr, noRotation)); + assertThrows(IllegalArgumentException.class, () -> withExtraArray(arr, noRotation)); + assertThrows(IllegalArgumentException.class, () -> cyclicReplacement(arr, noRotation)); + assertThrows(IllegalArgumentException.class, () -> reverse(arr, noRotation)); + + assertThrows(IllegalArgumentException.class, () -> bruteForce(null, someRotation)); + assertThrows(IllegalArgumentException.class, () -> withExtraArray(null, someRotation)); + assertThrows(IllegalArgumentException.class, () -> cyclicReplacement(null, someRotation)); + assertThrows(IllegalArgumentException.class, () -> reverse(null, someRotation)); + } + + @Test + void givenInputArray_whenUseBruteForceRotationLtArrayLength_thenRotateArrayOk() { + + bruteForce(arr, rotationLtArrayLength); + assertArrayEquals(ltArrayLengthRotation, arr); + } + + @Test + void givenInputArray_whenUseBruteForceRotationGtArrayLength_thenRotateArrayOk() { + + bruteForce(arr, rotationGtArrayLength); + assertArrayEquals(gtArrayLengthRotation, arr); + } + + @Test + void givenInputArray_whenUseBruteForceRotationEqArrayLength_thenDoNothing() { + int[] expected = arr.clone(); + + bruteForce(arr, arr.length); + assertArrayEquals(expected, arr); + } + + @Test + void givenInputArray_whenUseExtraArrayRotationLtArrayLength_thenRotateArrayOk() { + + withExtraArray(arr, rotationLtArrayLength); + assertArrayEquals(ltArrayLengthRotation, arr); + } + + @Test + void givenInputArray_whenUseExtraArrayRotationGtArrayLength_thenRotateArrayOk() { + + withExtraArray(arr, rotationGtArrayLength); + assertArrayEquals(gtArrayLengthRotation, arr); + } + + @Test + void givenInputArray_whenUseExtraArrayWithRotationEqArrayLength_thenDoNothing() { + int[] clone = arr.clone(); + + withExtraArray(arr, arr.length); + assertArrayEquals(clone, arr); + } + + @Test + void givenInputArray_whenUseCyclicReplacementRotationLtArrayLength_thenRotateArrayOk() { + + cyclicReplacement(arr, rotationLtArrayLength); + assertArrayEquals(ltArrayLengthRotation, arr); + } + + @Test + void givenInputArray_whenUseCyclicReplacementRotationGtArrayLength_thenRotateArrayOk() { + + cyclicReplacement(arr, rotationGtArrayLength); + assertArrayEquals(gtArrayLengthRotation, arr); + } + + @Test + void givenInputArray_whenUseCyclicReplacementRotationEqArrayLength_thenDoNothing() { + int[] clone = arr.clone(); + + cyclicReplacement(arr, arr.length); + assertArrayEquals(clone, arr); + } + + @Test + void givenInputArray_whenUseReverseRotationLtArrayLength_thenRotateArrayOk() { + + reverse(arr, rotationLtArrayLength); + assertArrayEquals(ltArrayLengthRotation, arr); + } + + @Test + void givenInputArray_whenUseReverseRotationGtArrayLength_thenRotateArrayOk() { + + reverse(arr, rotationGtArrayLength); + assertArrayEquals(gtArrayLengthRotation, arr); + } + + @Test + void givenInputArray_whenUseReverseRotationEqArrayLength_thenDoNothing() { + + int[] clone = arr.clone(); + + reverse(arr, arr.length); + assertArrayEquals(clone, arr); + } +}