Merge branch 'eugenp:master' into master

This commit is contained in:
Balamurugan 2024-01-29 22:44:18 +00:00 committed by GitHub
commit 7727131cf7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
72 changed files with 666 additions and 76 deletions

17
.gitignore vendored
View File

@ -64,13 +64,13 @@ core-java-io/hard_link.txt
core-java-io/target_link.txt
core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF
ethereum/logs/
jmeter/src/main/resources/*-JMeter.csv
jmeter/src/main/resources/*-Basic*.csv
jmeter/src/main/resources/*-JMeter*.csv
jmeter/src/main/resources/*ReportsDashboard*.csv
jmeter/src/main/resources/dashboard/*ReportsDashboard*.csv
jmeter/src/main/resources/*FileExtractionExample.csv
jmeter/src/main/resources/*_Summary-Report.csv
testing-modules/jmeter/src/main/resources/*-JMeter.csv
testing-modules/jmeter/src/main/resources/*-Basic*.csv
testing-modules/jmeter/src/main/resources/*-JMeter*.csv
testing-modules/jmeter/src/main/resources/*ReportsDashboard*.csv
testing-modules/jmeter/src/main/resources/dashboard/*ReportsDashboard*.csv
testing-modules/jmeter/src/main/resources/*FileExtractionExample.csv
testing-modules/jmeter/src/main/resources/*_Summary-Report.csv
ninja/devDb.mv.db
@ -128,3 +128,6 @@ persistence-modules/neo4j/data/**
/deep-shallow-copy/.mvn/wrapper
/deep-shallow-copy/mvnw
/deep-shallow-copy/mvnw.cmd
#spring-5-webflux-2
**/testdb.mv.db

View File

@ -1,3 +1,4 @@
## Relevant Articles
- [How To Convert Excel Data Into List Of Java Objects](https://www.baeldung.com/java-convert-excel-data-into-list)
- [Expand Columns with Apache POI](https://www.baeldung.com/java-apache-poi-expand-columns)
- [Apply Bold Text Style for an Entire Row Using Apache POI](https://www.baeldung.com/appache-poi-apply-bold-text-style-entire-row)

View File

@ -3,3 +3,4 @@
- [String Templates in Java 21](https://www.baeldung.com/java-21-string-templates)
- [Unnamed Classes and Instance Main Methods in Java 21](https://www.baeldung.com/java-21-unnamed-class-instance-main)
- [Unnamed Patterns and Variables in Java 21](https://www.baeldung.com/java-unnamed-patterns-variables)
- [JFR View Command in Java 21](https://www.baeldung.com/java-flight-recorder-view)

View File

@ -10,4 +10,7 @@
- [Representing Furthest Possible Date in Java](https://www.baeldung.com/java-date-represent-max)
- [Retrieving Unix Time in Java](https://www.baeldung.com/java-retrieve-unix-time)
- [Calculate Months Between Two Dates in Java](https://www.baeldung.com/java-months-difference-two-dates)
- [Format LocalDate to ISO 8601 With T and Z](https://www.baeldung.com/java-format-localdate-iso-8601-t-z)
- [Check if Two Date Ranges Overlap](https://www.baeldung.com/java-check-two-date-ranges-overlap)
- [Difference between ZoneOffset.UTC and ZoneId.of(“UTC”)](https://www.baeldung.com/java-zoneoffset-utc-zoneid-of)
- [[<-- Prev]](/core-java-modules/core-java-datetime-java8-1)

View File

@ -12,3 +12,4 @@ This module contains articles about arrays conversion in Java
- [Convert an ArrayList of String to a String Array in Java](https://www.baeldung.com/java-convert-string-arraylist-array)
- [Convert Char Array to Int Array in Java](https://www.baeldung.com/java-convert-char-int-array)
- [How to Convert Byte Array to Char Array](https://www.baeldung.com/java-convert-byte-array-char)
- [Convert byte[] to Byte[] and Vice Versa in Java](https://www.baeldung.com/java-byte-array-wrapper-primitive-type-convert)

View File

@ -13,4 +13,5 @@
- [Time Complexity of Java Collections Sort in Java](https://www.baeldung.com/java-time-complexity-collections-sort)
- [Check if List Contains at Least One Enum](https://www.baeldung.com/java-list-check-enum-presence)
- [Comparison of for Loops and Iterators](https://www.baeldung.com/java-for-loops-vs-iterators)
- [PriorityQueue iterator() Method in Java](https://www.baeldung.com/java-priorityqueue-iterator)
- More articles: [[<-- prev]](/core-java-modules/core-java-collections-4)

View File

@ -3,3 +3,4 @@
- [Removing the Last Node in a Linked List](https://www.baeldung.com/java-linked-list-remove-last-element)
- [Call a Method on Each Element of a List in Java](https://www.baeldung.com/java-call-method-each-list-item)
- [Sorting One List Based on Another List in Java](https://www.baeldung.com/java-sorting-one-list-using-another)
- [Reset ListIterator to First Element of the List in Java](https://www.baeldung.com/java-reset-listiterator)

View File

@ -5,6 +5,6 @@
- [How to Get First or Last Entry From a LinkedHashMap in Java](https://www.baeldung.com/java-linkedhashmap-first-last-key-value-pair)
- [How to Write and Read a File with a Java HashMap](https://www.baeldung.com/java-hashmap-write-read-file)
- [Limiting the Max Size of a HashMap in Java](https://www.baeldung.com/java-hashmap-size-bound)
- [How to Sort LinkedHashMap By Values in Java](https://www.baeldung.com/java-sort-linkedhashmap-using-values)
- [How to Sort LinkedHashMap by Values in Java](https://www.baeldung.com/java-sort-linkedhashmap-using-values)
- [How to Increment a Map Value in Java](https://www.baeldung.com/java-increment-map-value)
- More articles: [[<-- prev]](/core-java-modules/core-java-collections-maps-6)

View File

@ -8,3 +8,4 @@
- [System.console() vs. System.out](https://www.baeldung.com/java-system-console-vs-system-out)
- [How to Log to the Console in Color](https://www.baeldung.com/java-log-console-in-color)
- [Create Table Using ASCII in a Console in Java](https://www.baeldung.com/java-console-ascii-make-table)
- [Printing Message on Console without Using main() Method in Java](https://www.baeldung.com/java-no-main-print-message-console)

View File

@ -2,4 +2,5 @@
This module contains articles about date operations in Java.
### Relevant Articles:
- [Calculate Number of Weekdays Between Two Dates in Java](https://www.baeldung.com/java-count-weekdays-between-two-dates)

View File

@ -0,0 +1,42 @@
package com.baeldung.stringdatetoxmlgregoriancalendar;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
public class StringDateToXMLGregorianCalendarConverter {
public static XMLGregorianCalendar usingDatatypeFactoryForDate(String dateAsString) throws DatatypeConfigurationException {
return DatatypeFactory.newInstance().newXMLGregorianCalendar(dateAsString);
}
public static XMLGregorianCalendar usingLocalDate(String dateAsString) throws DatatypeConfigurationException {
LocalDate localDate = LocalDate.parse(dateAsString);
return DatatypeFactory.newInstance().newXMLGregorianCalendar(localDate.toString());
}
public static XMLGregorianCalendar usingSimpleDateFormat(String dateTimeAsString) throws DatatypeConfigurationException, ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = simpleDateFormat.parse(dateTimeAsString);
return DatatypeFactory.newInstance().newXMLGregorianCalendar(simpleDateFormat.format(date));
}
public static XMLGregorianCalendar usingGregorianCalendar(String dateTimeAsString) throws DatatypeConfigurationException, ParseException {
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse(dateTimeAsString));
return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
}
public static XMLGregorianCalendar usingJodaTime(String dateTimeAsString) throws DatatypeConfigurationException {
DateTime dateTime = DateTime.parse(dateTimeAsString, DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss"));
return DatatypeFactory.newInstance().newXMLGregorianCalendar(dateTime.toGregorianCalendar());
}
}

View File

@ -0,0 +1,63 @@
package com.baeldung.stringdatetoxmlgregoriancalendar;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.text.ParseException;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.XMLGregorianCalendar;
import org.junit.jupiter.api.Test;
public class StringDateToXMLGregorianCalendarConverterUnitTest {
private static final String dateAsString = "2014-04-24";
private static final String dateTimeAsString = "2014-04-24T15:45:30";
@Test
void givenStringDate_whenUsingDatatypeFactory_thenConvertToXMLGregorianCalendar() throws DatatypeConfigurationException {
XMLGregorianCalendar xmlGregorianCalendar = StringDateToXMLGregorianCalendarConverter.usingDatatypeFactoryForDate(dateAsString);
assertEquals(24,xmlGregorianCalendar.getDay());
assertEquals(4,xmlGregorianCalendar.getMonth());
assertEquals(2014,xmlGregorianCalendar.getYear());
}
@Test
void givenStringDateTime_whenUsingApacheCommonsLang3_thenConvertToXMLGregorianCalendar() throws DatatypeConfigurationException {
XMLGregorianCalendar xmlGregorianCalendar = StringDateToXMLGregorianCalendarConverter.usingLocalDate(dateAsString);
assertEquals(24,xmlGregorianCalendar.getDay());
assertEquals(4,xmlGregorianCalendar.getMonth());
assertEquals(2014,xmlGregorianCalendar.getYear());
}
@Test
void givenStringDateTime_whenUsingSimpleDateFormat_thenConvertToXMLGregorianCalendar() throws DatatypeConfigurationException, ParseException {
XMLGregorianCalendar xmlGregorianCalendar = StringDateToXMLGregorianCalendarConverter.usingSimpleDateFormat(dateTimeAsString);
assertEquals(24,xmlGregorianCalendar.getDay());
assertEquals(4,xmlGregorianCalendar.getMonth());
assertEquals(2014,xmlGregorianCalendar.getYear());
assertEquals(15,xmlGregorianCalendar.getHour());
assertEquals(45,xmlGregorianCalendar.getMinute());
assertEquals(30,xmlGregorianCalendar.getSecond());
}
@Test
void givenStringDateTime_whenUsingGregorianCalendar_thenConvertToXMLGregorianCalendar() throws DatatypeConfigurationException, ParseException {
XMLGregorianCalendar xmlGregorianCalendar = StringDateToXMLGregorianCalendarConverter.usingGregorianCalendar(dateTimeAsString);
assertEquals(24,xmlGregorianCalendar.getDay());
assertEquals(4,xmlGregorianCalendar.getMonth());
assertEquals(2014,xmlGregorianCalendar.getYear());
assertEquals(15,xmlGregorianCalendar.getHour());
assertEquals(45,xmlGregorianCalendar.getMinute());
assertEquals(30,xmlGregorianCalendar.getSecond());
}
@Test
void givenStringDateTime_whenUsingJodaTime_thenConvertToXMLGregorianCalendar() throws DatatypeConfigurationException {
XMLGregorianCalendar xmlGregorianCalendar = StringDateToXMLGregorianCalendarConverter.usingJodaTime(dateTimeAsString);
assertEquals(24,xmlGregorianCalendar.getDay());
assertEquals(4,xmlGregorianCalendar.getMonth());
assertEquals(2014,xmlGregorianCalendar.getYear());
assertEquals(15,xmlGregorianCalendar.getHour());
assertEquals(45,xmlGregorianCalendar.getMinute());
assertEquals(30,xmlGregorianCalendar.getSecond());
}
}

View File

@ -5,3 +5,4 @@ This module contains articles about parsing and formatting Java date and time ob
### Relevant Articles:
- [Convert String to Instant](https://www.baeldung.com/java-string-to-instant)
- [Sort Date Strings in Java](https://www.baeldung.com/java-sort-date-strings)
- [Using Current Time as Filename in Java](https://www.baeldung.com/java-current-time-filename)

View File

@ -6,3 +6,4 @@
- [Java 8 Predicate Chain](https://www.baeldung.com/java-predicate-chain)
- [Use Cases for Static Methods in Java](https://www.baeldung.com/java-static-methods-use-cases)
- [TriFunction Interface in Java](https://www.baeldung.com/java-trifunction)
- [Lazy Field Initialization with Lambdas](https://www.baeldung.com/java-lambda-lazy-field-initialization)

View File

@ -9,7 +9,7 @@ This module contains articles about core Java input and output (IO)
- [SequenceInputStream Class in Java](https://www.baeldung.com/java-sequenceinputstream)
- [Read a File Into a Map in Java](https://www.baeldung.com/java-read-file-into-map)
- [Read User Input Until a Condition Is Met](https://www.baeldung.com/java-read-input-until-condition)
- [Java Scanner.skip method with examples](https://www.baeldung.com/java-scanner-skip)
- [Java Scanner.skip Method with Examples](https://www.baeldung.com/java-scanner-skip)
- [Generate the MD5 Checksum for a File in Java](https://www.baeldung.com/java-md5-checksum-file)
- [Getting the Filename From a String Containing an Absolute File Path](https://www.baeldung.com/java-filename-full-path)
- [Mocking Java InputStream Object](https://www.baeldung.com/java-mocking-inputstream)

View File

@ -7,5 +7,6 @@ This module contains articles about core Java input and output (IO)
- [How to Remove Line Breaks From a File in Java](https://www.baeldung.com/java-file-remove-line-breaks)
- [Difference Between ZipFile and ZipInputStream in Java](https://www.baeldung.com/java-zipfile-vs-zipinputstream)
- [How to Write Strings to OutputStream in Java](https://www.baeldung.com/java-write-string-outputstream)
- [Read a File and Split It Into Multiple Files in Java](https://www.baeldung.com/java-read-file-split-into-several)
- [[<-- Prev]](/core-java-modules/core-java-io-4)

View File

@ -11,5 +11,5 @@ This module contains articles about core Java input/output(IO) APIs.
- [Quick Use of FilenameFilter](https://www.baeldung.com/java-filename-filter)
- [Guide to BufferedReader](https://www.baeldung.com/java-buffered-reader)
- [Difference Between FileReader and BufferedReader in Java](https://www.baeldung.com/java-filereader-vs-bufferedreader)
- [Java: Read Multiple Inputs on Same Line](https://www.baeldung.com/java-read-multiple-inputs-same-line)
- [Write Console Output to Text File in Java](https://www.baeldung.com/java-write-console-output-file)
- [Read Multiple Inputs on the Same Line in Java](https://www.baeldung.com/java-read-multiple-inputs-same-line)
- [Write Console Output to Text File in Java](https://www.baeldung.com/java-write-console-output-file)

View File

@ -13,3 +13,4 @@ This module contains articles about core features in the Java language
- [Compress and Uncompress Byte Array Using Deflater/Inflater](https://www.baeldung.com/java-compress-uncompress-byte-array)
- [Static Final Variables in Java](https://www.baeldung.com/java-static-final-variables)
- [What Is the Error: “Non-static method cannot be referenced from a static context”?](https://www.baeldung.com/java-non-static-method-cannot-be-referenced-from-a-static-context)
- [Recursively Sum the Integers in an Array](https://www.baeldung.com/java-recursive-sum-integer-array)

View File

@ -14,4 +14,7 @@
- [Clamp Function in Java](https://www.baeldung.com/java-clamp-function)
- [Creating a Magic Square in Java](https://www.baeldung.com/java-magic-square)
- [Check if a Point Is Between Two Points Drawn on a Straight Line in Java](https://www.baeldung.com/java-check-point-straight-line)
- [Validate if a String Is a Valid Geo Coordinate](https://www.baeldung.com/java-geo-coordinates-validation)
- [Rotate a Vertex Around a Certain Point in Java](https://www.baeldung.com/java-rotate-vertex-around-point)
- [Calculating the Power of Any Number in Java Without Using Math pow() Method](https://www.baeldung.com/java-calculating-the-power-without-math-pow)
- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math-2)

View File

@ -1,3 +1,4 @@
## Relevant Articles
- [Check if a double Is an Integer in Java](https://www.baeldung.com/java-check-double-integer)
- [Print a Double Value Without Scientific Notation in Java](https://www.baeldung.com/java-print-double-number-no-scientific-notation)
- [Check if a Float Value is Equivalent to an Integer Value in Java](https://www.baeldung.com/java-float-integer-equal)

View File

@ -2,7 +2,7 @@
- [Convert a Number to a Letter in Java](https://www.baeldung.com/java-convert-number-to-letter)
- [Convert Long to BigDecimal in Java](https://www.baeldung.com/java-convert-long-bigdecimal)
- [Convert int to Long in Java](https://www.baeldung.com/java-convert-int-long)
- [How To Convert Double To Float In Java](https://www.baeldung.com/java-convert-double-float)
- [How to Convert Double to Float in Java](https://www.baeldung.com/java-convert-double-float)
- [Converting from float to BigDecimal in Java](https://www.baeldung.com/java-convert-float-bigdecimal)
- [Convert Positive Integer to Negative and Vice Versa in Java](https://www.baeldung.com/java-negating-integer)
- [Rounding Up a Number to Nearest Multiple of 5 in Java](https://www.baeldung.com/java-round-nearest-multiple-five)

View File

@ -9,5 +9,5 @@
- [Regular Expression: \z vs \Z Anchors in Java](https://www.baeldung.com/java-regular-expression-z-vs-z-anchors)
- [Extract Text Between Square Brackets](https://www.baeldung.com/java-get-content-between-square-brackets)
- [Get the Indexes of Regex Pattern Matches in Java](https://www.baeldung.com/java-indexes-regex-pattern-matches)
- [Check if a String is Strictly Alphanumeric With Java](https://www.baeldung.com/java-check-string-contains-only-letters-numbers)
- [Check if a String Is Strictly Alphanumeric With Java](https://www.baeldung.com/java-check-string-contains-only-letters-numbers)
- More articles: [[<-- prev]](/core-java-modules/core-java-regex)

View File

@ -7,4 +7,5 @@ This module contains articles about core Java Security
- [Extract CN From X509 Certificate in Java](https://www.baeldung.com/java-extract-common-name-x509-certificate)
- [Check Certificate Name and Alias in Keystore File](https://www.baeldung.com/java-keystore-check-certificate-name-alias)
- [Using a Custom TrustStore in Java](https://www.baeldung.com/java-custom-truststore)
- [Enable Java SSL Debug Logging](https://www.baeldung.com/java-ssl-debug-logging)
- More articles: [[<-- prev]](/core-java-modules/core-java-security-3)

View File

@ -3,11 +3,14 @@
- [How to Center Text Output in Java](https://www.baeldung.com/java-center-text-output)
- [Capitalize the First Letter of Each Word in a String](https://www.baeldung.com/java-string-initial-capital-letter-every-word)
- [Check if a String Contains Only Unicode Letters](https://www.baeldung.com/java-string-all-unicode-characters)
- [Create a Mutable String in Java](https://www.baeldung.com/java-mutable-string)
- [Create a Mutable String in Java](https://www.baeldung.com/java-mutable-string)
- [Check if a String Contains a Number Value in Java](https://www.baeldung.com/java-string-number-presence)
- [Difference Between String isEmpty() and isBlank()](https://www.baeldung.com/java-string-isempty-vs-isblank)
- [Strings Maximum Length in Java](https://www.baeldung.com/java-strings-maximum-length)
- [Javas String.length() and String.getBytes().length](https://www.baeldung.com/java-string-length-vs-getbytes-length)
- [Replace Non-Printable Unicode Characters in Java](https://www.baeldung.com/java-replace-non-printable-unicode-characters)
- [Check If a Java StringBuilder Object Contains a Character](https://www.baeldung.com/java-check-stringbuilder-object-contains-character)
- [Comparing One String With Multiple Values in One Expression in Java](https://www.baeldung.com/java-compare-string-multiple-values-one-expression)
- [UTF-8 Validation in Java](https://www.baeldung.com/java-utf-8-validation)
- [Simple Morse Code Translation in Java](https://www.baeldung.com/java-morse-code-english-translate)
- [How to Determine if a String Contains Invalid Encoded Characters](https://www.baeldung.com/java-check-string-contains-invalid-encoded-characters)

View File

@ -29,6 +29,16 @@
<artifactId>tsid-creator</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,64 @@
package com.baeldung.uuid;
import static org.apache.commons.codec.binary.Base64.decodeBase64;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.nio.ByteBuffer;
import java.util.Base64;
import java.util.UUID;
import org.apache.commons.lang3.Conversion;
import org.junit.jupiter.api.Test;
public class DecodeUUIDStringFromBase64UnitTest {
private final UUID originalUUID = UUID.fromString("cc5f93f7-8cf1-4a51-83c6-e740313a0c6c");
@Test
public void shouldDecodeUUIDUsingByteArrayAndBase64Decoder() {
String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw";
byte[] decodedBytes = Base64.getDecoder()
.decode(expectedEncodedString);
UUID uuid = convertToUUID(decodedBytes);
assertEquals(originalUUID, uuid);
}
@Test
public void shouldDecodeUUIDUsingByteBufferAndBase64UrlDecoder() {
String expectedEncodedString = "zF-T94zxSlGDxudAMToMbA";
byte[] decodedBytes = Base64.getUrlDecoder()
.decode(expectedEncodedString);
ByteBuffer byteBuffer = ByteBuffer.wrap(decodedBytes);
long mostSignificantBits = byteBuffer.getLong();
long leastSignificantBits = byteBuffer.getLong();
UUID uuid = new UUID(mostSignificantBits, leastSignificantBits);
assertEquals(originalUUID, uuid);
}
@Test
public void shouldDecodeUUIDUsingApacheUtils() {
String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw";
byte[] decodedBytes = decodeBase64(expectedEncodedString);
UUID uuid = Conversion.byteArrayToUuid(decodedBytes, 0);
assertEquals(originalUUID, uuid);
}
private UUID convertToUUID(byte[] src) {
long mostSignificantBits = convertBytesToLong(src, 0);
long leastSignificantBits = convertBytesToLong(src, 8);
return new UUID(mostSignificantBits, leastSignificantBits);
}
private long convertBytesToLong(byte[] uuidBytes, int start) {
long result = 0;
for(int i = 0; i < 8; i++) {
int shift = i * 8;
long bits = (255L & (long)uuidBytes[i + start]) << shift;
long mask = 255L << shift;
result = result & ~mask | bits;
}
return result;
}
}

View File

@ -0,0 +1,62 @@
package com.baeldung.uuid;
import static org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.nio.ByteBuffer;
import java.util.Base64;
import java.util.UUID;
import org.apache.commons.lang3.Conversion;
import org.junit.jupiter.api.Test;
public class EncodeUUIDToBase64StringUnitTest {
private final UUID originalUUID = UUID.fromString("cc5f93f7-8cf1-4a51-83c6-e740313a0c6c");
@Test
public void shouldEncodeUUIDUsingByteArrayAndBase64Encoder() {
String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw";
byte[] uuidBytes = convertToByteArray(originalUUID);
String encodedUUID = Base64.getEncoder().withoutPadding()
.encodeToString(uuidBytes);
assertEquals(expectedEncodedString, encodedUUID);
}
@Test
public void shouldEncodeUUIDUsingByteBufferAndBase64UrlEncoder() {
String expectedEncodedString = "zF-T94zxSlGDxudAMToMbA";
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
byteBuffer.putLong(originalUUID.getMostSignificantBits());
byteBuffer.putLong(originalUUID.getLeastSignificantBits());
String encodedUUID = Base64.getUrlEncoder().withoutPadding()
.encodeToString(byteBuffer.array());
assertEquals(expectedEncodedString, encodedUUID);
}
@Test
public void shouldEncodeUUIDUsingApacheUtils() {
String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw";
byte[] bytes = Conversion.uuidToByteArray(originalUUID, new byte[16], 0, 16);
String encodedUUID = encodeBase64URLSafeString(bytes);
assertEquals(expectedEncodedString, encodedUUID);
}
private byte[] convertToByteArray(UUID uuid) {
byte[] result = new byte[16];
long mostSignificantBits = uuid.getMostSignificantBits();
fillByteArray(0, 8, result, mostSignificantBits);
long leastSignificantBits = uuid.getLeastSignificantBits();
fillByteArray(8, 16, result, leastSignificantBits);
return result;
}
private static void fillByteArray(int start, int end, byte[] result, long bits) {
for (int i = start; i < end; i++) {
int shift = i * 8;
result[i] = (byte) ((int) (255L & bits >> shift));
}
}
}

View File

@ -6,3 +6,4 @@ This module contains articles about Gson
- [Solving Gson Parsing Errors](https://www.baeldung.com/gson-parsing-errors)
- [Difference between Gson @Expose and @SerializedName](https://www.baeldung.com/gson-expose-vs-serializedname)
- [Resolving Gsons “Multiple JSON Fields” Exception](https://www.baeldung.com/java-gson-multiple-json-fields-exception)
- [Using Static Methods Instead of Deprecated JsonParser](https://www.baeldung.com/java-static-methods-jsonparser-replacement)

View File

@ -9,4 +9,5 @@ This module contains articles about libraries for data processing in Java.
- [A Guide to Apache Crunch](https://www.baeldung.com/apache-crunch)
- [Intro to Apache Storm](https://www.baeldung.com/apache-storm)
- [Guide to JMapper](https://www.baeldung.com/jmapper)
More articles: [[next -->]](/../libraries-data-2)
- [What Does It Mean to Hydrate an Object?](https://www.baeldung.com/java-object-hydration)
- More articles: [[next -->]](/../libraries-data-2)

View File

@ -0,0 +1,2 @@
### Relevant Articles:
- [Difference Between mvn install and mvn verify](https://www.baeldung.com/maven-install-versus-verify)

View File

@ -1,3 +1,4 @@
## Relevant Articles
- [The Factory Design Pattern in Java](https://www.baeldung.com/java-factory-pattern)
- [Drawbacks of the Singleton Design Pattern](https://www.baeldung.com/java-patterns-singleton-cons)
- [Builder Pattern and Inheritance](https://www.baeldung.com/java-builder-pattern-inheritance)

View File

@ -0,0 +1,2 @@
### Relevant Articles:
- [Introduction to Apache Calcite](https://www.baeldung.com/apache-calcite)

View File

@ -1,2 +1,3 @@
## Relevant Articles
- [Scroll API in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-scroll-api)
- [List vs. Set in @OneToMany JPA](https://www.baeldung.com/spring-jpa-onetomany-list-vs-set)

View File

@ -8,4 +8,5 @@ This module contains articles about Spring Data JPA.
- [Hibernate Natural IDs in Spring Boot](https://www.baeldung.com/spring-boot-hibernate-natural-ids)
- [Correct Use of flush() in JPA](https://www.baeldung.com/spring-jpa-flush)
- [Difference Between findBy and findOneBy in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-findby-vs-findoneby)
- [How to Get Last Record in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-last-record)
- More articles: [[<-- prev]](../spring-data-jpa-repo-2)

View File

@ -30,6 +30,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>io.hypersistence</groupId>
<artifactId>hypersistence-utils-hibernate-55</artifactId>
<version>${hypersistance-utils-hibernate-55.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
@ -47,6 +52,30 @@
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
</dependencies>
<build>
@ -98,4 +127,9 @@
</plugins>
</build>
<properties>
<hypersistance-utils-hibernate-55.version>3.7.0</hypersistance-utils-hibernate-55.version>
<postgresql.version>42.7.1</postgresql.version>
</properties>
</project>

View File

@ -0,0 +1,15 @@
package com.baeldung.spring.data.persistence.json;
import lombok.*;
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
public class Address {
private String postCode;
private String city;
}

View File

@ -0,0 +1,36 @@
package com.baeldung.spring.data.persistence.json;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
@Converter
@Slf4j
public class AddressAttributeConverter implements AttributeConverter<Address, String> {
private static final ObjectMapper objectMapper = new ObjectMapper();
@Override
public String convertToDatabaseColumn(Address address) {
try {
return objectMapper.writeValueAsString(address);
} catch (JsonProcessingException jpe) {
log.warn("Cannot convert Address into JSON");
return null;
}
}
@Override
public Address convertToEntityAttribute(String value) {
try {
return objectMapper.readValue(value, Address.class);
} catch (JsonProcessingException e) {
log.warn("Cannot convert JSON into Address");
return null;
}
}
}

View File

@ -0,0 +1,13 @@
package com.baeldung.spring.data.persistence.json;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class JsonAttributeApplication {
public static void main(String[] args) {
SpringApplication.run(JsonAttributeApplication.class, args);
}
}

View File

@ -0,0 +1,31 @@
package com.baeldung.spring.data.persistence.json;
import javax.persistence.*;
import io.hypersistence.utils.hibernate.type.json.JsonBinaryType;
import lombok.*;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
@Entity
@Table(name = "student")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(of = {"id"})
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
public class StudentEntity {
@Id
@Column(name = "student_id", length = 8)
private String id;
@Column(name = "admit_year", length = 4)
private String admitYear;
@Type(type = "jsonb")
@Column(name = "address", columnDefinition = "jsonb")
private Address address;
}

View File

@ -0,0 +1,16 @@
package com.baeldung.spring.data.persistence.json;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface StudentRepository extends CrudRepository<StudentEntity, String> {
@Query(value = "SELECT * FROM student WHERE address->>'postCode' = :postCode", nativeQuery = true)
List<StudentEntity> findByAddressPostCode(@Param("postCode") String postCode);
}

View File

@ -0,0 +1,27 @@
package com.baeldung.spring.data.persistence.json;
import javax.persistence.*;
import lombok.*;
@Entity
@Table(name = "student_str")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(of = {"id"})
public class StudentStrEntity {
@Id
@Column(name = "student_id", length = 8)
private String id;
@Column(name = "admit_year", length = 4)
private String admitYear;
@Convert(converter = AddressAttributeConverter.class)
@Column(name = "address", length = 500)
private Address address;
}

View File

@ -0,0 +1,16 @@
package com.baeldung.spring.data.persistence.json;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface StudentStrRepository extends CrudRepository<StudentStrEntity, String> {
@Query(value = "SELECT * FROM student WHERE address->>'postCode' = :postCode", nativeQuery = true)
List<StudentStrEntity> findByAddressPostCode(@Param("postCode") String postCode);
}

View File

@ -0,0 +1,76 @@
package com.baeldung.spring.data.persistence.json;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.context.SpringBootTest;
import javax.inject.Inject;
import java.util.List;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = JsonAttributeApplication.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class JsonAttributeLiveTest {
@Inject
private StudentStrRepository studentStrRepository;
@Inject
private StudentRepository studentRepository;
@Test
@Order(10)
void whenSaveAnStudentStrEntityAndFindById_thenTheRecordPresentsInDb() {
String studentId = "23876371";
String postCode = "KT6 7BB";
Address address = new Address(postCode, "London");
StudentStrEntity studentStrEntity = StudentStrEntity.builder()
.id(studentId)
.admitYear("2023")
.address(address)
.build();
StudentStrEntity savedStudentStrEntity = studentStrRepository.save(studentStrEntity);
Optional<StudentStrEntity> studentEntityOptional = studentStrRepository.findById(studentId);
assertThat(studentEntityOptional.isPresent()).isTrue();
studentStrEntity = studentEntityOptional.get();
assertThat(studentStrEntity.getId()).isEqualTo(studentId);
assertThat(studentStrEntity.getAddress().getPostCode()).isEqualTo(postCode);
}
@Test
@Order(20)
void whenSaveAnStudentEntityAndFindById_thenTheRecordPresentsInDb() {
String studentId = "23876371";
String postCode = "KT6 7BB";
Address address = new Address(postCode, "London");
StudentEntity studentEntity = StudentEntity.builder()
.id(studentId)
.admitYear("2023")
.address(address)
.build();
StudentEntity savedStudentEntity = studentRepository.save(studentEntity);
Optional<StudentEntity> studentEntityOptional = studentRepository.findById(studentId);
assertThat(studentEntityOptional.isPresent()).isTrue();
studentEntity = studentEntityOptional.get();
assertThat(studentEntity.getId()).isEqualTo(studentId);
assertThat(studentEntity.getAddress().getPostCode()).isEqualTo(postCode);
}
@Test
@Order(50)
void whenFindByAddressPostCode_thenReturnListIsNotEmpty() {
String postCode = "KT6 7BB";
List<StudentStrEntity> studentStrEntityList = studentStrRepository.findByAddressPostCode(postCode);
assertThat(studentStrEntityList).isNotEmpty();
}
}

View File

@ -7,4 +7,4 @@
- [Obtaining Auto-generated Keys in Spring JDBC](https://www.baeldung.com/spring-jdbc-autogenerated-keys)
- [Spring JDBC Batch Inserts](https://www.baeldung.com/spring-jdbc-batch-inserts)
- [Fix EmptyResultDataAccessException When Using JdbcTemplate](https://www.baeldung.com/jdbctemplate-fix-emptyresultdataaccessexception)
- [How to replace deprecated jdbcTemplate.queryForObject and jdbcTemplate.query in spring boot 2.4.X and above](https://www.baeldung.com/spring-boot-replace-deprecated-jdbctemplate-queryforobject-query)
- [How to Replace Deprecated jdbcTemplate.queryForObject and jdbcTemplate.query in Spring Boot 2.4.X and above](https://www.baeldung.com/spring-boot-replace-deprecated-jdbctemplate-queryforobject-query)

View File

@ -465,10 +465,10 @@
<module>parent-spring-4</module>
<module>parent-spring-5</module>
<module>parent-spring-6</module>
<module>apache-spark</module>
<module>apache-spark</module>
<module>jhipster-modules</module>
<module>web-modules/restx</module>
</modules>
</profile>
@ -615,10 +615,10 @@
<module>parent-spring-4</module>
<module>parent-spring-5</module>
<module>parent-spring-6</module>
<module>apache-spark</module>
<module>apache-spark</module>
<module>jhipster-modules</module>
<module>web-modules/restx</module>
</modules>
</profile>

View File

@ -16,7 +16,7 @@
<modules>
<module>quarkus-project</module>
<!--<module>spring-project</module>--> <!-- Fixing in JAVA-24010 -->
<module>spring-project</module>
</modules>
</project>

View File

@ -103,9 +103,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<configuration>
<source>${maven.compiler.source.version}</source>
<target>${maven.compiler.target.version}</target>
<source>${maven.compiler.release}</source>
<target>${maven.compiler.release}</target>
</configuration>
</plugin>
</plugins>
@ -117,16 +118,30 @@
<name>Spring release</name>
<url>https://repo.spring.io/release</url>
</repository>
<repository>
<id>spring-milestone</id>
<name>Spring Milestone</name>
<url>https://repo.spring.io/milestone</url>
</repository>
<repository>
<id>spring-snapshot</id>
<name>Spring Snapshot</name>
<url>https://repo.spring.io/snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-release</id>
<name>Spring release</name>
<url>https://repo.spring.io/release</url>
<id>spring-milestone</id>
<name>Spring milestone</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
<profiles>
<profile>
<id>native</id>
@ -158,6 +173,7 @@
<plugin>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-aot-maven-plugin</artifactId>
<version>${spring-native.version}</version>
<executions>
<execution>
<id>test-generate</id>
@ -194,6 +210,7 @@
<plugin>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-aot-maven-plugin</artifactId>
<version>${spring-native.version}</version>
<executions>
<execution>
<id>test-generate</id>
@ -257,6 +274,7 @@
<maven-surefire-plugin.version>3.1.0</maven-surefire-plugin.version>
<native-buildtools.version>0.9.11</native-buildtools.version>
<jasync-r2dbc-mysql.version>2.0.8</jasync-r2dbc-mysql.version>
<maven.compiler.release>17</maven.compiler.release>
</properties>
</project>

View File

@ -0,0 +1,2 @@
### Relevant Articles:
- [Global Exception Handling with Spring Cloud Gateway](https://www.baeldung.com/spring-cloud-global-exception-handling)

View File

@ -0,0 +1,2 @@
### Relevant Articles
- [Introduction to gRPC with Spring Boot](https://www.baeldung.com/spring-boot-grpc)

View File

@ -1,3 +1,3 @@
## Relevant Articles
- [Observability with Spring Boot 3](https://www.baeldung.com/spring-boot-3-observability)
- [Observability With Spring Boot 3](https://www.baeldung.com/spring-boot-3-observability)
- [Intercept SQL Logging with P6Spy](https://www.baeldung.com/java-p6spy-intercept-sql-logging)

View File

@ -2,4 +2,5 @@
This module contains articles about various Spring Boot libraries
### Relevant Articles:
### Relevant Articles:
- [Event Externalization with Spring Modulith](https://www.baeldung.com/spring-modulith-event-externalization)

View File

@ -5,3 +5,4 @@ This module contains articles about Spring Boot testing with Spock framework
### Relevant Articles:
- [Testing with Spring and Spock](https://www.baeldung.com/spring-spock-testing)
- [Setting up and Using Spock With Gradle](https://www.baeldung.com/groovy/spock-gradle-setup)

View File

@ -1,3 +1,4 @@
# Spring Cloud AWS
TBD
### Relevant Articles:
- [Introduction to Spring Cloud AWS 3.0 SQS Integration](https://www.baeldung.com/java-spring-cloud-aws-v3-intro)

View File

@ -1,2 +1,3 @@
## Relevant Articles
- [Spring Kafka Trusted Packages Feature](https://www.baeldung.com/spring-kafka-trusted-packages-feature)
- [How to Catch Deserialization Errors in Spring-Kafka?](https://www.baeldung.com/spring-kafka-deserialization-errors)

View File

@ -2,7 +2,7 @@
This module contains articles about reactive Spring Boot.
- [Validation for Functional Endpoints in Spring 5](https://www.baeldung.com/spring-functional-endpoints-validation)
- [Validation for Functional Endpoints in Spring 6](https://www.baeldung.com/spring-functional-endpoints-validation)
- [Testing Reactive Streams Using StepVerifier and TestPublisher](https://www.baeldung.com/reactive-streams-step-verifier-test-publisher)
- [Static Content in Spring WebFlux](https://www.baeldung.com/spring-webflux-static-content)
- [Server-Sent Events in Spring](https://www.baeldung.com/spring-server-sent-events)

View File

@ -11,7 +11,8 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>spring-security-modules</artifactId>
<artifactId>parent-boot-3</artifactId>
<relativePath>../../parent-boot-3</relativePath>
<version>0.0.1-SNAPSHOT</version>
</parent>
@ -40,8 +41,12 @@
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>
</dependencies>
<properties>
<start-class>com.baeldung.springsecuritythymeleaf.SpringSecurityThymeleafApplication</start-class>
</properties>
</project>

View File

@ -7,7 +7,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;
import java.util.Collections;
import java.util.HashMap;

View File

@ -21,19 +21,14 @@ public class SecurityConfiguration {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.userDetailsService(userDetailsService)
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.defaultSuccessUrl("/index")
.and()
.logout()
.permitAll()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login");
.authorizeHttpRequests(authorizationManagerRequestMatcherRegistry -> authorizationManagerRequestMatcherRegistry
.anyRequest().authenticated())
.formLogin(httpSecurityFormLoginConfigurer -> httpSecurityFormLoginConfigurer
.loginPage("/login").permitAll()
.defaultSuccessUrl("/index"))
.logout(httpSecurityLogoutConfigurer -> httpSecurityLogoutConfigurer.permitAll()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login"));
return http.build();
}
}

View File

@ -16,19 +16,13 @@ public class SecurityConfiguration {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.successForwardUrl("/index")
.and()
.logout()
.permitAll()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login");
http.authorizeHttpRequests(authorizationManagerRequestMatcherRegistry ->
authorizationManagerRequestMatcherRegistry.anyRequest().authenticated())
.formLogin(httpSecurityFormLoginConfigurer ->
httpSecurityFormLoginConfigurer.loginPage("/login").permitAll().successForwardUrl("/index"))
.logout(httpSecurityLogoutConfigurer -> httpSecurityLogoutConfigurer.permitAll()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login"));
return http.build();
}

View File

@ -14,4 +14,5 @@ The "REST With Spring" Classes: https://bit.ly/restwithspring
- [Spring @RequestParam vs @PathVariable Annotations](https://www.baeldung.com/spring-requestparam-vs-pathvariable)
- [@RequestMapping Value in Properties File](https://www.baeldung.com/spring-requestmapping-properties-file)
- [Map a JSON POST to Multiple Spring MVC Parameters](https://www.baeldung.com/spring-mvc-json-param-mapping)
- [Getting Query String Parameters from HttpServletRequest](https://www.baeldung.com/java-httpservletrequest-get-query-parameters)
- More articles: [[<-- prev]](../spring-mvc-basics-4)

View File

@ -7,7 +7,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles:
- [How to Set a Header on a Response with Spring 5](https://www.baeldung.com/spring-response-header)
- [How to Set a Header on a Response with Spring 6](https://www.baeldung.com/spring-response-header)
- [Returning Custom Status Codes from Spring Controllers](https://www.baeldung.com/spring-mvc-controller-custom-http-status-code)
- [Spring RequestMapping](https://www.baeldung.com/spring-requestmapping)
- [Guide to DeferredResult in Spring](https://www.baeldung.com/spring-deferred-result)

View File

@ -7,4 +7,5 @@ This module contains articles about Spring with Thymeleaf
- [Conditionals in Thymeleaf](https://www.baeldung.com/spring-thymeleaf-conditionals)
- [Iteration in Thymeleaf](https://www.baeldung.com/thymeleaf-iteration)
- [Spring with Thymeleaf Pagination for a List](https://www.baeldung.com/spring-thymeleaf-pagination)
- [Display Image With Thymeleaf](https://www.baeldung.com/spring-thymeleaf-image)
- More articles: [[<-- prev]](../spring-thymeleaf-4)

View File

@ -0,0 +1,13 @@
package com.baeldung.thymeleaf.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class PetController {
@RequestMapping("/")
public String home() {
return "index";
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 KiB

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Baeldung Pet Store</title>
</head>
<body>
<h1>Welcome Image</h1>
<h6>Pet Store</h6>
<img th:src="@{images/cat.jpg}" alt="cat">
<img th:src="@{cat.jpg}" alt="cat">
</body>
</html>

View File

@ -3,3 +3,4 @@
- [Introduction to Testing with Spock and Groovy](http://www.baeldung.com/groovy-spock)
- [Difference Between Stub, Mock, and Spy in the Spock Framework](https://www.baeldung.com/spock-stub-mock-spy)
- [Guide to Spock Extensions](https://www.baeldung.com/spock-extensions)
- [Improving Test Coverage and Readability With Spocks Data Pipes and Tables](https://www.baeldung.com/java-spock-improve-test-coverage-data-feeds-tables)

View File

@ -10,9 +10,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
<relativePath>../../parent-boot-3</relativePath>
</parent>
<dependencies>
@ -156,14 +156,11 @@
</plugin>
</plugins>
</build>
<properties>
<jmeter-maven-plugin.version>3.7.0</jmeter-maven-plugin.version>
</properties>
</profile>
</profiles>
<properties>
<start-class>com.baeldung.dashboard.DashboardApplication</start-class>
<jmeter-maven-plugin.version>3.7.0</jmeter-maven-plugin.version>
</properties>

View File

@ -1,5 +1,7 @@
package com.baeldung.configuration;
import static org.springframework.security.config.Customizer.withDefaults;
import java.util.HashSet;
import java.util.Set;
@ -12,6 +14,7 @@ import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@Configuration
public class WebSecurityConfiguration {
@ -30,15 +33,17 @@ public class WebSecurityConfiguration {
}
@Bean
public SecurityFilterChain securityFilter(HttpSecurity http) throws Exception {
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/secured/**").authenticated()
.anyRequest().permitAll()
.and()
.httpBasic();
.authorizeHttpRequests(authorizeRequests ->
authorizeRequests
.requestMatchers(new AntPathRequestMatcher("/secured/**"))
.authenticated()
.anyRequest().permitAll()
)
.httpBasic(withDefaults());
return http.build();
}
}

View File

@ -1,6 +1,6 @@
package com.baeldung.domain;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotNull;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

View File

@ -35,7 +35,6 @@
<!-- <module>raml-modules</module> --> <!-- Not a maven project -->
<module>ratpack</module>
<module>resteasy</module>
<module>restx</module>
<module>rome</module>
<module>spark-java</module>
<module>struts-2</module>

View File

@ -9,9 +9,10 @@
<packaging>war</packaging>
<parent>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung</groupId>
<artifactId>web-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<dependencies>