diff --git a/httpclient-2/.gitignore b/apache-httpclient-2/.gitignore similarity index 100% rename from httpclient-2/.gitignore rename to apache-httpclient-2/.gitignore diff --git a/httpclient-2/README.md b/apache-httpclient-2/README.md similarity index 85% rename from httpclient-2/README.md rename to apache-httpclient-2/README.md index 2e101a0609..45f1e41637 100644 --- a/httpclient-2/README.md +++ b/apache-httpclient-2/README.md @@ -1,6 +1,6 @@ -## HttpClient 4.x +## Apache HttpClient -This module contains articles about HttpClient 4.x +This module contains articles about Apache HttpClient ### The Course @@ -14,4 +14,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Enabling Logging for Apache HttpClient](https://www.baeldung.com/apache-httpclient-enable-logging) - [Expand Shortened URLs with Apache HttpClient](https://www.baeldung.com/apache-httpclient-expand-url) - [Apache HttpClient vs. CloseableHttpClient](https://www.baeldung.com/apache-httpclient-vs-closeablehttpclient) -- More articles: [[<-- prev]](../httpclient) +- More articles: [[<-- prev]](../apache-httpclient) diff --git a/httpclient-2/pom.xml b/apache-httpclient-2/pom.xml similarity index 96% rename from httpclient-2/pom.xml rename to apache-httpclient-2/pom.xml index f2da238494..c5b8195472 100644 --- a/httpclient-2/pom.xml +++ b/apache-httpclient-2/pom.xml @@ -3,9 +3,9 @@ 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 - httpclient-2 + apache-httpclient-2 0.1-SNAPSHOT - httpclient-2 + apache-httpclient-2 com.baeldung @@ -74,7 +74,7 @@ - httpclient-2 + apache-httpclient-2 src/main/resources diff --git a/httpclient-2/src/main/java/com/baeldung/tlsversion/ClientTlsVersionExamples.java b/apache-httpclient-2/src/main/java/com/baeldung/tlsversion/ClientTlsVersionExamples.java similarity index 100% rename from httpclient-2/src/main/java/com/baeldung/tlsversion/ClientTlsVersionExamples.java rename to apache-httpclient-2/src/main/java/com/baeldung/tlsversion/ClientTlsVersionExamples.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/cookies/HttpClientGettingCookieValueUnitTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/expandurl/HttpClientExpandUrlLiveTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/expandurl/HttpClientExpandUrlLiveTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/expandurl/HttpClientExpandUrlLiveTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/expandurl/HttpClientExpandUrlLiveTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/ApacheHttpClientUnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/ApacheHttpClientUnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/ApacheHttpClientUnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/ApacheHttpClientUnitTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/GetRequestMockServer.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/GetRequestMockServer.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/GetRequestMockServer.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/httpclient/GetRequestMockServer.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClientUnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClientUnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClientUnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClientUnitTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpClientUnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpClientUnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpClientUnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpClientUnitTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpUrlConnectionUnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpUrlConnectionUnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpUrlConnectionUnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpUrlConnectionUnitTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringRestTemplateUnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringRestTemplateUnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringRestTemplateUnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringRestTemplateUnitTest.java diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringWebClientUnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringWebClientUnitTest.java similarity index 100% rename from httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringWebClientUnitTest.java rename to apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/SpringWebClientUnitTest.java diff --git a/httpclient-2/src/test/resources/logback.xml b/apache-httpclient-2/src/test/resources/logback.xml similarity index 100% rename from httpclient-2/src/test/resources/logback.xml rename to apache-httpclient-2/src/test/resources/logback.xml diff --git a/httpclient/.gitignore b/apache-httpclient/.gitignore similarity index 100% rename from httpclient/.gitignore rename to apache-httpclient/.gitignore diff --git a/httpclient/README.md b/apache-httpclient/README.md similarity index 80% rename from httpclient/README.md rename to apache-httpclient/README.md index ea3bc28572..338b416df1 100644 --- a/httpclient/README.md +++ b/apache-httpclient/README.md @@ -1,6 +1,6 @@ -## HttpClient 4.x +## Apache HttpClient -This module contains articles about HttpClient 4.x +This module contains articles about Apache HttpClient ### The Course @@ -13,8 +13,8 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Multipart Upload with Apache HttpClient](https://www.baeldung.com/httpclient-multipart-upload) - [Apache HttpAsyncClient Tutorial](https://www.baeldung.com/httpasyncclient-tutorial) - [Apache HttpClient Tutorial](https://www.baeldung.com/httpclient-guide) -- [Advanced HttpClient Configuration](https://www.baeldung.com/httpclient-advanced-config) +- [Advanced Apache HttpClient Configuration](https://www.baeldung.com/httpclient-advanced-config) - [Apache HttpClient – Do Not Follow Redirects](https://www.baeldung.com/httpclient-stop-follow-redirect) - [Custom User-Agent in Apache HttpClient](https://www.baeldung.com/httpclient-user-agent-header) - [Apache HttpClient Connection Management](https://www.baeldung.com/httpclient-connection-management) -- More articles: [[next -->]](../httpclient-2) +- More articles: [[next -->]](../apache-httpclient-2) diff --git a/httpclient/pom.xml b/apache-httpclient/pom.xml similarity index 95% rename from httpclient/pom.xml rename to apache-httpclient/pom.xml index b69981fb13..26eb319ac0 100644 --- a/httpclient/pom.xml +++ b/apache-httpclient/pom.xml @@ -3,9 +3,9 @@ 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 - httpclient + apache-httpclient 0.1-SNAPSHOT - httpclient + apache-httpclient com.baeldung @@ -63,7 +63,7 @@ - httpclient + apache-httpclient src/main/resources diff --git a/httpclient/src/main/resources/logback.xml b/apache-httpclient/src/main/resources/logback.xml similarity index 100% rename from httpclient/src/main/resources/logback.xml rename to apache-httpclient/src/main/resources/logback.xml diff --git a/httpclient/src/main/resources/temp.txt b/apache-httpclient/src/main/resources/temp.txt similarity index 100% rename from httpclient/src/main/resources/temp.txt rename to apache-httpclient/src/main/resources/temp.txt diff --git a/httpclient/src/test/java/com/baeldung/httpclient/HttpAsyncClientLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/HttpAsyncClientLiveTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/HttpAsyncClientLiveTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/HttpAsyncClientLiveTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/HttpClientMultipartLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/HttpClientMultipartLiveTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/HttpClientMultipartLiveTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/HttpClientMultipartLiveTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/HttpClientRedirectLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/HttpClientRedirectLiveTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/HttpClientRedirectLiveTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/HttpClientRedirectLiveTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/ResponseUtil.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/ResponseUtil.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/ResponseUtil.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/ResponseUtil.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/advancedconfig/HttpClientAdvancedConfigurationIntegrationTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/advancedconfig/HttpClientAdvancedConfigurationIntegrationTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/advancedconfig/HttpClientAdvancedConfigurationIntegrationTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/advancedconfig/HttpClientAdvancedConfigurationIntegrationTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientBasicPostLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientBasicPostLiveTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientBasicPostLiveTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientBasicPostLiveTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientLiveTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientLiveTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientLiveTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientSandboxLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientSandboxLiveTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientSandboxLiveTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/base/HttpClientSandboxLiveTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/conn/IdleConnectionMonitorThread.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/conn/IdleConnectionMonitorThread.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/conn/IdleConnectionMonitorThread.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/conn/IdleConnectionMonitorThread.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/conn/MultiHttpClientConnThread.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/conn/MultiHttpClientConnThread.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/conn/MultiHttpClientConnThread.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/conn/MultiHttpClientConnThread.java diff --git a/httpclient/src/test/java/com/baeldung/httpclient/conn/TesterVersion_MultiHttpClientConnThread.java b/apache-httpclient/src/test/java/com/baeldung/httpclient/conn/TesterVersion_MultiHttpClientConnThread.java similarity index 100% rename from httpclient/src/test/java/com/baeldung/httpclient/conn/TesterVersion_MultiHttpClientConnThread.java rename to apache-httpclient/src/test/java/com/baeldung/httpclient/conn/TesterVersion_MultiHttpClientConnThread.java diff --git a/httpclient/src/test/resources/.gitignore b/apache-httpclient/src/test/resources/.gitignore similarity index 100% rename from httpclient/src/test/resources/.gitignore rename to apache-httpclient/src/test/resources/.gitignore diff --git a/httpclient/src/test/resources/test.in b/apache-httpclient/src/test/resources/test.in similarity index 100% rename from httpclient/src/test/resources/test.in rename to apache-httpclient/src/test/resources/test.in diff --git a/httpclient/src/test/resources/uploads/image.jpg b/apache-httpclient/src/test/resources/uploads/image.jpg similarity index 100% rename from httpclient/src/test/resources/uploads/image.jpg rename to apache-httpclient/src/test/resources/uploads/image.jpg diff --git a/httpclient/src/test/resources/uploads/sandbox.txt b/apache-httpclient/src/test/resources/uploads/sandbox.txt similarity index 100% rename from httpclient/src/test/resources/uploads/sandbox.txt rename to apache-httpclient/src/test/resources/uploads/sandbox.txt diff --git a/httpclient/src/test/resources/uploads/temp.txt b/apache-httpclient/src/test/resources/uploads/temp.txt similarity index 100% rename from httpclient/src/test/resources/uploads/temp.txt rename to apache-httpclient/src/test/resources/uploads/temp.txt diff --git a/httpclient/src/test/resources/uploads/zipFile.zip b/apache-httpclient/src/test/resources/uploads/zipFile.zip similarity index 100% rename from httpclient/src/test/resources/uploads/zipFile.zip rename to apache-httpclient/src/test/resources/uploads/zipFile.zip diff --git a/aws-app-sync/README.md b/aws-modules/aws-app-sync/README.md similarity index 100% rename from aws-app-sync/README.md rename to aws-modules/aws-app-sync/README.md diff --git a/aws-app-sync/pom.xml b/aws-modules/aws-app-sync/pom.xml similarity index 96% rename from aws-app-sync/pom.xml rename to aws-modules/aws-app-sync/pom.xml index b759de4a72..8d7d90e631 100644 --- a/aws-app-sync/pom.xml +++ b/aws-modules/aws-app-sync/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/aws-app-sync/src/main/java/com/baeldung/awsappsync/AppSyncClientHelper.java b/aws-modules/aws-app-sync/src/main/java/com/baeldung/awsappsync/AppSyncClientHelper.java similarity index 100% rename from aws-app-sync/src/main/java/com/baeldung/awsappsync/AppSyncClientHelper.java rename to aws-modules/aws-app-sync/src/main/java/com/baeldung/awsappsync/AppSyncClientHelper.java diff --git a/aws-app-sync/src/main/java/com/baeldung/awsappsync/AwsAppSyncApplication.java b/aws-modules/aws-app-sync/src/main/java/com/baeldung/awsappsync/AwsAppSyncApplication.java similarity index 100% rename from aws-app-sync/src/main/java/com/baeldung/awsappsync/AwsAppSyncApplication.java rename to aws-modules/aws-app-sync/src/main/java/com/baeldung/awsappsync/AwsAppSyncApplication.java diff --git a/aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationUnitTest.java b/aws-modules/aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationUnitTest.java similarity index 100% rename from aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationUnitTest.java rename to aws-modules/aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationUnitTest.java diff --git a/aws-lambda/.gitignore b/aws-modules/aws-lambda/.gitignore similarity index 100% rename from aws-lambda/.gitignore rename to aws-modules/aws-lambda/.gitignore diff --git a/aws-lambda/README.md b/aws-modules/aws-lambda/README.md similarity index 73% rename from aws-lambda/README.md rename to aws-modules/aws-lambda/README.md index 0ae188fc97..a845c5835e 100644 --- a/aws-lambda/README.md +++ b/aws-modules/aws-lambda/README.md @@ -3,7 +3,9 @@ This module contains articles about AWS Lambda ### Relevant Articles: +- [A Basic AWS Lambda Example With Java](https://www.baeldung.com/java-aws-lambda) - [Using AWS Lambda with API Gateway](https://www.baeldung.com/aws-lambda-api-gateway) - [Introduction to AWS Serverless Application Model](https://www.baeldung.com/aws-serverless) - [How to Implement Hibernate in an AWS Lambda Function in Java](https://www.baeldung.com/java-aws-lambda-hibernate) - [Writing an Enterprise-Grade AWS Lambda in Java](https://www.baeldung.com/java-enterprise-aws-lambda) +- [AWS Lambda Using DynamoDB With Java](https://www.baeldung.com/aws-lambda-dynamodb-java) diff --git a/aws-lambda/lambda/pom.xml b/aws-modules/aws-lambda/lambda/pom.xml similarity index 100% rename from aws-lambda/lambda/pom.xml rename to aws-modules/aws-lambda/lambda/pom.xml diff --git a/aws-lambda/lambda/sam-templates/template-implicit.yaml b/aws-modules/aws-lambda/lambda/sam-templates/template-implicit.yaml similarity index 100% rename from aws-lambda/lambda/sam-templates/template-implicit.yaml rename to aws-modules/aws-lambda/lambda/sam-templates/template-implicit.yaml diff --git a/aws-lambda/lambda/sam-templates/template-inline-swagger.yaml b/aws-modules/aws-lambda/lambda/sam-templates/template-inline-swagger.yaml similarity index 100% rename from aws-lambda/lambda/sam-templates/template-inline-swagger.yaml rename to aws-modules/aws-lambda/lambda/sam-templates/template-inline-swagger.yaml diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java diff --git a/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java b/aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java similarity index 100% rename from aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java rename to aws-modules/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java diff --git a/aws-lambda/lambda/src/main/resources/logback.xml b/aws-modules/aws-lambda/lambda/src/main/resources/logback.xml similarity index 100% rename from aws-lambda/lambda/src/main/resources/logback.xml rename to aws-modules/aws-lambda/lambda/src/main/resources/logback.xml diff --git a/aws-lambda/pom.xml b/aws-modules/aws-lambda/pom.xml similarity index 93% rename from aws-lambda/pom.xml rename to aws-modules/aws-lambda/pom.xml index fc655f282d..bdd295c007 100644 --- a/aws-lambda/pom.xml +++ b/aws-modules/aws-lambda/pom.xml @@ -9,7 +9,7 @@ com.baeldung - parent-modules + aws-modules 1.0.0-SNAPSHOT diff --git a/aws-lambda/shipping-tracker/.gitignore b/aws-modules/aws-lambda/shipping-tracker/.gitignore similarity index 100% rename from aws-lambda/shipping-tracker/.gitignore rename to aws-modules/aws-lambda/shipping-tracker/.gitignore diff --git a/aws-lambda/shipping-tracker/ShippingFunction/pom.xml b/aws-modules/aws-lambda/shipping-tracker/ShippingFunction/pom.xml similarity index 100% rename from aws-lambda/shipping-tracker/ShippingFunction/pom.xml rename to aws-modules/aws-lambda/shipping-tracker/ShippingFunction/pom.xml diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java b/aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java similarity index 100% rename from aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java rename to aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Checkin.java b/aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Checkin.java similarity index 100% rename from aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Checkin.java rename to aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Checkin.java diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Consignment.java b/aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Consignment.java similarity index 100% rename from aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Consignment.java rename to aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Consignment.java diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Item.java b/aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Item.java similarity index 100% rename from aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Item.java rename to aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Item.java diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingDao.java b/aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingDao.java similarity index 100% rename from aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingDao.java rename to aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingDao.java diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingService.java b/aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingService.java similarity index 100% rename from aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingService.java rename to aws-modules/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingService.java diff --git a/aws-lambda/shipping-tracker/template.yaml b/aws-modules/aws-lambda/shipping-tracker/template.yaml similarity index 100% rename from aws-lambda/shipping-tracker/template.yaml rename to aws-modules/aws-lambda/shipping-tracker/template.yaml diff --git a/aws-lambda/todo-reminder/ToDoFunction/pom.xml b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/pom.xml similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/pom.xml rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/pom.xml diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/App.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/App.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/App.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/App.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostApi.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostApi.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostApi.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostApi.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostItem.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostItem.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostItem.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/PostItem.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoApi.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoApi.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoApi.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoApi.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoItem.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoItem.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoItem.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/api/ToDoItem.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Config.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Config.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Config.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Config.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Credentials.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Credentials.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Credentials.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Credentials.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/ExecutionContext.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/ExecutionContext.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/ExecutionContext.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/ExecutionContext.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Services.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Services.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Services.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/config/Services.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/PostService.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/PostService.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/PostService.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/PostService.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/ToDoReaderService.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/ToDoReaderService.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/ToDoReaderService.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/java/com/baeldung/lambda/todo/service/ToDoReaderService.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/resources/configuration.yml b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/resources/configuration.yml similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/resources/configuration.yml rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/resources/configuration.yml diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/main/resources/log4j2.xml b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/resources/log4j2.xml similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/main/resources/log4j2.xml rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/main/resources/log4j2.xml diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/AppTest.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/AppTest.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/AppTest.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/AppTest.java diff --git a/aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/service/ToDoReaderServiceTest.java b/aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/service/ToDoReaderServiceTest.java similarity index 100% rename from aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/service/ToDoReaderServiceTest.java rename to aws-modules/aws-lambda/todo-reminder/ToDoFunction/src/test/java/com/baeldung/lambda/todo/service/ToDoReaderServiceTest.java diff --git a/aws-lambda/todo-reminder/template.yaml b/aws-modules/aws-lambda/todo-reminder/template.yaml similarity index 100% rename from aws-lambda/todo-reminder/template.yaml rename to aws-modules/aws-lambda/todo-reminder/template.yaml diff --git a/aws/.gitignore b/aws-modules/aws-miscellaneous/.gitignore similarity index 100% rename from aws/.gitignore rename to aws-modules/aws-miscellaneous/.gitignore diff --git a/aws-modules/aws-miscellaneous/README.md b/aws-modules/aws-miscellaneous/README.md new file mode 100644 index 0000000000..5be8e6a3f2 --- /dev/null +++ b/aws-modules/aws-miscellaneous/README.md @@ -0,0 +1,10 @@ +## AWS Miscellaneous + +This module contains articles about various Amazon Web Services (AWS) such as EC2, DynamoDB, SQS, RDS + +### Relevant articles + +- [Managing EC2 Instances in Java](https://www.baeldung.com/ec2-java) +- [Integration Testing with a Local DynamoDB Instance](https://www.baeldung.com/dynamodb-local-integration-tests) +- [Managing Amazon SQS Queues in Java](https://www.baeldung.com/aws-queues-java) +- [Guide to AWS Aurora RDS with Java](https://www.baeldung.com/aws-aurora-rds-java) diff --git a/aws/pom.xml b/aws-modules/aws-miscellaneous/pom.xml similarity index 88% rename from aws/pom.xml rename to aws-modules/aws-miscellaneous/pom.xml index a57dd6690e..f05764f10a 100644 --- a/aws/pom.xml +++ b/aws-modules/aws-miscellaneous/pom.xml @@ -3,14 +3,14 @@ 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 - aws + aws-miscellaneous 0.1.0-SNAPSHOT - aws + aws-miscellaneous jar com.baeldung - parent-modules + aws-modules 1.0.0-SNAPSHOT @@ -58,17 +58,6 @@ ${dynamodblocal.version} test - - - org.lucee - jets3t - ${jets3t-version} - - - org.lucee - commons-codec - ${commons-codec-version} - diff --git a/aws/src/main/java/com/baeldung/dynamodb/entity/ProductInfo.java b/aws-modules/aws-miscellaneous/src/main/java/com/baeldung/dynamodb/entity/ProductInfo.java similarity index 100% rename from aws/src/main/java/com/baeldung/dynamodb/entity/ProductInfo.java rename to aws-modules/aws-miscellaneous/src/main/java/com/baeldung/dynamodb/entity/ProductInfo.java diff --git a/aws/src/main/java/com/baeldung/dynamodb/repository/AbstractRepository.java b/aws-modules/aws-miscellaneous/src/main/java/com/baeldung/dynamodb/repository/AbstractRepository.java similarity index 100% rename from aws/src/main/java/com/baeldung/dynamodb/repository/AbstractRepository.java rename to aws-modules/aws-miscellaneous/src/main/java/com/baeldung/dynamodb/repository/AbstractRepository.java diff --git a/aws/src/main/java/com/baeldung/dynamodb/repository/ProductInfoRepository.java b/aws-modules/aws-miscellaneous/src/main/java/com/baeldung/dynamodb/repository/ProductInfoRepository.java similarity index 100% rename from aws/src/main/java/com/baeldung/dynamodb/repository/ProductInfoRepository.java rename to aws-modules/aws-miscellaneous/src/main/java/com/baeldung/dynamodb/repository/ProductInfoRepository.java diff --git a/aws/src/main/java/com/baeldung/ec2/EC2Application.java b/aws-modules/aws-miscellaneous/src/main/java/com/baeldung/ec2/EC2Application.java similarity index 100% rename from aws/src/main/java/com/baeldung/ec2/EC2Application.java rename to aws-modules/aws-miscellaneous/src/main/java/com/baeldung/ec2/EC2Application.java diff --git a/aws/src/main/java/com/baeldung/rds/AWSRDSService.java b/aws-modules/aws-miscellaneous/src/main/java/com/baeldung/rds/AWSRDSService.java similarity index 100% rename from aws/src/main/java/com/baeldung/rds/AWSRDSService.java rename to aws-modules/aws-miscellaneous/src/main/java/com/baeldung/rds/AWSRDSService.java diff --git a/aws/src/main/java/com/baeldung/sqs/SQSApplication.java b/aws-modules/aws-miscellaneous/src/main/java/com/baeldung/sqs/SQSApplication.java similarity index 100% rename from aws/src/main/java/com/baeldung/sqs/SQSApplication.java rename to aws-modules/aws-miscellaneous/src/main/java/com/baeldung/sqs/SQSApplication.java diff --git a/aws/src/main/resources/db.properties b/aws-modules/aws-miscellaneous/src/main/resources/db.properties similarity index 100% rename from aws/src/main/resources/db.properties rename to aws-modules/aws-miscellaneous/src/main/resources/db.properties diff --git a/aws/src/main/resources/logback.xml b/aws-modules/aws-miscellaneous/src/main/resources/logback.xml similarity index 100% rename from aws/src/main/resources/logback.xml rename to aws-modules/aws-miscellaneous/src/main/resources/logback.xml diff --git a/aws/src/test/java/com/baeldung/dynamodb/ProductInfoRepositoryIntegrationTest.java b/aws-modules/aws-miscellaneous/src/test/java/com/baeldung/dynamodb/ProductInfoRepositoryIntegrationTest.java similarity index 100% rename from aws/src/test/java/com/baeldung/dynamodb/ProductInfoRepositoryIntegrationTest.java rename to aws-modules/aws-miscellaneous/src/test/java/com/baeldung/dynamodb/ProductInfoRepositoryIntegrationTest.java diff --git a/aws/src/test/java/com/baeldung/dynamodb/rule/LocalDbCreationRule.java b/aws-modules/aws-miscellaneous/src/test/java/com/baeldung/dynamodb/rule/LocalDbCreationRule.java similarity index 100% rename from aws/src/test/java/com/baeldung/dynamodb/rule/LocalDbCreationRule.java rename to aws-modules/aws-miscellaneous/src/test/java/com/baeldung/dynamodb/rule/LocalDbCreationRule.java diff --git a/aws/src/test/resources/test.properties b/aws-modules/aws-miscellaneous/src/test/resources/test.properties similarity index 100% rename from aws/src/test/resources/test.properties rename to aws-modules/aws-miscellaneous/src/test/resources/test.properties diff --git a/aws-reactive/README.md b/aws-modules/aws-reactive/README.md similarity index 58% rename from aws-reactive/README.md rename to aws-modules/aws-reactive/README.md index 1abf987b52..9164bd0ea6 100644 --- a/aws-reactive/README.md +++ b/aws-modules/aws-reactive/README.md @@ -1,3 +1,7 @@ +## AWS Reactive + +This module contains articles about reactive support with AWS + ### Relevant Articles: - [AWS S3 with Java – Reactive Support](https://www.baeldung.com/java-aws-s3-reactive) diff --git a/aws-reactive/images/rective-upload.png b/aws-modules/aws-reactive/images/rective-upload.png similarity index 100% rename from aws-reactive/images/rective-upload.png rename to aws-modules/aws-reactive/images/rective-upload.png diff --git a/aws-reactive/images/rective-upload.txt b/aws-modules/aws-reactive/images/rective-upload.txt similarity index 100% rename from aws-reactive/images/rective-upload.txt rename to aws-modules/aws-reactive/images/rective-upload.txt diff --git a/aws-reactive/images/thread-per-client.png b/aws-modules/aws-reactive/images/thread-per-client.png similarity index 100% rename from aws-reactive/images/thread-per-client.png rename to aws-modules/aws-reactive/images/thread-per-client.png diff --git a/aws-reactive/images/thread-per-client.txt b/aws-modules/aws-reactive/images/thread-per-client.txt similarity index 100% rename from aws-reactive/images/thread-per-client.txt rename to aws-modules/aws-reactive/images/thread-per-client.txt diff --git a/aws-reactive/pom.xml b/aws-modules/aws-reactive/pom.xml similarity index 98% rename from aws-reactive/pom.xml rename to aws-modules/aws-reactive/pom.xml index 923e1361ab..7a9cefb9d1 100644 --- a/aws-reactive/pom.xml +++ b/aws-modules/aws-reactive/pom.xml @@ -10,7 +10,7 @@ com.baeldung - parent-modules + aws-modules 1.0.0-SNAPSHOT diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadFailedException.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadFailedException.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadFailedException.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadFailedException.java diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadResource.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadResource.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadResource.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/DownloadResource.java diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/ReactiveS3Application.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/ReactiveS3Application.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/ReactiveS3Application.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/ReactiveS3Application.java diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfigurarionProperties.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfigurarionProperties.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfigurarionProperties.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfigurarionProperties.java diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfiguration.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfiguration.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfiguration.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/S3ClientConfiguration.java diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadFailedException.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadFailedException.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadFailedException.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadFailedException.java diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResource.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResource.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResource.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResource.java diff --git a/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResult.java b/aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResult.java similarity index 100% rename from aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResult.java rename to aws-modules/aws-reactive/src/main/java/com/baeldung/aws/reactive/s3/UploadResult.java diff --git a/aws-reactive/src/main/resources/application-minio.yml b/aws-modules/aws-reactive/src/main/resources/application-minio.yml similarity index 100% rename from aws-reactive/src/main/resources/application-minio.yml rename to aws-modules/aws-reactive/src/main/resources/application-minio.yml diff --git a/aws-reactive/src/main/resources/application.yml b/aws-modules/aws-reactive/src/main/resources/application.yml similarity index 100% rename from aws-reactive/src/main/resources/application.yml rename to aws-modules/aws-reactive/src/main/resources/application.yml diff --git a/aws-reactive/src/test/java/com/baeldung/aws/reactive/s3/ReactiveS3ApplicationLiveTest.java b/aws-modules/aws-reactive/src/test/java/com/baeldung/aws/reactive/s3/ReactiveS3ApplicationLiveTest.java similarity index 100% rename from aws-reactive/src/test/java/com/baeldung/aws/reactive/s3/ReactiveS3ApplicationLiveTest.java rename to aws-modules/aws-reactive/src/test/java/com/baeldung/aws/reactive/s3/ReactiveS3ApplicationLiveTest.java diff --git a/aws-reactive/src/test/resources/testimage1.png b/aws-modules/aws-reactive/src/test/resources/testimage1.png similarity index 100% rename from aws-reactive/src/test/resources/testimage1.png rename to aws-modules/aws-reactive/src/test/resources/testimage1.png diff --git a/aws-reactive/src/test/resources/testimage2.png b/aws-modules/aws-reactive/src/test/resources/testimage2.png similarity index 100% rename from aws-reactive/src/test/resources/testimage2.png rename to aws-modules/aws-reactive/src/test/resources/testimage2.png diff --git a/aws-modules/aws-s3/.gitignore b/aws-modules/aws-s3/.gitignore new file mode 100644 index 0000000000..bf11a4cc38 --- /dev/null +++ b/aws-modules/aws-s3/.gitignore @@ -0,0 +1,2 @@ +/target/ +.idea/ \ No newline at end of file diff --git a/aws-modules/aws-s3/README.md b/aws-modules/aws-s3/README.md new file mode 100644 index 0000000000..efebf7d933 --- /dev/null +++ b/aws-modules/aws-s3/README.md @@ -0,0 +1,9 @@ +## AWS S3 + +This module contains articles about Simple Storage Service (S3) on AWS + +### Relevant articles + +- [AWS S3 with Java](https://www.baeldung.com/aws-s3-java) +- [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) \ No newline at end of file diff --git a/aws-modules/aws-s3/pom.xml b/aws-modules/aws-s3/pom.xml new file mode 100644 index 0000000000..65ad6f27f8 --- /dev/null +++ b/aws-modules/aws-s3/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + aws-s3 + 0.1.0-SNAPSHOT + aws-s3 + jar + + + com.baeldung + aws-modules + 1.0.0-SNAPSHOT + + + + + com.amazonaws + aws-java-sdk + ${aws-java-sdk.version} + + + + commons-io + commons-io + ${commons-io.version} + + + + org.lucee + jets3t + ${jets3t-version} + + + org.lucee + commons-codec + ${commons-codec-version} + + + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven-shade-plugin.version} + + false + + + + package + + shade + + + + + + + + + 1.11.290 + 1.10.L001 + 0.9.4.0006L + 3.0.0 + + + \ No newline at end of file diff --git a/aws/src/main/java/com/baeldung/s3/AWSS3Service.java b/aws-modules/aws-s3/src/main/java/com/baeldung/s3/AWSS3Service.java similarity index 100% rename from aws/src/main/java/com/baeldung/s3/AWSS3Service.java rename to aws-modules/aws-s3/src/main/java/com/baeldung/s3/AWSS3Service.java diff --git a/aws/src/main/java/com/baeldung/s3/MultipartUpload.java b/aws-modules/aws-s3/src/main/java/com/baeldung/s3/MultipartUpload.java similarity index 100% rename from aws/src/main/java/com/baeldung/s3/MultipartUpload.java rename to aws-modules/aws-s3/src/main/java/com/baeldung/s3/MultipartUpload.java diff --git a/aws/src/main/java/com/baeldung/s3/S3Application.java b/aws-modules/aws-s3/src/main/java/com/baeldung/s3/S3Application.java similarity index 100% rename from aws/src/main/java/com/baeldung/s3/S3Application.java rename to aws-modules/aws-s3/src/main/java/com/baeldung/s3/S3Application.java diff --git a/aws-modules/aws-s3/src/main/resources/logback.xml b/aws-modules/aws-s3/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/aws-modules/aws-s3/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/aws/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java b/aws-modules/aws-s3/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java similarity index 100% rename from aws/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java rename to aws-modules/aws-s3/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java diff --git a/aws/src/test/java/com/baeldung/s3/AWSS3ServiceIntegrationTest.java b/aws-modules/aws-s3/src/test/java/com/baeldung/s3/AWSS3ServiceIntegrationTest.java similarity index 100% rename from aws/src/test/java/com/baeldung/s3/AWSS3ServiceIntegrationTest.java rename to aws-modules/aws-s3/src/test/java/com/baeldung/s3/AWSS3ServiceIntegrationTest.java diff --git a/aws/src/test/java/com/baeldung/s3/MultipartUploadLiveTest.java b/aws-modules/aws-s3/src/test/java/com/baeldung/s3/MultipartUploadLiveTest.java similarity index 100% rename from aws/src/test/java/com/baeldung/s3/MultipartUploadLiveTest.java rename to aws-modules/aws-s3/src/test/java/com/baeldung/s3/MultipartUploadLiveTest.java diff --git a/aws-modules/pom.xml b/aws-modules/pom.xml new file mode 100644 index 0000000000..4bdffa789a --- /dev/null +++ b/aws-modules/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + aws-modules + aws-modules + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + aws-app-sync + aws-lambda + aws-miscellaneous + aws-reactive + aws-s3 + + + \ No newline at end of file diff --git a/aws/README.md b/aws/README.md deleted file mode 100644 index 9006c2d190..0000000000 --- a/aws/README.md +++ /dev/null @@ -1,15 +0,0 @@ -## AWS - -This module contains articles about Amazon Web Services (AWS) - -### Relevant articles - -- [AWS Lambda Using DynamoDB With Java](https://www.baeldung.com/aws-lambda-dynamodb-java) -- [AWS S3 with Java](https://www.baeldung.com/aws-s3-java) -- [A Basic AWS Lambda Example With Java](https://www.baeldung.com/java-aws-lambda) -- [Managing EC2 Instances in Java](https://www.baeldung.com/ec2-java) -- [Multipart Uploads in Amazon S3 with Java](https://www.baeldung.com/aws-s3-multipart-upload) -- [Integration Testing with a Local DynamoDB Instance](https://www.baeldung.com/dynamodb-local-integration-tests) -- [Using the JetS3t Java Client With Amazon S3](https://www.baeldung.com/jets3t-amazon-s3) -- [Managing Amazon SQS Queues in Java](https://www.baeldung.com/aws-queues-java) -- [Guide to AWS Aurora RDS with Java](https://www.baeldung.com/aws-aurora-rds-java) diff --git a/aws/native-libs/libsqlite4java-linux-amd64-1.0.392.so b/aws/native-libs/libsqlite4java-linux-amd64-1.0.392.so deleted file mode 100644 index 884615789b..0000000000 Binary files a/aws/native-libs/libsqlite4java-linux-amd64-1.0.392.so and /dev/null differ diff --git a/aws/native-libs/libsqlite4java-linux-i386-1.0.392.so b/aws/native-libs/libsqlite4java-linux-i386-1.0.392.so deleted file mode 100644 index 15e7469e38..0000000000 Binary files a/aws/native-libs/libsqlite4java-linux-i386-1.0.392.so and /dev/null differ diff --git a/aws/native-libs/sqlite4java-win32-x64-1.0.392.dll b/aws/native-libs/sqlite4java-win32-x64-1.0.392.dll deleted file mode 100644 index 70d258f29b..0000000000 Binary files a/aws/native-libs/sqlite4java-win32-x64-1.0.392.dll and /dev/null differ diff --git a/aws/native-libs/sqlite4java-win32-x86-1.0.392.dll b/aws/native-libs/sqlite4java-win32-x86-1.0.392.dll deleted file mode 100644 index c988e5a697..0000000000 Binary files a/aws/native-libs/sqlite4java-win32-x86-1.0.392.dll and /dev/null differ diff --git a/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listOfHashMaps/ListOfHashMapsUnitTest.java b/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listOfHashMaps/ListOfHashMapsUnitTest.java new file mode 100644 index 0000000000..e69de29bb2 diff --git a/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listoflists/ListOfListsUnitTest.java b/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listoflists/ListOfListsUnitTest.java new file mode 100644 index 0000000000..321fa475f6 --- /dev/null +++ b/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/listoflists/ListOfListsUnitTest.java @@ -0,0 +1,74 @@ +package com.baeldung.list.listoflists; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.Test; + +public class ListOfListsUnitTest { + + private List> getListOfListsFromCsv() throws URISyntaxException, IOException { + + List lines = Files.readAllLines(Paths.get(getClass().getResource("/listoflists/example.csv") + .toURI())); + List> listOfLists = new ArrayList<>(); + + lines.forEach(line -> { + List innerList = new ArrayList<>(Arrays.asList(line.split(", "))); + listOfLists.add(innerList); + }); + return listOfLists; + } + + private void printListOfLists(List> listOfLists) { + System.out.println("\n List of Lists "); + System.out.println("-------------------------------------"); + listOfLists.forEach(innerList -> { + String line = String.join(", ", innerList); + System.out.println(line); + }); + } + + @Test + void givenCsv_whenInitListOfLists_thenGetExpectedResults() throws URISyntaxException, IOException { + List> listOfLists = getListOfListsFromCsv(); + assertThat(listOfLists).hasSize(3); + assertThat(listOfLists.stream() + .map(List::size) + .collect(Collectors.toSet())).hasSize(1) + .containsExactly(4); + printListOfLists(listOfLists); + } + + @Test + void givenListOfLists_whenRemoveElementFromInnerLists_thenGetExpectedResults() throws URISyntaxException, IOException { + List> listOfLists = getListOfListsFromCsv(); + + listOfLists.forEach(innerList -> innerList.remove("Delete Me")); + assertThat(listOfLists.stream() + .map(List::size) + .collect(Collectors.toSet())).hasSize(1) + .containsExactly(3); + + printListOfLists(listOfLists); + } + + @Test + void givenListOfLists_whenAddNewInnerList_thenGetExpectedResults() throws URISyntaxException, IOException { + List> listOfLists = getListOfListsFromCsv(); + List newList = new ArrayList<>(Arrays.asList("Slack", "Zoom", "Microsoft Teams", "Telegram")); + listOfLists.add(2, newList); + + assertThat(listOfLists).hasSize(4); + assertThat(listOfLists.get(2)).containsExactly("Slack", "Zoom", "Microsoft Teams", "Telegram"); + printListOfLists(listOfLists); + } +} diff --git a/core-java-modules/core-java-collections-list-3/src/test/resources/listoflists/example.csv b/core-java-modules/core-java-collections-list-3/src/test/resources/listoflists/example.csv new file mode 100644 index 0000000000..e275848e19 --- /dev/null +++ b/core-java-modules/core-java-collections-list-3/src/test/resources/listoflists/example.csv @@ -0,0 +1,3 @@ +Linux, Microsoft Windows, Mac OS, Delete Me +Kotlin, Delete Me, Java, Python +Delete Me, Mercurial, Git, Subversion \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/FixedTimeTask.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/FixedTimeTask.java new file mode 100644 index 0000000000..9ac20d73dd --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/FixedTimeTask.java @@ -0,0 +1,28 @@ +package com.baeldung.concurrent.stopexecution; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.TimeUnit; + +public class FixedTimeTask implements Runnable { + + private static final Logger LOG = LoggerFactory.getLogger(FixedTimeTask.class); + + final int fixedTime; // milliseconds + + public FixedTimeTask(int fixedTime) { + this.fixedTime = fixedTime; + } + + @Override + public void run() { + LOG.info(fixedTime + " milliseconds running task"); + try { + TimeUnit.MILLISECONDS.sleep(fixedTime); + } catch (InterruptedException e) { + LOG.info("interrupted"); + } + LOG.info("finished"); + } +} diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/LongRunningTask.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/LongRunningTask.java new file mode 100644 index 0000000000..7167859308 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/LongRunningTask.java @@ -0,0 +1,21 @@ +package com.baeldung.concurrent.stopexecution; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LongRunningTask implements Runnable { + + private static final Logger LOG = LoggerFactory.getLogger(LongRunningTask.class); + + @Override + public void run() { + LOG.info("running"); + for (int i = 0; i < Long.MAX_VALUE; i++) { + if (Thread.interrupted()) { + LOG.info("stopping"); + return; + } + } + LOG.info("finished"); + } +} diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/Step.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/Step.java new file mode 100644 index 0000000000..d6d8c8c036 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/Step.java @@ -0,0 +1,23 @@ +package com.baeldung.concurrent.stopexecution; + +import java.util.Random; + +public class Step { + + private static int MAX = Integer.MAX_VALUE / 2; + int number; + + public Step(int number) { + this.number = number; + } + + public void perform() throws InterruptedException { + Random rnd = new Random(); + int target = rnd.nextInt(MAX); + while (rnd.nextInt(MAX) != target) { + if (Thread.interrupted()) { + throw new InterruptedException(); + } + } + } +} diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/SteppedTask.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/SteppedTask.java new file mode 100644 index 0000000000..5b2b0c445a --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/SteppedTask.java @@ -0,0 +1,31 @@ +package com.baeldung.concurrent.stopexecution; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +public class SteppedTask implements Runnable { + private static final Logger LOG = LoggerFactory.getLogger(SteppedTask.class); + + private List steps; + + public SteppedTask(List steps) { + this.steps = steps; + } + + @Override + public void run() { + LOG.info("running stepped process"); + for (Step step : steps) { + LOG.info("running step " + step.number); + try { + step.perform(); + } catch (InterruptedException e) { + LOG.info("interrupting task"); + return; + } + } + LOG.info("stepped process finished"); + } +} diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/StoppingExecution.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/StoppingExecution.java new file mode 100644 index 0000000000..ac4af8adc4 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/StoppingExecution.java @@ -0,0 +1,95 @@ +package com.baeldung.concurrent.stopexecution; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.Timer; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class StoppingExecution { + + private static final Logger LOG = LoggerFactory.getLogger(StoppingExecution.class); + + public static void main(String[] args) { + StoppingExecution.testUsingLoop(); + StoppingExecution.testUsingTimer(); + StoppingExecution.testUsingFuture(); + StoppingExecution.testScheduledExecutor(); + StoppingExecution.testSteppedProcess(); + } + + public static void testUsingLoop() { + LOG.info("using loop started"); + long start = System.currentTimeMillis(); + long end = start + 30 * 1000; // 30 seconds + while (System.currentTimeMillis() < end) { + LOG.info("running task"); + new FixedTimeTask(7 * 1000).run(); // 7 seconds + } + LOG.info("using loop ended"); + } + + public static void testUsingTimer() { + LOG.info("using timer started"); + Thread thread = new Thread(new LongRunningTask()); + thread.start(); + + Timer timer = new Timer(); + TimeOutTask timeOutTask = new TimeOutTask(thread, timer); + + LOG.info("scheduling timeout in 3 seconds"); + timer.schedule(timeOutTask, 3000); + LOG.info("using timer ended"); + } + + public static void testUsingFuture() { + LOG.info("using future started"); + ExecutorService executor = Executors.newSingleThreadExecutor(); + Future future = executor.submit(new LongRunningTask()); + try { + LOG.info("future get with 7 seconds timeout"); + future.get(7, TimeUnit.SECONDS); + } catch (TimeoutException e) { + LOG.info("future timeout"); + future.cancel(true); + } catch (Exception e) { + LOG.info("future exception", e); + } finally { + executor.shutdownNow(); + } + LOG.info("using future ended"); + } + + public static void testScheduledExecutor() { + LOG.info("using future schedule executor started"); + + ScheduledExecutorService executor = Executors.newScheduledThreadPool(2); + Future future = executor.submit(new LongRunningTask()); + Runnable cancelTask = () -> future.cancel(true); + + LOG.info("cancel task in 3 seconds"); + executor.schedule(cancelTask, 3000, TimeUnit.MILLISECONDS); + executor.shutdown(); + LOG.info("using future schedule executor ended"); + } + + public static void testSteppedProcess() { + List steps = Stream.of(new Step(1), new Step(2), new Step(3), new Step(4)).collect(Collectors.toList()); + + LOG.info("stepped process started"); + Thread thread = new Thread(new SteppedTask(steps)); + thread.start(); + + Timer timer = new Timer(); + TimeOutTask timeOutTask = new TimeOutTask(thread, timer); + timer.schedule(timeOutTask, 10000); + } +} diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/TimeOutTask.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/TimeOutTask.java new file mode 100644 index 0000000000..e27e64476e --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/TimeOutTask.java @@ -0,0 +1,22 @@ +package com.baeldung.concurrent.stopexecution; + +import java.util.Timer; +import java.util.TimerTask; + +public class TimeOutTask extends TimerTask { + private Thread thread; + private Timer timer; + + public TimeOutTask(Thread thread, Timer timer) { + this.thread = thread; + this.timer = timer; + } + + @Override + public void run() { + if (thread != null && thread.isAlive()) { + thread.interrupt(); + timer.cancel(); + } + } +} diff --git a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/FixedTimeTaskUnitTest.java b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/FixedTimeTaskUnitTest.java new file mode 100644 index 0000000000..bbb8d0571a --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/FixedTimeTaskUnitTest.java @@ -0,0 +1,18 @@ +package com.baeldung.concurrent.stopexecution; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class FixedTimeTaskUnitTest { + + @Test + public void run() throws InterruptedException { + long start = System.currentTimeMillis(); + Thread thread = new Thread(new FixedTimeTask(10)); + thread.start(); + thread.join(); + long end = System.currentTimeMillis(); + assertTrue(end - start >= 10); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/LongRunningTaskUnitTest.java b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/LongRunningTaskUnitTest.java new file mode 100644 index 0000000000..c9bcb75e6d --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/LongRunningTaskUnitTest.java @@ -0,0 +1,19 @@ +package com.baeldung.concurrent.stopexecution; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class LongRunningTaskUnitTest { + + @Test + public void run() { + Thread thread = new Thread(new LongRunningTask()); + thread.start(); + assertTrue(thread.isAlive()); + + thread.interrupt(); + assertTrue(thread.isInterrupted()); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/SteppedTaskUnitTest.java b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/SteppedTaskUnitTest.java new file mode 100644 index 0000000000..ab9ac2732a --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/SteppedTaskUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.concurrent.stopexecution; + +import org.junit.Test; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.junit.Assert.*; + +public class SteppedTaskUnitTest { + + @Test + public void run() throws InterruptedException { + List steps = Stream.of( + new Step(1), + new Step(2), + new Step(3)) + .collect(Collectors.toList()); + + Thread thread = new Thread(new SteppedTask(steps)); + thread.start(); + thread.interrupt(); + thread.join(); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/TimeOutTaskUnitTest.java b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/TimeOutTaskUnitTest.java new file mode 100644 index 0000000000..39ec9f7d26 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/stopexecution/TimeOutTaskUnitTest.java @@ -0,0 +1,20 @@ +package com.baeldung.concurrent.stopexecution; + +import org.junit.Test; + +import java.util.Timer; + +import static org.junit.Assert.assertTrue; + +public class TimeOutTaskUnitTest { + + @Test + public void run() { + Thread thread = new Thread(new LongRunningTask()); + Timer timer = new Timer(); + TimeOutTask timeOutTask = new TimeOutTask(thread, timer); + thread.start(); + timeOutTask.run(); + assertTrue(thread.isInterrupted()); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-io-4/src/test/java/com/baeldung/scanner/ScannerUnitTest.java b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/scanner/ScannerUnitTest.java new file mode 100644 index 0000000000..f11f3d032d --- /dev/null +++ b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/scanner/ScannerUnitTest.java @@ -0,0 +1,34 @@ +package com.baeldung.scanner; + +import org.junit.Test; + +import java.util.*; +import java.util.regex.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ScannerUnitTest { + @Test public void scannerSkipUsingPattern() { + String str = "Java scanner skip tutorial"; + // Instantiates Scanner + Scanner sc = new Scanner(str); + // By using skip(Pattern) method is to skip that meets the given pattern + sc.skip(Pattern.compile(".ava")); + assertEquals(sc.nextLine(), " scanner skip tutorial"); + // Scanner closed + sc.close(); + } + + @Test public void scannerSkipUsingStringPattern() { + String str = "Java scanner skip tutorial"; + // Instantiates Scanner + Scanner sc = new Scanner(str); + // By using skip(String) method is to skip that meets the given + // pattern constructed from the given String + sc.skip("Java"); + assertEquals(sc.nextLine(), " scanner skip tutorial"); + + // Scanner closed + sc.close(); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-networking-3/src/main/java/com/baeldung/iplookup/IPAddressLookup.java b/core-java-modules/core-java-networking-3/src/main/java/com/baeldung/iplookup/IPAddressLookup.java new file mode 100644 index 0000000000..30ad5a503d --- /dev/null +++ b/core-java-modules/core-java-networking-3/src/main/java/com/baeldung/iplookup/IPAddressLookup.java @@ -0,0 +1,50 @@ +package com.baeldung.iplookup; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketException; +import java.net.URL; +import java.net.UnknownHostException; + +public class IPAddressLookup { + public static void main(String[] args) { + System.out.println("UDP connection IP lookup: " + getLocalIpAddressUdp()); + System.out.println("Socket connection IP lookup: " + getLocalIpAddressSocket()); + System.out.println("AWS connection IP lookup: " + getPublicIpAddressAws()); + } + + public static String getLocalIpAddressUdp() { + try (final DatagramSocket datagramSocket = new DatagramSocket()) { + datagramSocket.connect(InetAddress.getByName("8.8.8.8"), 12345); + return datagramSocket.getLocalAddress().getHostAddress(); + } catch (SocketException | UnknownHostException exception) { + throw new RuntimeException(exception); + } + } + + public static String getLocalIpAddressSocket() { + try (Socket socket = new Socket()) { + socket.connect(new InetSocketAddress("google.com", 80)); + return socket.getLocalAddress().getHostAddress(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static String getPublicIpAddressAws() { + try { + String urlString = "http://checkip.amazonaws.com/"; + URL url = new URL(urlString); + try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) { + return br.readLine(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringperformance/StringPerformance.java b/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringperformance/StringPerformance.java index 8e9d3afdde..90335b4aba 100644 --- a/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringperformance/StringPerformance.java +++ b/core-java-modules/core-java-strings/src/main/java/com/baeldung/stringperformance/StringPerformance.java @@ -125,6 +125,8 @@ public class StringPerformance { stringSplit.add(longString.substring(pos, end)); pos = end + 1; } + //Add last token of string + stringSplit.add(longString.substring(pos)); return stringSplit; } diff --git a/graphql/graphql-java/pom.xml b/graphql/graphql-java/pom.xml index 5808dd17fb..068cb04ea8 100644 --- a/graphql/graphql-java/pom.xml +++ b/graphql/graphql-java/pom.xml @@ -36,6 +36,21 @@ graphql-java-annotations ${graphql-java-annotations.version} + + io.ratpack + ratpack-core + ${ratpack-core.version} + + + com.github.americanexpress.nodes + nodes + 0.5.0 + + + com.graphql-java + graphql-java + 11.0 + com.graphql-java graphql-java-tools @@ -95,6 +110,14 @@ ${mockserver-client-java.version} test + + + com.graphql-java + graphql-java-extended-scalars + ${graphql-java-extended-scalars.version} + + + @@ -133,6 +156,13 @@ false false true + + + JSON + java.util.Map + com.baeldung.graphqlreturnmap.ExtendedGraphQLScalarType + + @@ -154,6 +184,8 @@ 1.8 1.8 + 1.18 + 2022-04-06T00-10-27-a70541e - \ No newline at end of file + diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphql/server/GraphQLQuery.java b/graphql/graphql-java/src/main/java/com/baeldung/graphql/server/GraphQLQuery.java index 8ba9fa25c5..f2ac792e80 100644 --- a/graphql/graphql-java/src/main/java/com/baeldung/graphql/server/GraphQLQuery.java +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphql/server/GraphQLQuery.java @@ -2,6 +2,7 @@ package com.baeldung.graphql.server; import com.baeldung.graphql.data.Book; import com.baeldung.graphql.data.BookRepository; +import com.baeldung.graphqlreturnmap.entity.Product; import com.coxautodev.graphql.tools.GraphQLQueryResolver; import java.util.List; @@ -18,4 +19,12 @@ public class GraphQLQuery implements GraphQLQueryResolver { return repository.getAllBooks(); } + public List getProducts(int pageSize, int pageNumber) { + return null; + } + + public Product getProduct(int id) { + return null; + } + } diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/AppHandler.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/AppHandler.java new file mode 100644 index 0000000000..26ad0eef2c --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/AppHandler.java @@ -0,0 +1,52 @@ +package com.baeldung.graphqlreturnmap; + +import com.baeldung.graphql.utils.SchemaUtils; +import com.baeldung.graphqlreturnmap.resolver.ProductResolver; +import com.baeldung.graphqlreturnmap.resolver.Query; +import com.coxautodev.graphql.tools.SchemaParser; +import graphql.ExecutionResult; +import graphql.GraphQL; +import graphql.scalars.ExtendedScalars; +import graphql.schema.GraphQLSchema; +import ratpack.handling.Context; +import ratpack.handling.Handler; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.logging.Logger; + +import static ratpack.jackson.Jackson.json; + +public class AppHandler implements Handler { + private static final Logger LOGGER = Logger.getLogger(AppHandler.class.getSimpleName()); + private GraphQL graphql; + + public AppHandler() throws Exception { + GraphQLSchema schema = SchemaParser.newParser() + .resolvers(new Query(), new ProductResolver()) + .scalars(ExtendedScalars.Json) + .file("schema.graphqls") + .build() + .makeExecutableSchema(); + graphql = GraphQL.newGraphQL(schema).build(); + } + + @Override + public void handle(Context context) throws Exception { + context.parse(Map.class) + .then(payload -> { + ExecutionResult executionResult = graphql.execute(payload.get(SchemaUtils.QUERY) + .toString(), null, this, Collections.emptyMap()); + Map result = new LinkedHashMap<>(); + if (executionResult.getErrors() + .isEmpty()) { + result.put(SchemaUtils.DATA, executionResult.getData()); + } else { + result.put(SchemaUtils.ERRORS, executionResult.getErrors()); + LOGGER.warning("Errors: " + executionResult.getErrors()); + } + context.render(json(result)); + }); + } +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/ExtendedGraphQLScalarType.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/ExtendedGraphQLScalarType.java new file mode 100644 index 0000000000..5cdc72b13d --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/ExtendedGraphQLScalarType.java @@ -0,0 +1,24 @@ +package com.baeldung.graphqlreturnmap; + +import graphql.language.ScalarTypeDefinition; +import graphql.schema.Coercing; +import graphql.schema.GraphQLDirective; +import graphql.schema.GraphQLScalarType; + +import java.util.List; + +public class ExtendedGraphQLScalarType extends GraphQLScalarType { + + public ExtendedGraphQLScalarType(){ + super("","",null); + + } + + public ExtendedGraphQLScalarType(String name, String description, Coercing coercing) { + super(name, description, coercing); + } + + public ExtendedGraphQLScalarType(String name, String description, Coercing coercing, List directives, ScalarTypeDefinition definition) { + super(name, description, coercing, directives, definition); + } +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/GraphqlReturnMap.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/GraphqlReturnMap.java new file mode 100644 index 0000000000..8717fcb722 --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/GraphqlReturnMap.java @@ -0,0 +1,12 @@ +package com.baeldung.graphqlreturnmap; + +import ratpack.server.RatpackServer; + +public class GraphqlReturnMap { + + public static void main(String[] args) throws Exception { + final RatpackServer server = RatpackServer.of(s -> s.handlers(chain -> chain.post("product", new AppHandler()))); + server.start(); + } + +} \ No newline at end of file diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/entity/Attribute.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/entity/Attribute.java new file mode 100644 index 0000000000..dd2766afa5 --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/entity/Attribute.java @@ -0,0 +1,46 @@ +package com.baeldung.graphqlreturnmap.entity; + +public class Attribute { + private String name; + private String description; + private String unit; + + public Attribute(String name, String description, String unit){ + this.name = name; + this.description = description; + this.unit = unit; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + @Override + public String toString() { + return "Attribute{" + + "name='" + name + '\'' + + ", description='" + description + '\'' + + ", unit='" + unit + '\'' + + '}'; + } +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/entity/Product.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/entity/Product.java new file mode 100644 index 0000000000..db39d763de --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/entity/Product.java @@ -0,0 +1,48 @@ +package com.baeldung.graphqlreturnmap.entity; + + +import java.util.Map; + +public class Product { + private Integer id; + private String name; + private String description; + private Map attributes; + + + public Product(){ + + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map getAttributes() { + return attributes; + } + + public void setAttributes(Map attributes) { + this.attributes = attributes; + } +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/model/AttributeKeyValueModel.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/model/AttributeKeyValueModel.java new file mode 100644 index 0000000000..bb7641143b --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/model/AttributeKeyValueModel.java @@ -0,0 +1,30 @@ +package com.baeldung.graphqlreturnmap.model; + + +import com.baeldung.graphqlreturnmap.entity.Attribute; + +public class AttributeKeyValueModel { + private String key; + private Attribute value; + + public AttributeKeyValueModel(String key, Attribute value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public Attribute getValue() { + return value; + } + + public void setValue(Attribute value) { + this.value = value; + } +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/repository/ProductRepository.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/repository/ProductRepository.java new file mode 100644 index 0000000000..c751efc183 --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/repository/ProductRepository.java @@ -0,0 +1,12 @@ +package com.baeldung.graphqlreturnmap.repository; + + +import com.baeldung.graphqlreturnmap.entity.Product; + +import java.util.List; + +public interface ProductRepository { + List getProducts(Integer pageSize, Integer pageNumber); + Product getProduct(Integer id); + +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/repository/impl/ProductRepositoryImpl.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/repository/impl/ProductRepositoryImpl.java new file mode 100644 index 0000000000..466a2149f4 --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/repository/impl/ProductRepositoryImpl.java @@ -0,0 +1,43 @@ +package com.baeldung.graphqlreturnmap.repository.impl; + +import com.baeldung.graphqlreturnmap.entity.Attribute; +import com.baeldung.graphqlreturnmap.entity.Product; +import com.baeldung.graphqlreturnmap.repository.ProductRepository; +import org.springframework.stereotype.Repository; + +import java.util.*; +import java.util.stream.Collectors; + +@Repository +public class ProductRepositoryImpl implements ProductRepository { + + private static List productList = new ArrayList<>(); + + public ProductRepositoryImpl() { + for (int i = 1; i <= 10; i++){ + Product product = new Product(); + product.setId(i); + product.setName(String.format("Product %d", i)); + product.setDescription(String.format("Product %d description", i)); + product.setAttributes(createAttributes(i)); + productList.add(product); + } + } + + private Map createAttributes(int i) { + Map attributeMap = new HashMap<>(); + attributeMap.put(String.format("attribute_%d",i), new Attribute(String.format("Attribute%d name",i),"This is custom attribute description","This is custom attribute unit")); + attributeMap.put("size", new Attribute((i & 1) == 0 ? "Small" : "Large","This is custom attribute description","This is custom attribute unit")); + return attributeMap; + } + + @Override + public List getProducts(Integer pageSize, Integer pageNumber) { + return productList.stream().skip(pageSize*pageNumber).limit(pageSize).collect(Collectors.toList()); + } + + @Override + public Product getProduct(Integer id) { + return productList.stream().filter(product -> product.getId().equals(id)).findFirst().orElse(null); + } +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/resolver/ProductResolver.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/resolver/ProductResolver.java new file mode 100644 index 0000000000..d9789ea0c6 --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/resolver/ProductResolver.java @@ -0,0 +1,30 @@ +package com.baeldung.graphqlreturnmap.resolver; + +import com.baeldung.graphqlreturnmap.entity.Product; +import com.baeldung.graphqlreturnmap.model.AttributeKeyValueModel; +import com.coxautodev.graphql.tools.GraphQLResolver; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.LinkedList; +import java.util.List; + +public class ProductResolver implements GraphQLResolver { + public ProductResolver(){ + } + + public List getAttribute_list(Product product){ + List attributeModelList = new LinkedList<>(); + product.getAttributes().forEach((key, val) -> attributeModelList.add(new AttributeKeyValueModel(key, val))); + return attributeModelList; + } + + public String getAttribute_string(Product product){ + try { + return new ObjectMapper().writeValueAsString(product.getAttributes()); + } catch (JsonProcessingException e) { + e.printStackTrace(); + return ""; + } + } +} diff --git a/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/resolver/Query.java b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/resolver/Query.java new file mode 100644 index 0000000000..cbcff6056b --- /dev/null +++ b/graphql/graphql-java/src/main/java/com/baeldung/graphqlreturnmap/resolver/Query.java @@ -0,0 +1,33 @@ +package com.baeldung.graphqlreturnmap.resolver; + +import com.baeldung.graphql.data.Book; +import com.baeldung.graphqlreturnmap.entity.Product; +import com.baeldung.graphqlreturnmap.repository.ProductRepository; +import com.baeldung.graphqlreturnmap.repository.impl.ProductRepositoryImpl; +import com.coxautodev.graphql.tools.GraphQLQueryResolver; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +public class Query implements GraphQLQueryResolver { + + @Autowired + private ProductRepository productRepository; + public Query(){ + productRepository = new ProductRepositoryImpl(); + } + + public List getProducts(int pageSize, int pageNumber) { + return productRepository.getProducts(pageSize, pageNumber); + } + + public Product getProduct(int id) { + return productRepository.getProduct(id); + } + + public List allBooks() { + return null; + } + + +} diff --git a/graphql/graphql-java/src/main/resources/schema.graphqls b/graphql/graphql-java/src/main/resources/schema.graphqls index b0834e04b7..da10cd18bd 100644 --- a/graphql/graphql-java/src/main/resources/schema.graphqls +++ b/graphql/graphql-java/src/main/resources/schema.graphqls @@ -10,8 +10,34 @@ type Author { type Query { allBooks: [Book] + products(size: Int, page: Int): [Product]! + product(id: Int): Product! } + + +type Product { + id: ID + name: String! + description: String + attribute_string:String + attribute_list:[AttributeKeyValuePair] + attributes: JSON +} + +type AttributeKeyValuePair { + key:String + value:Attribute +} + +type Attribute { + name:String + description:String + unit:String +} +scalar JSON + + schema { query: Query } \ No newline at end of file diff --git a/libraries-3/README.md b/libraries-3/README.md index b267e82ed9..99b1b60a0a 100644 --- a/libraries-3/README.md +++ b/libraries-3/README.md @@ -16,6 +16,6 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Introduction to Takes](https://www.baeldung.com/java-takes) - [Using NullAway to Avoid NullPointerExceptions](https://www.baeldung.com/java-nullaway) - [Introduction to Alibaba Arthas](https://www.baeldung.com/java-alibaba-arthas-intro) -- [Introduction to Structurizr](https://www.baeldung.com/structurizr) +- [Intro to Structurizr](https://www.baeldung.com/structurizr) - [Introduction to Immutables](https://www.baeldung.com/immutables) - More articles [[<-- prev]](../libraries-2) [[next -->]](../libraries-4) diff --git a/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/model/Foo.java b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/model/Foo.java index eec15c5e56..ac79653b2b 100644 --- a/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/model/Foo.java +++ b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/model/Foo.java @@ -13,6 +13,9 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.NamedNativeQueries; import javax.persistence.NamedNativeQuery; +import javax.persistence.NamedStoredProcedureQuery; +import javax.persistence.ParameterMode; +import javax.persistence.StoredProcedureParameter; import org.hibernate.envers.Audited; @@ -20,6 +23,20 @@ import org.hibernate.envers.Audited; @NamedNativeQuery(name = "callGetAllFoos", query = "CALL GetAllFoos()", resultClass = Foo.class), @NamedNativeQuery(name = "callGetFoosByName", query = "CALL GetFoosByName(:fooName)", resultClass = Foo.class) }) +@NamedStoredProcedureQuery( + name="GetAllFoos", + procedureName="GetAllFoos", + resultClasses = { Foo.class } + ) +@NamedStoredProcedureQuery( + name="GetFoosByName", + procedureName="GetFoosByName", + resultClasses = { Foo.class }, + parameters={ + @StoredProcedureParameter(name="fooName", type=String.class, mode=ParameterMode.IN) + } + ) + @Entity @Audited // @Proxy(lazy = false) diff --git a/persistence-modules/spring-data-jpa-query-2/src/test/java/com/baeldung/persistence/service/FooStoredProceduresLiveTest.java b/persistence-modules/spring-data-jpa-query-2/src/test/java/com/baeldung/persistence/service/FooStoredProceduresLiveTest.java index 8bf33c4110..f6dedfc6de 100644 --- a/persistence-modules/spring-data-jpa-query-2/src/test/java/com/baeldung/persistence/service/FooStoredProceduresLiveTest.java +++ b/persistence-modules/spring-data-jpa-query-2/src/test/java/com/baeldung/persistence/service/FooStoredProceduresLiveTest.java @@ -1,10 +1,14 @@ package com.baeldung.persistence.service; -import java.util.List; - import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.junit.Assert.assertEquals; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.StoredProcedureQuery; + import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; @@ -17,6 +21,7 @@ import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; @@ -38,8 +43,15 @@ public class FooStoredProceduresLiveTest { private Session session; + @Autowired + @Qualifier("jpaEntityManager") + private EntityManagerFactory entityManagerFactory; + + private EntityManager entityManager; + @Before public final void before() { + entityManager = entityManagerFactory.createEntityManager(); session = sessionFactory.openSession(); Assume.assumeTrue(getAllFoosExists()); Assume.assumeTrue(getFoosByNameExists()); @@ -70,6 +82,7 @@ public class FooStoredProceduresLiveTest { @After public final void after() { session.close(); + entityManager.close(); } @Test @@ -94,6 +107,15 @@ public class FooStoredProceduresLiveTest { LOGGER.info("getAllFoos() NamedQuery result : {}", foo.getName()); } assertEquals(allFoos2.size(), fooService.findAll().size()); + + StoredProcedureQuery spQuery = + entityManager.createNamedStoredProcedureQuery("GetAllFoos"); + List allFoos3 = spQuery.getResultList(); + for (Foo foo : allFoos3) { + LOGGER.info("getAllFoos() StoredProcedureQuery result : {}", foo.getName()); + } + assertEquals(allFoos3.size(), fooService.findAll().size()); + } @Test @@ -116,6 +138,15 @@ public class FooStoredProceduresLiveTest { for (Foo foo : allFoosByName2) { LOGGER.info("getFoosByName() using Native Query : found => {}", foo.toString()); } - + + StoredProcedureQuery spQuery = entityManager. + createNamedStoredProcedureQuery("GetFoosByName") + .setParameter("fooName", "NewFooName"); + List allFoosByName3 = spQuery.getResultList(); + assertEquals(1, allFoosByName3.size()); + for (Foo foo : allFoosByName3) { + LOGGER.info("getFoosByName() using StoredProcedureQuery : found => {}", foo.toString()); + assertEquals("NewFooName", foo.getName()); + } } } diff --git a/pom.xml b/pom.xml index 21589f5525..25aeebef9d 100644 --- a/pom.xml +++ b/pom.xml @@ -366,11 +366,8 @@ atomix - aws - aws-app-sync - aws-lambda - aws-reactive - + aws-modules + axon azure @@ -428,7 +425,7 @@ hazelcast helidon - httpclient + apache-httpclient httpclient-simple hystrix @@ -850,11 +847,8 @@ atomix - aws - aws-app-sync - aws-lambda - aws-reactive - + aws-modules + axon azure @@ -912,7 +906,7 @@ hazelcast helidon - httpclient + apache-httpclient httpclient-simple hystrix @@ -1346,7 +1340,7 @@ core-java-modules/core-java-strings ddd-modules docker - httpclient-2 + apache-httpclient-2 libraries-concurrency persistence-modules/sirix persistence-modules/spring-data-cassandra-2 @@ -1413,7 +1407,7 @@ core-java-modules/core-java-strings ddd-modules docker - httpclient-2 + apache-httpclient-2 libraries-concurrency persistence-modules/sirix persistence-modules/spring-data-cassandra-2 diff --git a/spring-boot-modules/spring-boot-crud/README.md b/spring-boot-modules/spring-boot-crud/README.md index 3d3d8f42d7..6b0032deb3 100644 --- a/spring-boot-modules/spring-boot-crud/README.md +++ b/spring-boot-modules/spring-boot-crud/README.md @@ -5,4 +5,3 @@ This module contains articles about Spring Boot CRUD Operations ### Relevant Articles: - [Spring Boot CRUD Application with Thymeleaf](https://www.baeldung.com/spring-boot-crud-thymeleaf) - [Using a Spring Boot Application as a Dependency](https://www.baeldung.com/spring-boot-dependency) -- [A Guide to Spring in Eclipse STS](https://www.baeldung.com/eclipse-sts-spring) \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-4/README.md b/spring-boot-modules/spring-boot-mvc-4/README.md index 68fcfa8b6b..c6820ce930 100644 --- a/spring-boot-modules/spring-boot-mvc-4/README.md +++ b/spring-boot-modules/spring-boot-mvc-4/README.md @@ -7,4 +7,4 @@ This module contains articles about Spring Web MVC in Spring Boot projects. - [How to Register a Servlet in Java](https://www.baeldung.com/register-servlet) - [Guide to Spring WebUtils and ServletRequestUtils](https://www.baeldung.com/spring-webutils-servletrequestutils) - [Configure a Spring Boot Web Application](https://www.baeldung.com/spring-boot-application-configuration) -- More articles: [[<-- Prev]](/spring-boot-modules/spring-boot-mvc-3) +- [A Guide to Spring in Eclipse STS](https://www.baeldung.com/eclipse-sts-spring) diff --git a/spring-boot-modules/spring-boot-mvc-4/pom.xml b/spring-boot-modules/spring-boot-mvc-4/pom.xml index 7d4d6e3d0c..5b58b326ab 100644 --- a/spring-boot-modules/spring-boot-mvc-4/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-4/pom.xml @@ -1,13 +1,14 @@ + 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-boot-mvc-4 spring-boot-mvc-4 jar Module For Spring Boot MVC Web - + com.baeldung.spring-boot-modules spring-boot-modules @@ -19,13 +20,27 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-thymeleaf + org.springframework.boot spring-boot-starter-validation org.springframework.boot - spring-boot-starter-thymeleaf + spring-boot-devtools + true + + + io.springfox + springfox-boot-starter + ${spring.fox.version} + + + com.fasterxml.jackson.core + jackson-databind org.springframework.boot @@ -42,4 +57,23 @@ + + + + org.springframework.boot + spring-boot-maven-plugin + + ${start-class} + JAR + + + + + + + + 3.0.0 + com.baeldung.springboot.swagger.ArticleApplication + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/ArticleApplication.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/ArticleApplication.java similarity index 91% rename from spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/ArticleApplication.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/ArticleApplication.java index 568d31e8bc..8be380baa0 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/ArticleApplication.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/ArticleApplication.java @@ -4,6 +4,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.spi.DocumentationType; @@ -12,6 +13,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; @SpringBootApplication @EnableSwagger2 +@EnableWebMvc public class ArticleApplication { public static void main(String[] args) { diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/controller/ArticlesController.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/controller/ArticlesController.java similarity index 91% rename from spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/controller/ArticlesController.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/controller/ArticlesController.java index 96812e367a..c4336a7cfe 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/controller/ArticlesController.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/controller/ArticlesController.java @@ -21,7 +21,7 @@ public class ArticlesController { } @PostMapping("") - public void addArticle(@RequestBody Article article) { + public void addArticle(@ModelAttribute Article article) { articleService.addArticle(article); } diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/model/Article.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/model/Article.java similarity index 97% rename from spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/model/Article.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/model/Article.java index 6512b4e1a7..f6318c04b3 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/model/Article.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/model/Article.java @@ -15,6 +15,7 @@ public class Article { //@ApiModelProperty(hidden = true) //@ApiParam(hidden = true) //@ApiModelProperty(readOnly = true) + @ApiParam(hidden = true) private int id; private String title; private int numOfWords; diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/service/ArticleService.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/service/ArticleService.java similarity index 99% rename from spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/service/ArticleService.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/service/ArticleService.java index 04f6e6c6e3..3fd0279988 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/service/ArticleService.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/service/ArticleService.java @@ -20,6 +20,6 @@ public class ArticleService { article.setId(articles.size() + 1); articles.add(article); } - + } diff --git a/spring-boot-modules/spring-boot-mvc-4/src/main/resources/static/index.html b/spring-boot-modules/spring-boot-mvc-4/src/main/resources/static/index.html new file mode 100644 index 0000000000..9f55d12685 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/resources/static/index.html @@ -0,0 +1 @@ +Welcome to Baeldung \ No newline at end of file diff --git a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/AppInitializer.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/AppInitializer.java new file mode 100644 index 0000000000..43921f71a2 --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/AppInitializer.java @@ -0,0 +1,11 @@ +package com.baeldung.exceptionhandler; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class AppInitializer { + public static void main(String[] args) { + SpringApplication.run(AppInitializer.class, args); + } +} diff --git a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/controller/AccessDeniedController.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/controller/AccessDeniedController.java new file mode 100644 index 0000000000..0973fe1ad3 --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/controller/AccessDeniedController.java @@ -0,0 +1,15 @@ +package com.baeldung.exceptionhandler.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@RequestMapping("/access-denied") +public class AccessDeniedController { + + @GetMapping + public String accessDenied() { + return "/denied.html"; + } +} diff --git a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/controller/CustomErrorController.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/controller/CustomErrorController.java new file mode 100644 index 0000000000..8b65a623eb --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/controller/CustomErrorController.java @@ -0,0 +1,15 @@ +package com.baeldung.exceptionhandler.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@RequestMapping +public class CustomErrorController { + + @GetMapping("/customError") + public String customErrorController() { + return "/error"; + } +} diff --git a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/controller/HomeController.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/controller/HomeController.java new file mode 100644 index 0000000000..d64bf7b5f3 --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/controller/HomeController.java @@ -0,0 +1,15 @@ +package com.baeldung.exceptionhandler.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@RequestMapping("/home") +public class HomeController { + + @GetMapping + public String home() { + return "/index.html"; + } +} diff --git a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/controller/SecuredResourceController.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/controller/SecuredResourceController.java new file mode 100644 index 0000000000..a057570e29 --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/controller/SecuredResourceController.java @@ -0,0 +1,15 @@ +package com.baeldung.exceptionhandler.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@RequestMapping("/secured") +public class SecuredResourceController { + + @GetMapping + public String secureResource() { + return "/admin.html"; + } +} diff --git a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/security/CustomAccessDeniedHandler.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/security/CustomAccessDeniedHandler.java new file mode 100644 index 0000000000..a3d6aca9be --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/security/CustomAccessDeniedHandler.java @@ -0,0 +1,17 @@ +package com.baeldung.exceptionhandler.security; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.web.access.AccessDeniedHandler; + +public class CustomAccessDeniedHandler implements AccessDeniedHandler { + + @Override + public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException exc) throws IOException { + response.sendRedirect("/access-denied"); + } +} diff --git a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/security/CustomAuthenticationFailureHandler.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/security/CustomAuthenticationFailureHandler.java new file mode 100644 index 0000000000..281f9d5289 --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/security/CustomAuthenticationFailureHandler.java @@ -0,0 +1,17 @@ +package com.baeldung.exceptionhandler.security; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.authentication.AuthenticationFailureHandler; + +public class CustomAuthenticationFailureHandler implements AuthenticationFailureHandler { + + @Override + public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException { + httpServletResponse.sendRedirect("/customError"); + } +} diff --git a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/security/CustomAuthenticationSuccessHandler.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/security/CustomAuthenticationSuccessHandler.java new file mode 100644 index 0000000000..62cbdf8873 --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/security/CustomAuthenticationSuccessHandler.java @@ -0,0 +1,31 @@ +package com.baeldung.exceptionhandler.security; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; + +public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler { + + @Override + public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException { + + HttpSession session = httpServletRequest.getSession(); + User authUser = (User) SecurityContextHolder.getContext() + .getAuthentication() + .getPrincipal(); + session.setAttribute("username", authUser.getUsername()); + session.setAttribute("authorities", authentication.getAuthorities()); + + httpServletResponse.setStatus(HttpServletResponse.SC_OK); + + httpServletResponse.sendRedirect("/home"); + } +} diff --git a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/security/SecurityConfig.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/security/SecurityConfig.java new file mode 100644 index 0000000000..71ded0f131 --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/exceptionhandler/security/SecurityConfig.java @@ -0,0 +1,98 @@ +package com.baeldung.exceptionhandler.security; + +import org.springframework.context.annotation.Bean; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +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.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.crypto.factory.PasswordEncoderFactories; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; +import org.springframework.security.web.access.AccessDeniedHandler; +import org.springframework.security.web.authentication.AuthenticationFailureHandler; +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; + +@EnableWebSecurity +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + @Bean + public UserDetailsService userDetailsService() { + + UserDetails user = User.withUsername("user") + .passwordEncoder(PasswordEncoderFactories.createDelegatingPasswordEncoder()::encode) + .password("password") + .roles("USER") + .build(); + + UserDetails admin = User.withUsername("admin") + .passwordEncoder(PasswordEncoderFactories.createDelegatingPasswordEncoder()::encode) + .password("password") + .roles("ADMIN") + .build(); + + InMemoryUserDetailsManager userDetailsManager = new InMemoryUserDetailsManager(); + + userDetailsManager.createUser(user); + userDetailsManager.createUser(admin); + + return userDetailsManager; + } + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.inMemoryAuthentication() + .withUser("user") + .password("{noop}password") + .roles("USER") + .and() + .withUser("admin") + .password("{noop}password") + .roles("ADMIN"); + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf() + .disable() + .httpBasic() + .disable() + .authorizeRequests() + .antMatchers("/login") + .permitAll() + .antMatchers("/customError") + .permitAll() + .antMatchers("/access-denied") + .permitAll() + .antMatchers("/secured") + .hasRole("ADMIN") + .anyRequest() + .authenticated() + .and() + .formLogin() + .failureHandler(authenticationFailureHandler()) + .successHandler(authenticationSuccessHandler()) + .and() + .exceptionHandling() + .accessDeniedHandler(accessDeniedHandler()) + .and() + .logout(); + } + + @Bean + public AuthenticationFailureHandler authenticationFailureHandler() { + return new CustomAuthenticationFailureHandler(); + } + + @Bean + public AuthenticationSuccessHandler authenticationSuccessHandler() { + return new CustomAuthenticationSuccessHandler(); + } + + @Bean + public AccessDeniedHandler accessDeniedHandler() { + return new CustomAccessDeniedHandler(); + } + +} diff --git a/spring-security-modules/spring-security-core/src/main/resources/application.properties b/spring-security-modules/spring-security-core/src/main/resources/application.properties new file mode 100644 index 0000000000..9d154c9cc0 --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.thymeleaf.prefix=classpath:/templates/ \ No newline at end of file diff --git a/spring-security-modules/spring-security-core/src/main/resources/templates/admin.html b/spring-security-modules/spring-security-core/src/main/resources/templates/admin.html new file mode 100644 index 0000000000..d7f7ec232a --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/resources/templates/admin.html @@ -0,0 +1,5 @@ + + +
Hello Admin!
+ + diff --git a/spring-security-modules/spring-security-core/src/main/resources/templates/denied.html b/spring-security-modules/spring-security-core/src/main/resources/templates/denied.html new file mode 100644 index 0000000000..b7a8e09309 --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/resources/templates/denied.html @@ -0,0 +1,5 @@ + + +
You need permission to perform this action.
+ + diff --git a/spring-security-modules/spring-security-core/src/main/resources/templates/error.html b/spring-security-modules/spring-security-core/src/main/resources/templates/error.html new file mode 100644 index 0000000000..ce74f05d99 --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/resources/templates/error.html @@ -0,0 +1,5 @@ + + +
Ups! Wrong credentials
+ + diff --git a/spring-security-modules/spring-security-core/src/main/resources/templates/index.html b/spring-security-modules/spring-security-core/src/main/resources/templates/index.html new file mode 100644 index 0000000000..34d070b37a --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/resources/templates/index.html @@ -0,0 +1,6 @@ + + +
Hello User!
+ + + diff --git a/spring-security-modules/spring-security-core/src/test/java/com/baeldung/exceptionhandler/SecurityConfigUnitTest.java b/spring-security-modules/spring-security-core/src/test/java/com/baeldung/exceptionhandler/SecurityConfigUnitTest.java new file mode 100644 index 0000000000..ad35d575a5 --- /dev/null +++ b/spring-security-modules/spring-security-core/src/test/java/com/baeldung/exceptionhandler/SecurityConfigUnitTest.java @@ -0,0 +1,50 @@ +package com.baeldung.exceptionhandler; + +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import com.baeldung.exceptionhandler.security.SecurityConfig; + +@RunWith(SpringRunner.class) +@WebMvcTest(SecurityConfig.class) +class SecurityConfigUnitTest { + @Autowired + private MockMvc mvc; + + @Test + void whenUserAccessLogin_shouldSucceed() throws Exception { + mvc.perform(get("/login")) + .andExpect(status().isOk()); + } + + @Test + void whenUserAccessWithWrongCredentials_shouldRedirectToCustomErrorPage() throws Exception { + mvc.perform(formLogin("/login").user("username", "wrong") + .password("password", "credentials")) + .andExpect(redirectedUrl("/customError")); + } + + @Test + void whenUserAccessWithCorrectCredentials_shouldRedirectToHome() throws Exception { + mvc.perform(formLogin("/login").user("username", "user") + .password("password", "password")) + .andExpect(redirectedUrl("/home")); + } + + @Test + @WithMockUser(username = "user", roles = { "USER" }) + void whenUserAccessToSecuredPageWithoutUserRole_shouldRedirectToDeniedPage() throws Exception { + mvc.perform(get("/secured")) + .andExpect(redirectedUrl("/access-denied")); + } +} \ No newline at end of file