diff --git a/.gitignore b/.gitignore index d3a5dae06d..78125cc3ee 100644 --- a/.gitignore +++ b/.gitignore @@ -85,7 +85,3 @@ transaction.log *-shell.log apache-cxf/cxf-aegis/baeldung.xml -apache-fop/src/test/resources/input.xml -apache-fop/src/test/resources/output_herold.pdf -apache-fop/src/test/resources/output_html2fo.pdf -apache-fop/src/test/resources/output_jtidy.pdf \ No newline at end of file diff --git a/core-groovy-2/determine-datatype/pom.xml b/core-groovy-2/determine-datatype/pom.xml deleted file mode 100644 index e03cb58ead..0000000000 --- a/core-groovy-2/determine-datatype/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - 4.0.0 - com.baeldung.groovy - determine-datatype - 0.0.1-SNAPSHOT - - src - - - maven-compiler-plugin - 3.8.0 - - 1.8 - 1.8 - - - - org.codehaus.gmaven - groovy-maven-plugin - - - org.codehaus.groovy - groovy-all - 2.0.6 - - - - - - - - - org.junit - junit5-engine - ${junit5.version} - - - - - 5.0.0-ALPHA - - \ No newline at end of file diff --git a/core-groovy-2/determine-datatype/src/com/baeldung/groovy/determine/datatype/Person.groovy b/core-groovy-2/determine-datatype/src/com/baeldung/groovy/determine/datatype/Person.groovy deleted file mode 100644 index 1a89dce435..0000000000 --- a/core-groovy-2/determine-datatype/src/com/baeldung/groovy/determine/datatype/Person.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.groovy.determine.datatype - -class Person { - - private int ageAsInt - private Double ageAsDouble - private String ageAsString - - Person() {} - Person(int ageAsInt) { this.ageAsInt = ageAsInt} - Person(Double ageAsDouble) { this.ageAsDouble = ageAsDouble} - Person(String ageAsString) { this.ageAsString = ageAsString} -} -class Student extends Person {} diff --git a/core-groovy-2/determine-datatype/src/com/baeldung/groovy/determine/datatype/PersonTest.groovy b/core-groovy-2/determine-datatype/src/com/baeldung/groovy/determine/datatype/PersonTest.groovy deleted file mode 100644 index 56095a3f1b..0000000000 --- a/core-groovy-2/determine-datatype/src/com/baeldung/groovy/determine/datatype/PersonTest.groovy +++ /dev/null @@ -1,55 +0,0 @@ -package com.baeldung.groovy.determine.datatype; - -import org.junit.Assert -import org.junit.Test; - -public class PersonTest { - - @Test - public void givenWhenParameterTypeIsInteger_thenReturnTrue() { - Person personObj = new Person(10) - Assert.assertTrue(personObj.ageAsInt instanceof Integer); - } - - @Test - public void givenWhenParameterTypeIsDouble_thenReturnTrue() { - Person personObj = new Person(10.0) - Assert.assertTrue((personObj.ageAsDouble).getClass() == Double) - } - - @Test - public void givenWhenParameterTypeIsString_thenReturnTrue() { - Person personObj = new Person("10 years") - Assert.assertTrue(personObj.ageAsString.class == String) - } - - @Test - public void givenClassName_WhenParameterIsInteger_thenReturnTrue() { - Assert.assertTrue(Person.class.getDeclaredField('ageAsInt').type == int.class) - } - - @Test - public void givenWhenObjectIsInstanceOfType_thenReturnTrue() { - Person personObj = new Person() - Assert.assertTrue(personObj instanceof Person) - } - - @Test - public void givenWhenInstanceIsOfSubtype_thenReturnTrue() { - Student studentObj = new Student() - Assert.assertTrue(studentObj in Person) - } - - @Test - public void givenGroovyList_WhenFindClassName_thenReturnTrue() { - def ageList = ['ageAsString','ageAsDouble', 10] - Assert.assertTrue(ageList.class == ArrayList) - Assert.assertTrue(ageList.getClass() == ArrayList) - } - - @Test - public void givenGrooyMap_WhenFindClassName_thenReturnTrue() { - def ageMap = [ageAsString: '10 years', ageAsDouble: 10.0] - Assert.assertFalse(ageMap.class == LinkedHashMap) - } -} \ No newline at end of file diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/size/JavaFolderSizeUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/size/JavaFolderSizeUnitTest.java index 467da4f76a..7fd7641a61 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/size/JavaFolderSizeUnitTest.java +++ b/core-java-modules/core-java-io/src/test/java/com/baeldung/size/JavaFolderSizeUnitTest.java @@ -72,7 +72,7 @@ public class JavaFolderSizeUnitTest { public void whenGetFolderSizeUsingGuava_thenCorrect() { final File folder = new File(path); - final Iterable files = com.google.common.io.Files.fileTreeTraverser().breadthFirstTraversal(folder); + final Iterable files = com.google.common.io.Files.fileTraverser().breadthFirst(folder); final long size = StreamSupport.stream(files.spliterator(), false).filter(File::isFile).mapToLong(File::length).sum(); assertEquals(EXPECTED_SIZE, size); diff --git a/core-java-modules/core-java-jvm-2/README.md b/core-java-modules/core-java-jvm-2/README.md new file mode 100644 index 0000000000..4925a268a9 --- /dev/null +++ b/core-java-modules/core-java-jvm-2/README.md @@ -0,0 +1,5 @@ +## Core Java JVM Cookbooks and Examples + +This module contains articles about working with the Java Virtual Machine (JVM). + +### Relevant Articles: \ No newline at end of file diff --git a/core-java-modules/core-java-jvm-2/pom.xml b/core-java-modules/core-java-jvm-2/pom.xml new file mode 100644 index 0000000000..71dca18094 --- /dev/null +++ b/core-java-modules/core-java-jvm-2/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + core-java-jvm-2 + 0.1.0-SNAPSHOT + core-java-jvm-2 + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + + junit + junit + ${junit.version} + test + + + org.assertj + assertj-core + ${assertj.version} + test + + + org.openjdk.jol + jol-core + ${jol-core.version} + + + + + 3.6.1 + 0.10 + + + diff --git a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/arraylength/ArrayLengthUnitTest.java b/core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/arraylength/ArrayLengthUnitTest.java similarity index 100% rename from core-java-modules/core-java-jvm/src/test/java/com/baeldung/arraylength/ArrayLengthUnitTest.java rename to core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/arraylength/ArrayLengthUnitTest.java diff --git a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java b/core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java similarity index 99% rename from core-java-modules/core-java-jvm/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java rename to core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java index 005ece0195..2f226d7657 100644 --- a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java +++ b/core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java @@ -91,7 +91,7 @@ public class MemoryLayoutUnitTest { private boolean first; private char second; private double third; - private int forth; + private int fourth; private boolean fifth; } diff --git a/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEquals.java b/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEquals.java index e3a61fc05a..1358393538 100644 --- a/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEquals.java +++ b/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEquals.java @@ -22,15 +22,15 @@ public class PersonWithEquals { this.birthDate = birthDate; } - public String firstName() { + public String getFirstName() { return firstName; } - public String lastName() { + public String getLastName() { return lastName; } - public LocalDate birthDate() { + public LocalDate getBirthDate() { return birthDate; } diff --git a/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEqualsAndComparable.java b/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEqualsAndComparable.java index 5611ce8a09..b358271cae 100644 --- a/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEqualsAndComparable.java +++ b/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEqualsAndComparable.java @@ -22,6 +22,18 @@ public class PersonWithEqualsAndComparable implements Comparable timeToDeliveryToEnumValuesMapping = new HashMap<>(); static { - PizzaStatus[] pizzaStatuses = PizzaStatus.values(); - for (int pizzaStatusIndex = 0; pizzaStatusIndex < pizzaStatuses.length; pizzaStatusIndex++) { + for (PizzaStatus pizzaStatus : PizzaStatus.values()) { timeToDeliveryToEnumValuesMapping.put( - pizzaStatuses[pizzaStatusIndex].getTimeToDelivery(), - pizzaStatuses[pizzaStatusIndex] + pizzaStatus.getTimeToDelivery(), + pizzaStatus ); } } diff --git a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparing/ComparatorInterfaceUnitTest.java b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparing/ComparatorInterfaceUnitTest.java index 769ae60bed..e2f66a5ebd 100644 --- a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparing/ComparatorInterfaceUnitTest.java +++ b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparing/ComparatorInterfaceUnitTest.java @@ -20,7 +20,7 @@ class ComparatorInterfaceUnitTest { Comparator compareByFirstNames = new Comparator() { @Override public int compare(PersonWithEquals o1, PersonWithEquals o2) { - return o1.firstName().compareTo(o2.firstName()); + return o1.getFirstName().compareTo(o2.getFirstName()); } }; people.sort(compareByFirstNames); @@ -37,7 +37,7 @@ class ComparatorInterfaceUnitTest { people.add(joe); people.add(allan); - Comparator compareByFirstNames = Comparator.comparing(PersonWithEquals::firstName); + Comparator compareByFirstNames = Comparator.comparing(PersonWithEquals::getFirstName); people.sort(compareByFirstNames); assertThat(people).containsExactly(allan, joe); diff --git a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparing/GuavaUnitTest.java b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparing/GuavaUnitTest.java index 5c8591e134..129efd54ea 100644 --- a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparing/GuavaUnitTest.java +++ b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparing/GuavaUnitTest.java @@ -63,8 +63,8 @@ class GuavaUnitTest { PersonWithEquals joe = new PersonWithEquals("Joe", "Portman"); int comparisonResult = ComparisonChain.start() - .compare(natalie.lastName(), joe.lastName()) - .compare(natalie.firstName(), joe.firstName()) + .compare(natalie.getLastName(), joe.getLastName()) + .compare(natalie.getFirstName(), joe.getFirstName()) .result(); assertThat(comparisonResult).isPositive(); diff --git a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/inttoenum/IntToEnumUnitTest.java b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/inttoenum/IntToEnumUnitTest.java index 876c230827..aed8ce0a2b 100644 --- a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/inttoenum/IntToEnumUnitTest.java +++ b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/inttoenum/IntToEnumUnitTest.java @@ -1,7 +1,12 @@ package com.baeldung.inttoenum; +import org.assertj.core.api.Assertions; import org.junit.Test; +import java.util.Arrays; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; public class IntToEnumUnitTest { @@ -9,19 +14,33 @@ public class IntToEnumUnitTest { @Test public void whenIntToEnumUsingValuesMethod_thenReturnEnumObject() { int timeToDeliveryForOrderedPizzaStatus = 5; - PizzaStatus[] pizzaStatuses = PizzaStatus.values(); + PizzaStatus pizzaOrderedStatus = null; - for (int pizzaStatusIndex = 0; pizzaStatusIndex < pizzaStatuses.length; pizzaStatusIndex++) { - if (pizzaStatuses[pizzaStatusIndex].getTimeToDelivery() == timeToDeliveryForOrderedPizzaStatus) { - pizzaOrderedStatus = pizzaStatuses[pizzaStatusIndex]; + + for (PizzaStatus pizzaStatus : PizzaStatus.values()) { + if (pizzaStatus.getTimeToDelivery() == timeToDeliveryForOrderedPizzaStatus) { + pizzaOrderedStatus = pizzaStatus; } } - assertEquals(pizzaOrderedStatus, PizzaStatus.ORDERED); + + assertThat(pizzaOrderedStatus).isEqualTo(PizzaStatus.ORDERED); } @Test public void whenIntToEnumUsingMap_thenReturnEnumObject() { int timeToDeliveryForOrderedPizzaStatus = 5; - assertEquals(PizzaStatus.castIntToEnum(timeToDeliveryForOrderedPizzaStatus), PizzaStatus.ORDERED); + + assertThat(PizzaStatus.castIntToEnum(timeToDeliveryForOrderedPizzaStatus)).isEqualTo(PizzaStatus.ORDERED); + } + + @Test + public void whenIntToEnumUsingStream_thenReturnEnumObject() { + int timeToDeliveryForOrderedPizzaStatus = 5; + + Optional pizzaStatus = Arrays.stream(PizzaStatus.values()) + .filter(p -> p.getTimeToDelivery() == timeToDeliveryForOrderedPizzaStatus) + .findFirst(); + + assertThat(pizzaStatus).hasValue(PizzaStatus.ORDERED); } } \ No newline at end of file diff --git a/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/macaddress/GetAllMacAddressesDemo.java b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/macaddress/GetAllMacAddressesDemo.java new file mode 100644 index 0000000000..8f07d4133e --- /dev/null +++ b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/macaddress/GetAllMacAddressesDemo.java @@ -0,0 +1,23 @@ +package com.baeldung.macaddress; + +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Enumeration; + +public class GetAllMacAddressesDemo { + + public static void main(String[] args) throws SocketException { + Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); + while (networkInterfaces.hasMoreElements()) { + NetworkInterface ni = networkInterfaces.nextElement(); + byte[] hardwareAddress = ni.getHardwareAddress(); + if (hardwareAddress != null) { + String[] hexadecimalFormat = new String[hardwareAddress.length]; + for (int i = 0; i < hardwareAddress.length; i++) { + hexadecimalFormat[i] = String.format("%02X", hardwareAddress[i]); + } + System.out.println(String.join("-", hexadecimalFormat)); + } + } + } +} diff --git a/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/macaddress/MacAddressUnitTest.java b/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/macaddress/MacAddressUnitTest.java new file mode 100644 index 0000000000..293e92c690 --- /dev/null +++ b/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/macaddress/MacAddressUnitTest.java @@ -0,0 +1,21 @@ +package com.baeldung.macaddress; + +import org.junit.Test; + +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; + +import static org.junit.Assert.assertEquals; + +public class MacAddressUnitTest { + + @Test + public void givenNetworkInterface_whenUsingLocalHost_thenGetMacAddress() throws UnknownHostException, SocketException { + InetAddress localHost = InetAddress.getLocalHost(); + NetworkInterface ni = NetworkInterface.getByInetAddress(localHost); + byte[] macAddress = ni.getHardwareAddress(); + assertEquals(6, macAddress.length); + } +} diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/deserialization/DefaultSerial.java b/core-java-modules/core-java/src/main/java/com/baeldung/deserialization/DefaultSerial.java new file mode 100644 index 0000000000..ddfef9a1d2 --- /dev/null +++ b/core-java-modules/core-java/src/main/java/com/baeldung/deserialization/DefaultSerial.java @@ -0,0 +1,15 @@ +package com.baeldung.deserialization; + +import java.io.IOException; +import java.io.Serializable; + +public class DefaultSerial implements Serializable { + + private String name; + + public static void main(String[] args) throws IOException, ClassNotFoundException { + String digest = "rO0ABXNyACpjb20uYmFlbGR1bmcuZGVzZXJpY" + + "WxpemF0aW9uLkRlZmF1bHRTZXJpYWx9iVz3Lz/mdAIAAHhw"; + DefaultSerial instance = (DefaultSerial) DeserializationUtility.deSerializeObjectFromString(digest); + } +} diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 26c374b51d..76fed91251 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -80,6 +80,7 @@ core-java-jndi core-java-jvm + core-java-jvm-2 core-java-lambdas core-java-lang diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt index 1077eb94f9..8a0ee48a36 100644 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt +++ b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt @@ -6,6 +6,7 @@ interface Page { fun elements(): MutableList } +operator fun Page.invoke(index: Int): T = elements()[index] operator fun Page.get(index: Int): T = elements()[index] operator fun Page.get(start: Int, endExclusive: Int): List = elements().subList(start, endExclusive) operator fun Page.set(index: Int, value: T) { diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PageTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PageTest.kt index 4217fc0c08..fa6e1773bd 100644 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PageTest.kt +++ b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PageTest.kt @@ -14,6 +14,11 @@ class PageTest { assertEquals(page[1, 3], listOf("Kotlin", "Scala")) } + @Test + fun `Invoke convention should work as expected`() { + assertEquals(page(1), "Kotlin") + } + @Test fun `In convention should work on a page as expected`() { assertTrue("Kotlin" in page) diff --git a/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java b/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java new file mode 100644 index 0000000000..6b315265b4 --- /dev/null +++ b/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java @@ -0,0 +1,75 @@ +package com.baeldung.circularbuffer; + +public class CircularBuffer { + + private static final int DEFAULT_CAPACITY = 8; + + private final int capacity; + private final E[] data; + private volatile int writeSequence, readSequence; + + @SuppressWarnings("unchecked") + public CircularBuffer(int capacity) { + + this.capacity = (capacity < 1) ? DEFAULT_CAPACITY : capacity; + this.data = (E[]) new Object[capacity]; + + this.readSequence = 0; + this.writeSequence = -1; + } + + public boolean offer(E element) { + + if (isNotFull()) { + + int nextWriteSeq = writeSequence + 1; + data[nextWriteSeq % capacity] = element; + + writeSequence++; + return true; + } + + return false; + } + + public E poll() { + + if (isNotEmpty()) { + + E nextValue = data[readSequence % capacity]; + readSequence++; + return nextValue; + } + + return null; + } + + public int capacity() { + return capacity; + } + + public int size() { + + return (writeSequence - readSequence) + 1; + } + + public boolean isEmpty() { + + return writeSequence < readSequence; + } + + public boolean isFull() { + + return size() >= capacity; + } + + private boolean isNotEmpty() { + + return !isEmpty(); + } + + private boolean isNotFull() { + + return !isFull(); + } +} diff --git a/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java b/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java new file mode 100644 index 0000000000..4b8e8646f3 --- /dev/null +++ b/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java @@ -0,0 +1,72 @@ +package com.baeldung.circularbuffer; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class CircularBufferUnitTest { + + private final String[] shapes = { "Circle", "Triangle", "Rectangle", "Square", "Rhombus", "Trapezoid", "Pentagon", "Pentagram", "Hexagon", "Hexagram" }; + private final int defaultCapacity = shapes.length; + + @Test + public void givenCircularBuffer_whenAnElementIsEnqueued_thenSizeIsOne() { + CircularBuffer buffer = new CircularBuffer<>(defaultCapacity); + + assertTrue(buffer.offer("Square")); + assertEquals(1, buffer.size()); + } + + @Test + public void givenCircularBuffer_whenAnElementIsDequeued_thenElementMatchesEnqueuedElement() { + CircularBuffer buffer = new CircularBuffer<>(defaultCapacity); + + buffer.offer("Triangle"); + + String shape = buffer.poll(); + assertEquals("Triangle", shape); + } + + @Test + public void givenCircularBuffer_whenAnElementIsEnqueuedAndDeququed_thenBufferIsEmpty() { + + CircularBuffer buffer = new CircularBuffer<>(defaultCapacity); + + buffer.offer("Rectangle"); + + assertFalse(buffer.isEmpty()); + assertEquals(1, buffer.size()); + + buffer.poll(); + + assertTrue(buffer.isEmpty()); + } + + @Test + public void givenCircularBuffer_whenFilledToCapacity_thenNoMoreElementsCanBeEnqueued() { + + int capacity = shapes.length; + CircularBuffer buffer = new CircularBuffer<>(capacity); + + assertTrue(buffer.isEmpty()); + + for (String shape : shapes) { + buffer.offer(shape); + } + + assertTrue(buffer.isFull()); + assertFalse(buffer.offer("Octagon")); + } + + @Test + public void givenCircularBuffer_whenBufferIsEmpty_thenReturnsNull() { + + CircularBuffer buffer = new CircularBuffer<>(1); + + assertTrue(buffer.isEmpty()); + assertNull(buffer.poll()); + } +} diff --git a/data-structures/src/test/java/com/baeldung/circularbuffer/ProducerConsumerLiveTest.java b/data-structures/src/test/java/com/baeldung/circularbuffer/ProducerConsumerLiveTest.java new file mode 100644 index 0000000000..83ce27043b --- /dev/null +++ b/data-structures/src/test/java/com/baeldung/circularbuffer/ProducerConsumerLiveTest.java @@ -0,0 +1,80 @@ +package com.baeldung.circularbuffer; + +import static org.junit.Assert.assertArrayEquals; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.LockSupport; + +import org.junit.jupiter.api.Test; + +public class ProducerConsumerLiveTest { + + private final String[] shapes = { "Circle", "Triangle", "Rectangle", "Square", "Rhombus", "Trapezoid", "Pentagon", "Pentagram", "Hexagon", "Hexagram" }; + + @Test + public void givenACircularBuffer_whenInterleavingProducerConsumer_thenElementsMatch() throws Exception { + CircularBuffer buffer = new CircularBuffer(shapes.length); + + ExecutorService executorService = Executors.newFixedThreadPool(2); + + executorService.submit(new Producer(buffer, shapes)); + Future consumed = executorService.submit(new Consumer(buffer, shapes.length)); + + String[] shapesConsumed = consumed.get(5L, TimeUnit.SECONDS); + assertArrayEquals(shapes, shapesConsumed); + } + + static class Producer implements Runnable { + + private CircularBuffer buffer; + private T[] items; + + public Producer(CircularBuffer buffer, T[] items) { + this.buffer = buffer; + this.items = items; + } + + @Override + public void run() { + + for (int i = 0; i < items.length;) { + if (buffer.offer(items[i])) { + System.out.println("Produced: " + items[i]); + i++; + LockSupport.parkNanos(5); + } + } + } + } + + @SuppressWarnings("unchecked") + static class Consumer implements Callable { + + private CircularBuffer buffer; + private int expectedCount; + + public Consumer(CircularBuffer buffer, int expectedCount) { + this.buffer = buffer; + this.expectedCount = expectedCount; + } + + @Override + public T[] call() throws Exception { + T[] items = (T[]) new Object[expectedCount]; + for (int i = 0; i < items.length;) { + T item = buffer.poll(); + if (item != null) { + items[i++] = item; + + LockSupport.parkNanos(5); + System.out.println("Consumed: " + item); + } + } + return items; + } + } +} diff --git a/gradle-5/.gitignore b/gradle-5/.gitignore new file mode 100644 index 0000000000..4ded91f387 --- /dev/null +++ b/gradle-5/.gitignore @@ -0,0 +1,2 @@ +**/build/** +/build/ diff --git a/gradle-5/build.gradle b/gradle-5/build.gradle index a728845dff..84cf05bad6 100644 --- a/gradle-5/build.gradle +++ b/gradle-5/build.gradle @@ -1,54 +1,21 @@ -plugins { - id "application" -} -apply plugin :"java" - -description = "Java MainClass execution examples" -group = "com.baeldung" -version = "0.0.1" -sourceCompatibility = "1.8" -targetCompatibility = "1.8" - -ext { - javaMainClass = "com.baeldung.gradle.exec.MainClass" +plugins{ + id "nebula.lint" version "16.9.0" } -jar { - manifest { - attributes( - "Main-Class": javaMainClass - ) +description = "Gradle 5 root project" +allprojects { + apply plugin :"java" + apply plugin :"nebula.lint" + gradleLint { + rules=['unused-dependency'] + reportFormat = 'text' } -} + group = "com.baeldung" + version = "0.0.1" + sourceCompatibility = "1.8" + targetCompatibility = "1.8" -application { - mainClassName = javaMainClass -} - -task runWithJavaExec(type: JavaExec) { - group = "Execution" - description = "Run the main class with JavaExecTask" - classpath = sourceSets.main.runtimeClasspath - main = javaMainClass -} - -task runWithExec(type: Exec) { - dependsOn build - group = "Execution" - description = "Run the main class with ExecTask" - commandLine "java", "-classpath", sourceSets.main.runtimeClasspath.getAsPath(), javaMainClass -} - -task runWithExecJarExecutable(type: Exec) { - dependsOn jar - group = "Execution" - description = "Run the output executable jar with ExecTask" - commandLine "java", "-jar", jar.archiveFile.get() -} - -task runWithExecJarOnClassPath(type: Exec) { - dependsOn jar - group = "Execution" - description = "Run the mainClass from the output jar in classpath with ExecTask" - commandLine "java", "-classpath", jar.archiveFile.get() , javaMainClass + repositories { + jcenter() + } } \ No newline at end of file diff --git a/gradle-5/gradle/wrapper/gradle-wrapper.properties b/gradle-5/gradle/wrapper/gradle-wrapper.properties index b33419deee..4c46317507 100644 --- a/gradle-5/gradle/wrapper/gradle-wrapper.properties +++ b/gradle-5/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip diff --git a/gradle-5/java-exec/.gitignore b/gradle-5/java-exec/.gitignore new file mode 100644 index 0000000000..84c048a73c --- /dev/null +++ b/gradle-5/java-exec/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/gradle-5/java-exec/build.gradle b/gradle-5/java-exec/build.gradle new file mode 100644 index 0000000000..08aa738902 --- /dev/null +++ b/gradle-5/java-exec/build.gradle @@ -0,0 +1,47 @@ +apply plugin: "application" + +description = "Java MainClass execution examples" + +ext { + javaMainClass = "com.baeldung.gradle.exec.MainClass" +} + +jar { + manifest { + attributes( + "Main-Class": javaMainClass + ) + } +} + +application { + mainClassName = javaMainClass +} + +task runWithJavaExec(type: JavaExec) { + group = "Execution" + description = "Run the main class with JavaExecTask" + classpath = sourceSets.main.runtimeClasspath + main = javaMainClass +} + +task runWithExec(type: Exec) { + dependsOn build + group = "Execution" + description = "Run the main class with ExecTask" + commandLine "java", "-classpath", sourceSets.main.runtimeClasspath.getAsPath(), javaMainClass +} + +task runWithExecJarExecutable(type: Exec) { + dependsOn jar + group = "Execution" + description = "Run the output executable jar with ExecTask" + commandLine "java", "-jar", jar.archiveFile.get() +} + +task runWithExecJarOnClassPath(type: Exec) { + dependsOn jar + group = "Execution" + description = "Run the mainClass from the output jar in classpath with ExecTask" + commandLine "java", "-classpath", jar.archiveFile.get() , javaMainClass +} \ No newline at end of file diff --git a/gradle-5/src/main/java/com/baeldung/gradle/exec/MainClass.java b/gradle-5/java-exec/src/main/java/com/baeldung/gradle/exec/MainClass.java similarity index 100% rename from gradle-5/src/main/java/com/baeldung/gradle/exec/MainClass.java rename to gradle-5/java-exec/src/main/java/com/baeldung/gradle/exec/MainClass.java diff --git a/gradle-5/settings.gradle b/gradle-5/settings.gradle new file mode 100644 index 0000000000..1997e12ca5 --- /dev/null +++ b/gradle-5/settings.gradle @@ -0,0 +1,3 @@ +rootProject.name='gradle-5-articles' +include 'java-exec' +include 'unused-dependencies' \ No newline at end of file diff --git a/gradle-5/unused-dependencies/.gitignore b/gradle-5/unused-dependencies/.gitignore new file mode 100644 index 0000000000..84c048a73c --- /dev/null +++ b/gradle-5/unused-dependencies/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/gradle-5/unused-dependencies/build.gradle b/gradle-5/unused-dependencies/build.gradle new file mode 100644 index 0000000000..d848cd0e0d --- /dev/null +++ b/gradle-5/unused-dependencies/build.gradle @@ -0,0 +1,8 @@ + +description = "Gradle Unused Dependencies example" + +dependencies { + implementation('com.google.guava:guava:29.0-jre') + implementation('org.apache.httpcomponents:httpclient:4.5.12') + testImplementation('junit:junit:4.12') +} diff --git a/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java b/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java new file mode 100644 index 0000000000..c2e221356c --- /dev/null +++ b/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java @@ -0,0 +1,39 @@ +package com.baeldung.unused; + +import java.lang.reflect.Method; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.http.ssl.SSLContextBuilder; + +import com.google.common.collect.ImmutableList; + +public class UnusedDependencies { + + public static void main(String[] args) { + System.out.println("Hello world"); + useGuava(); + useHttpCore(); + useHttpClientWithReflection(); + } + + private static void useGuava() { + List list = ImmutableList.of("Baledung", "is", "cool"); + System.out.println(list.stream() + .collect(Collectors.joining(" "))); + } + + private static void useHttpCore() { + SSLContextBuilder.create(); + } + + private static void useHttpClientWithReflection() { + try { + Class httpBuilder = Class.forName("org.apache.http.impl.client.HttpClientBuilder"); + Method create = httpBuilder.getMethod("create", null); + create.invoke(httpBuilder, null); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/guava-collections/README.md b/guava-collections/README.md index 51731d7db7..17cdb91ef5 100644 --- a/guava-collections/README.md +++ b/guava-collections/README.md @@ -14,3 +14,4 @@ This module contains articles about Google Guava collections - [Guava – Lists](https://www.baeldung.com/guava-lists) - [Guide to Guava MinMaxPriorityQueue and EvictingQueue](https://www.baeldung.com/guava-minmax-priority-queue-and-evicting-queue) - [Guide to Guava Table](https://www.baeldung.com/guava-table) +- [Guava CharMatcher](https://www.baeldung.com/guava-string-charmatcher) diff --git a/guava-collections/src/test/java/com/baeldung/guava/joinsplit/GuavaStringUnitTest.java b/guava-collections/src/test/java/com/baeldung/guava/joinsplit/GuavaStringUnitTest.java index 73c4c3291e..0c480d02a0 100644 --- a/guava-collections/src/test/java/com/baeldung/guava/joinsplit/GuavaStringUnitTest.java +++ b/guava-collections/src/test/java/com/baeldung/guava/joinsplit/GuavaStringUnitTest.java @@ -117,7 +117,7 @@ public class GuavaStringUnitTest { @Test public void whenRemoveSpecialCharacters_thenRemoved() { final String input = "H*el.lo,}12"; - final CharMatcher matcher = CharMatcher.JAVA_LETTER_OR_DIGIT; + final CharMatcher matcher = CharMatcher.javaLetterOrDigit(); final String result = matcher.retainFrom(input); assertEquals("Hello12", result); @@ -127,7 +127,7 @@ public class GuavaStringUnitTest { public void whenRemoveNonASCIIChars_thenRemoved() { final String input = "あhello₤"; - String result = CharMatcher.ASCII.retainFrom(input); + String result = CharMatcher.ascii().retainFrom(input); assertEquals("hello", result); result = CharMatcher.inRange('0', 'z').retainFrom(input); @@ -138,13 +138,13 @@ public class GuavaStringUnitTest { public void whenValidateString_thenValid() { final String input = "hello"; - boolean result = CharMatcher.JAVA_LOWER_CASE.matchesAllOf(input); + boolean result = CharMatcher.javaLowerCase().matchesAllOf(input); assertTrue(result); result = CharMatcher.is('e').matchesAnyOf(input); assertTrue(result); - result = CharMatcher.JAVA_DIGIT.matchesNoneOf(input); + result = CharMatcher.javaDigit().matchesNoneOf(input); assertTrue(result); } diff --git a/java-numbers-3/src/test/java/com/baeldung/divisionbyzero/DivisionByZeroUnitTest.java b/java-numbers-3/src/test/java/com/baeldung/divisionbyzero/DivisionByZeroUnitTest.java new file mode 100644 index 0000000000..0e0e099d91 --- /dev/null +++ b/java-numbers-3/src/test/java/com/baeldung/divisionbyzero/DivisionByZeroUnitTest.java @@ -0,0 +1,76 @@ +package com.baeldung.divisionbyzero; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class DivisionByZeroUnitTest { + + @Test + void givenInt_whenDividedByZero_thenThrowException() { + assertThrows(ArithmeticException.class, () -> { + int result = 12 / 0; + }); + } + + @Test + void whenDividingIntZeroByZero_thenThrowException() { + assertThrows(ArithmeticException.class, () -> { + int result = 0 / 0; + }); + } + + @Test + void whenDividingFloatingNumberByZero_thenNoExceptionIsThrown() { + assertDoesNotThrow(() -> { + float result = 0f / 0; + }); + assertDoesNotThrow(() -> { + double result = 0d / 0; + }); + } + + @Test + void givenPositiveFloatingNumber_whenDividedByZero_thenReturnPositiveInfinity() { + assertEquals(Float.POSITIVE_INFINITY, 12f / 0); + assertEquals(Double.POSITIVE_INFINITY, 12d / 0); + } + + @Test + void givenNegativeFloatingNumber_whenDividedByZero_thenReturnNegativeInfinity() { + assertEquals(Float.NEGATIVE_INFINITY, -12f / 0); + assertEquals(Double.NEGATIVE_INFINITY, -12d / 0); + } + + @Test + void givenPositiveFloatingNumber_whenDividedByNegativeZero_thenReturnNegativeInfinity() { + assertEquals(Float.NEGATIVE_INFINITY, 12f / -0f); + assertEquals(Double.NEGATIVE_INFINITY, 12f / -0f); + } + + @Test + void whenDividingFloatingNumberZeroByZero_thenReturnNaN() { + assertEquals(Float.NaN, 0f / 0); + assertEquals(Double.NaN, 0d / 0); + } + + @Test + void givenABitRepresentationWithAllExponentBitsZeroesAndAllFractionBitsZeroes_whenTransformingItToFloat_thenReturnPositiveZero() { + assertEquals(0f, Float.intBitsToFloat(0b00000000000000000000000000000000)); + assertEquals(-0f, Float.intBitsToFloat(0b10000000000000000000000000000000)); + } + + @Test + void givenABitRepresentationWithAllExponentBitsOnesAndAllFractionBitsZeroes_whenTransformingItToFloat_thenReturnInfinity() { + assertEquals(Float.POSITIVE_INFINITY, Float.intBitsToFloat(0b01111111100000000000000000000000)); + assertEquals(Float.NEGATIVE_INFINITY, Float.intBitsToFloat(0b11111111100000000000000000000000)); + } + + @Test + void givenABitRepresentationWithAllExponentBitsOnesAndNotAllFractionBitsZeroes_whenTransformingItToFloat_thenReturnNan() { + assertEquals(Float.NaN, Float.intBitsToFloat(0b11111111100000010000000000000000)); + assertEquals(Float.NaN, Float.intBitsToFloat(0b11111111100000011000000000100000)); + assertEquals(Float.NaN, Float.intBitsToFloat(0b11111111100000011100000000000000)); + assertEquals(Float.NaN, Float.intBitsToFloat(0b11111111100000011110000000000000)); + } +} diff --git a/libraries-testing/README.md b/libraries-testing/README.md index ffdefe4b19..43d7673e2d 100644 --- a/libraries-testing/README.md +++ b/libraries-testing/README.md @@ -8,7 +8,7 @@ This module contains articles about test libraries. - [Introduction to JSONassert](https://www.baeldung.com/jsonassert) - [Serenity BDD and Screenplay](https://www.baeldung.com/serenity-screenplay) - [Serenity BDD with Spring and JBehave](https://www.baeldung.com/serenity-spring-jbehave) -- [Introduction to Awaitlity](https://www.baeldung.com/awaitlity-testing) +- [Introduction to Awaitility](https://www.baeldung.com/awaitlity-testing) - [Introduction to Hoverfly in Java](https://www.baeldung.com/hoverfly) - [Testing with Hamcrest](https://www.baeldung.com/java-junit-hamcrest-guide) - [Introduction To DBUnit](https://www.baeldung.com/java-dbunit) diff --git a/parent-java/pom.xml b/parent-java/pom.xml index f56ffbd7f7..d251adcdd3 100644 --- a/parent-java/pom.xml +++ b/parent-java/pom.xml @@ -42,7 +42,7 @@ - 23.0 + 29.0-jre 2.6 1.19 2.3.7 diff --git a/persistence-modules/hibernate5/README.md b/persistence-modules/hibernate5/README.md index bd437c80eb..8793e2e9c7 100644 --- a/persistence-modules/hibernate5/README.md +++ b/persistence-modules/hibernate5/README.md @@ -4,7 +4,7 @@ This module contains articles about Hibernate 5. Let's not add more articles her ### Relevant articles: -- [An Overview of Identifiers in Hibernate](https://www.baeldung.com/hibernate-identifiers) +- [An Overview of Identifiers in Hibernate/JPA](https://www.baeldung.com/hibernate-identifiers) - [Hibernate Interceptors](https://www.baeldung.com/hibernate-interceptor) - [Hibernate Entity Lifecycle](https://www.baeldung.com/hibernate-entity-lifecycle) - [Hibernate 5 Naming Strategy Configuration](https://www.baeldung.com/hibernate-naming-strategy) @@ -12,4 +12,4 @@ This module contains articles about Hibernate 5. Let's not add more articles her - [Hibernate 5 Bootstrapping API](https://www.baeldung.com/hibernate-5-bootstrapping-api) - [Guide to the Hibernate EntityManager](https://www.baeldung.com/hibernate-entitymanager) - [Using c3p0 with Hibernate](https://www.baeldung.com/hibernate-c3p0) -- [Persist a JSON Object Using Hibernate](https://www.baeldung.com/hibernate-persist-json-object) \ No newline at end of file +- [Persist a JSON Object Using Hibernate](https://www.baeldung.com/hibernate-persist-json-object) diff --git a/persistence-modules/redis/pom.xml b/persistence-modules/redis/pom.xml index b8f76c09c4..e4c5eb4002 100644 --- a/persistence-modules/redis/pom.xml +++ b/persistence-modules/redis/pom.xml @@ -33,7 +33,7 @@ redis.clients jedis - ${redisson.version} + ${jedis.version} com.github.kstyrc @@ -48,12 +48,19 @@ io.lettuce lettuce-core - + + + io.netty + netty-transport-native-epoll + ${epoll.version} + 0.6 - 3.3.0 + 3.13.1 + 3.3.0 + 4.1.50.Final diff --git a/persistence-modules/redis/src/main/java/com/baeldung/CustomMessage.java b/persistence-modules/redis/src/main/java/com/baeldung/CustomMessage.java index 1d6a7e4e13..26ebe46f64 100644 --- a/persistence-modules/redis/src/main/java/com/baeldung/CustomMessage.java +++ b/persistence-modules/redis/src/main/java/com/baeldung/CustomMessage.java @@ -1,9 +1,11 @@ package com.baeldung; +import java.io.Serializable; + /** * Created by johnson on 3/9/17. */ -public class CustomMessage { +public class CustomMessage implements Serializable { private String message; public CustomMessage() { diff --git a/persistence-modules/redis/src/main/java/com/baeldung/Ledger.java b/persistence-modules/redis/src/main/java/com/baeldung/Ledger.java index da72791f7e..c9fb81979e 100644 --- a/persistence-modules/redis/src/main/java/com/baeldung/Ledger.java +++ b/persistence-modules/redis/src/main/java/com/baeldung/Ledger.java @@ -1,6 +1,8 @@ package com.baeldung; -public class Ledger { +import java.io.Serializable; + +public class Ledger implements Serializable { public Ledger() { } diff --git a/persistence-modules/redis/src/main/resources/singleNodeConfig.json b/persistence-modules/redis/src/main/resources/singleNodeConfig.json index f56e13dcfc..c46a542b46 100644 --- a/persistence-modules/redis/src/main/resources/singleNodeConfig.json +++ b/persistence-modules/redis/src/main/resources/singleNodeConfig.json @@ -1,13 +1,10 @@ { "singleServerConfig": { "idleConnectionTimeout": 10000, - "pingTimeout": 1000, "connectTimeout": 10000, "timeout": 3000, "retryAttempts": 3, "retryInterval": 1500, - "reconnectionTimeout": 3000, - "failedAttempts": 3, "password": null, "subscriptionsPerConnection": 5, "clientName": null, @@ -17,11 +14,9 @@ "connectionMinimumIdleSize": 10, "connectionPoolSize": 64, "database": 0, - "dnsMonitoring": false, "dnsMonitoringInterval": 5000 }, "threads": 0, "nettyThreads": 0, - "codec": null, - "useLinuxNativeEpoll": false + "codec": null } \ No newline at end of file diff --git a/persistence-modules/redis/src/main/resources/singleNodeConfig.yaml b/persistence-modules/redis/src/main/resources/singleNodeConfig.yaml index 1b05c46be2..9074434bd1 100644 --- a/persistence-modules/redis/src/main/resources/singleNodeConfig.yaml +++ b/persistence-modules/redis/src/main/resources/singleNodeConfig.yaml @@ -1,12 +1,9 @@ singleServerConfig: idleConnectionTimeout: 10000 - pingTimeout: 1000 connectTimeout: 10000 timeout: 3000 retryAttempts: 3 retryInterval: 1500 - reconnectionTimeout: 3000 - failedAttempts: 3 password: null subscriptionsPerConnection: 5 clientName: null @@ -16,9 +13,7 @@ singleServerConfig: connectionMinimumIdleSize: 10 connectionPoolSize: 64 database: 0 - dnsMonitoring: false dnsMonitoringInterval: 5000 threads: 0 nettyThreads: 0 -codec: ! {} -useLinuxNativeEpoll: false \ No newline at end of file +codec: ! {} \ No newline at end of file diff --git a/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java b/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java index 66f61ae5dd..c2e771d7b8 100644 --- a/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java +++ b/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java @@ -48,7 +48,7 @@ public class RedissonConfigurationIntegrationTest { public void givenJavaConfig_thenRedissonConnectToRedis() { Config config = new Config(); config.useSingleServer() - .setAddress(String.format("127.0.0.1:%s", port)); + .setAddress(String.format("redis://127.0.0.1:%s", port)); client = Redisson.create(config); diff --git a/persistence-modules/redis/src/test/java/com/baeldung/RedissonIntegrationTest.java b/persistence-modules/redis/src/test/java/com/baeldung/RedissonIntegrationTest.java index 53d77c2699..8c8e6a02dd 100644 --- a/persistence-modules/redis/src/test/java/com/baeldung/RedissonIntegrationTest.java +++ b/persistence-modules/redis/src/test/java/com/baeldung/RedissonIntegrationTest.java @@ -7,6 +7,7 @@ import org.redisson.Redisson; import org.redisson.RedissonMultiLock; import org.redisson.api.*; import org.redisson.client.RedisClient; +import org.redisson.client.RedisClientConfig; import org.redisson.client.RedisConnection; import org.redisson.client.codec.StringCodec; import org.redisson.client.protocol.RedisCommands; @@ -103,10 +104,10 @@ public class RedissonIntegrationTest { public void givenTopicSubscribedToAChannel_thenReceiveMessageFromChannel() throws ExecutionException, InterruptedException { CompletableFuture future = new CompletableFuture<>(); - RTopic subscribeTopic = client.getTopic("baeldung"); - subscribeTopic.addListener((channel, customMessage) -> future.complete(customMessage.getMessage())); + RTopic subscribeTopic = client.getTopic("baeldung"); + subscribeTopic.addListener(CustomMessage.class, (channel, customMessage) -> future.complete(customMessage.getMessage())); - RTopic publishTopic = client.getTopic("baeldung"); + RTopic publishTopic = client.getTopic("baeldung"); long clientsReceivedMessage = publishTopic.publish(new CustomMessage("This is a message")); @@ -203,10 +204,10 @@ public class RedissonIntegrationTest { batch.getMap("ledgerMap").fastPutAsync("1", "2"); batch.getMap("ledgerMap").putAsync("2", "5"); - List result = batch.execute(); + BatchResult batchResult = batch.execute(); RMap map = client.getMap("ledgerMap"); - assertTrue(result.size() > 0 && map.get("1").equals("2")); + assertTrue(batchResult.getResponses().size() > 0 && map.get("1").equals("2")); } @Test @@ -220,7 +221,9 @@ public class RedissonIntegrationTest { @Test public void givenLowLevelRedisCommands_thenExecuteLowLevelCommandsOnRedis(){ - RedisClient client = new RedisClient("localhost", 6379); + RedisClientConfig redisClientConfig = new RedisClientConfig(); + redisClientConfig.setAddress("localhost", 6379); + RedisClient client = RedisClient.create(redisClientConfig); RedisConnection conn = client.connect(); conn.sync(StringCodec.INSTANCE, RedisCommands.SET, "test", 0); diff --git a/persistence-modules/spring-data-elasticsearch/README.md b/persistence-modules/spring-data-elasticsearch/README.md index 63f1185732..9f68a25243 100644 --- a/persistence-modules/spring-data-elasticsearch/README.md +++ b/persistence-modules/spring-data-elasticsearch/README.md @@ -6,7 +6,7 @@ - [Guide to Elasticsearch in Java](https://www.baeldung.com/elasticsearch-java) - [Geospatial Support in ElasticSearch](https://www.baeldung.com/elasticsearch-geo-spatial) - [A Simple Tagging Implementation with Elasticsearch](https://www.baeldung.com/elasticsearch-tagging) -- [Introduction to Spring Data Elasticsearch – test 2](https://www.baeldung.com/spring-data-elasticsearch-test-2) +- [Introduction to Spring Data Elasticsearch (evaluation)](https://www.baeldung.com/spring-data-elasticsearch-test-2) ### Build the Project with Tests Running ``` diff --git a/spring-5-reactive-security/src/main/resources/application.properties b/spring-5-reactive-security/src/main/resources/application.properties index 234834b894..d13007ded7 100644 --- a/spring-5-reactive-security/src/main/resources/application.properties +++ b/spring-5-reactive-security/src/main/resources/application.properties @@ -1,5 +1,9 @@ logging.level.root=INFO -management.endpoints.web.exposure.include.=* +management.endpoints.web.exposure.include=* info.app.name=Spring Boot 2 actuator Application +management.endpoint.health.group.custom.include=diskSpace,ping +management.endpoint.health.group.custom.show-components=always +management.endpoint.health.group.custom.show-details=always +management.endpoint.health.group.custom.status.http-mapping.up=207 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/pom.xml b/spring-cloud/spring-cloud-bootstrap/customer-service/pom.xml new file mode 100644 index 0000000000..3e33e27c6c --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/customer-service/pom.xml @@ -0,0 +1,84 @@ + + + + 4.0.0 + com.baeldung.customerservice + customer-service + 1.0.0-SNAPSHOT + customer-service + jar + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../../parent-boot-2 + + + + 1.8 + 1.8 + 1.8 + UTF-8 + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-json + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-configuration-processor + + + org.projectlombok + lombok + true + + + com.baeldung.orderservice + order-client + 1.0.0-SNAPSHOT + compile + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + exec + + + + + + + + diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/Customer.java b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/Customer.java new file mode 100644 index 0000000000..7d10510cbc --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/Customer.java @@ -0,0 +1,14 @@ +package com.baeldung.customerservice; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class Customer { + + private int id; + private String firstName; + private String lastName; + +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java new file mode 100644 index 0000000000..489129a3d2 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java @@ -0,0 +1,25 @@ +package com.baeldung.customerservice; + +import com.baeldung.orderservice.client.OrderClient; +import com.baeldung.orderservice.client.OrderClientImpl; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; + +/** + * Spring Boot application starter class + */ +@SpringBootApplication +public class CustomerApplication { + public static void main(String[] args) { + SpringApplication.run(CustomerApplication.class, args); + } + + @Bean + public OrderClient getOrderClient() { + + return new OrderClientImpl(new RestTemplateBuilder()); + } + +} diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java new file mode 100644 index 0000000000..ab8872de1c --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java @@ -0,0 +1,56 @@ +package com.baeldung.customerservice; + +import com.baeldung.orderservice.client.OrderClient; +import com.baeldung.orderservice.client.OrderDTO; +import com.baeldung.orderservice.client.OrderResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +@RestController +public class CustomerService { + + @Autowired + private OrderClient orderClient; + + private List customers = Arrays.asList( + + new Customer(1, "John", "Smith"), + new Customer(2, "Deny", "Dominic")); + + + @GetMapping + public List getAllCustomers() { + return customers; + } + + @GetMapping("/{id}") + public Customer getCustomerById(@PathVariable int id) { + return customers.stream() + .filter(customer -> customer.getId() == id) + .findFirst() + .orElseThrow(IllegalArgumentException::new); + } + + + @PostMapping(value = "/order") + public String sendOrder(@RequestBody Map body) { + + OrderDTO dto = new OrderDTO(); + dto.setCustomerId((Integer) body.get("customerId")); + dto.setItemId((String) body.get("itemId")); + + OrderResponse response = orderClient.order(dto); + + return response.getStatus(); + } + +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/resources/application.properties b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/resources/application.properties new file mode 100644 index 0000000000..d439ae9b76 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/resources/application.properties @@ -0,0 +1,4 @@ +#Spring Boot server configuration +server.servlet.context-path=/customer-service +server.port=8001 + diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/src/test/resources/application.properties b/spring-cloud/spring-cloud-bootstrap/customer-service/src/test/resources/application.properties new file mode 100644 index 0000000000..1d50559005 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/customer-service/src/test/resources/application.properties @@ -0,0 +1,2 @@ +local.server.port=8001 +server.servlet.context-path=/customer-service \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml new file mode 100644 index 0000000000..4c8cf742b1 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + com.baeldung.orderservice + order-client + 1.0.0-SNAPSHOT + order-client + Order service client module + http://projects.spring.io/spring-boot/ + + + com.baeldung.orderservice + order-service + 1.0.0-SNAPSHOT + + + diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java new file mode 100644 index 0000000000..2dd6b13248 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java @@ -0,0 +1,6 @@ +package com.baeldung.orderservice.client; + +public interface OrderClient { + + OrderResponse order(OrderDTO orderDTO); +} diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java new file mode 100644 index 0000000000..70ec77fab6 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java @@ -0,0 +1,35 @@ +package com.baeldung.orderservice.client; + +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + + +@Component +public class OrderClientImpl implements OrderClient { + + private RestTemplate restTemplate; + + public OrderClientImpl(RestTemplateBuilder builder) { + + this.restTemplate = builder.build(); + } + + @Override + public OrderResponse order(OrderDTO orderDTO) { + + String serviceUrl = "http://localhost:8002/order-service"; + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + + HttpEntity request = new HttpEntity<>(orderDTO, headers); + + OrderResponse orderResponse = restTemplate.postForObject(serviceUrl + "/create", request, OrderResponse.class); + + return orderResponse; + + } +} diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java new file mode 100644 index 0000000000..c31c9f6bec --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java @@ -0,0 +1,16 @@ +package com.baeldung.orderservice.client; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class OrderDTO { + + private int customerId; + private String itemId; + +} diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java new file mode 100644 index 0000000000..e8d2059cbb --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java @@ -0,0 +1,15 @@ +package com.baeldung.orderservice.client; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class OrderResponse { + + private int orderId; + private String productId; + private String status; +} diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/resources/application.properties b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/resources/application.properties new file mode 100644 index 0000000000..53e503689f --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/resources/application.properties @@ -0,0 +1 @@ +server.port=8002 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-server/pom.xml b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/pom.xml new file mode 100644 index 0000000000..d6c521c5df --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + com.baeldung.orderservice + order-server + 1.0.0-SNAPSHOT + + order-service + com.baeldung.orderservice + 1.0.0-SNAPSHOT + + + + com.baeldung.orderservice + order-client + 1.0.0-SNAPSHOT + compile + + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java new file mode 100644 index 0000000000..719305064f --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java @@ -0,0 +1,18 @@ +package com.baeldung.orderservice; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class Order { + + private Integer id; + private Integer customerId; + private String itemId; + private String date; + +} diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java new file mode 100644 index 0000000000..eb89959ee0 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java @@ -0,0 +1,17 @@ +package com.baeldung.orderservice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; + +/** + * Spring Boot application starter class + */ +@SpringBootApplication +public class OrderApplication { + public static void main(String[] args) { + SpringApplication.run(OrderApplication.class, args); + } + +} diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java new file mode 100644 index 0000000000..a43bbcec65 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java @@ -0,0 +1,54 @@ +package com.baeldung.orderservice; + +import com.baeldung.orderservice.client.OrderDTO; +import com.baeldung.orderservice.client.OrderResponse; +import org.apache.commons.lang.time.DateFormatUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + + +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +@RestController +public class OrderService { + + + private List orders = Arrays.asList( + + new Order(1, 1, "A101", "2020/02/14"), + new Order(2, 1, "A101", "2020/02/14"), + new Order(3, 2, "A150", "2020/02/17")); + + @GetMapping + public List getAllOrders() { + return orders; + } + + @GetMapping("/{id}") + public List getOrdersByCustomer(@PathVariable int id) { + return orders.stream() + .filter(order -> order.getCustomerId() == id).collect(Collectors.toList()); + } + + @PostMapping("/create") + public OrderResponse createOrder(@RequestBody OrderDTO request) { + + int lastIndex = orders.size(); + Order order = new Order(); + order.setId(lastIndex + 1); + order.setCustomerId(request.getCustomerId()); + order.setItemId(request.getItemId()); + String date = DateFormatUtils.format(new Date(), "yyyy/MM/dd"); + order.setDate(date); + + return new OrderResponse(order.getId(), order.getItemId(), "CREATED"); + } + +} diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/resources/application.properties b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/resources/application.properties new file mode 100644 index 0000000000..f4fe5e7079 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/resources/application.properties @@ -0,0 +1,4 @@ +#Spring Boot server configuration +server.servlet.context-path=/order-service +server.port=8002 + diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/pom.xml b/spring-cloud/spring-cloud-bootstrap/order-service/pom.xml new file mode 100644 index 0000000000..8f3c9ceaff --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/pom.xml @@ -0,0 +1,123 @@ + + + + 4.0.0 + com.baeldung.orderservice + order-service + 1.0.0-SNAPSHOT + order-service + pom + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../../parent-boot-2 + + + + order-client + order-server + + + + 1.8 + 2.6 + 0.0.2 + 1.8 + 1.8 + UTF-8 + com.baeldung.orderservice.OrderApplication + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-web + + + commons-lang + commons-lang + ${commons-lang.version} + + + org.projectlombok + lombok + true + + + org.qunix + structure-maven-plugin + ${structure-maven.version} + + + org.springframework.boot + spring-boot-starter-json + + + org.springframework.boot + spring-boot-configuration-processor + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + ${orderservice.mainclass} + + + + + repackage + + + exec + + + + start-application + + com.baeldung.orderservice.OrderApplication + ../order-server/target/classes + + + start + + + + + + org.qunix + structure-maven-plugin + ${structure-maven.version} + false + + + compile + + modules + + + + + + + + diff --git a/spring-cloud/spring-cloud-bootstrap/pom.xml b/spring-cloud/spring-cloud-bootstrap/pom.xml index 2447b90538..ed9b148564 100644 --- a/spring-cloud/spring-cloud-bootstrap/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/pom.xml @@ -20,6 +20,9 @@ svc-book svc-rating zipkin + customer-service + order-service + shared-dto \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/shared-dto/pom.xml b/spring-cloud/spring-cloud-bootstrap/shared-dto/pom.xml new file mode 100644 index 0000000000..59dde717b5 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/shared-dto/pom.xml @@ -0,0 +1,60 @@ + + + + + 4.0.0 + com.baeldung + shared-dto + 1.0.0-SNAPSHOT + shared-dto + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../../parent-boot-2 + + + + + UTF-8 + 1.8 + 1.8 + 0.0.2 + + + + + org.qunix + structure-maven-plugin + ${structure-maven.version} + + + org.projectlombok + lombok + true + + + + + + + + org.qunix + structure-maven-plugin + ${structure-maven.version} + false + + + compile + + files + + + + + + + + diff --git a/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/deliverydto/CustomerDTO.java b/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/deliverydto/CustomerDTO.java new file mode 100644 index 0000000000..aa6b3ceac8 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/deliverydto/CustomerDTO.java @@ -0,0 +1,16 @@ +package com.baeldung.deliverydto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CustomerDTO { + private String firstName; + private String lastName; + private String homeAddress; + private String contactNumber; + // constructor, getters, setters +} diff --git a/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/CustomerDTO.java b/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/CustomerDTO.java new file mode 100644 index 0000000000..905773609d --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/CustomerDTO.java @@ -0,0 +1,15 @@ +package com.baeldung.shared; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CustomerDTO { + private String firstName; + private String lastName; + private String cardNumber; + // constructor, getters, setters +} diff --git a/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/OrderDTO.java b/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/OrderDTO.java new file mode 100644 index 0000000000..0640b84291 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/OrderDTO.java @@ -0,0 +1,16 @@ +package com.baeldung.shared; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class OrderDTO { + + private int customerId; + private String itemId; + +} diff --git a/spring-mvc-basics-2/README.md b/spring-mvc-basics-2/README.md index 5c1c671f73..cbc9f93e93 100644 --- a/spring-mvc-basics-2/README.md +++ b/spring-mvc-basics-2/README.md @@ -7,7 +7,6 @@ This module contains articles about Spring MVC - [Template Engines for Spring](https://www.baeldung.com/spring-template-engines) - [Spring 5 and Servlet 4 – The PushBuilder](https://www.baeldung.com/spring-5-push) - [Servlet Redirect vs Forward](https://www.baeldung.com/servlet-redirect-forward) -- [Apache Tiles Integration with Spring MVC](https://www.baeldung.com/spring-mvc-apache-tiles) - [Guide to Spring Email](https://www.baeldung.com/spring-email) - [Using ThymeLeaf and FreeMarker Emails Templates with Spring](https://www.baeldung.com/spring-email-templates) - [Request Method Not Supported (405) in Spring](https://www.baeldung.com/spring-request-method-not-supported-405) diff --git a/spring-mvc-basics-2/pom.xml b/spring-mvc-basics-2/pom.xml index 4c3041a209..026ddf8e72 100644 --- a/spring-mvc-basics-2/pom.xml +++ b/spring-mvc-basics-2/pom.xml @@ -99,12 +99,6 @@ ${jade.version} - - org.apache.tiles - tiles-jsp - ${apache-tiles.version} - - org.springframework @@ -178,7 +172,6 @@ 1.4.9 5.1.0 20180130 - 3.0.8 1.6.1 diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java b/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java index 4d43549440..aaa2443105 100644 --- a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java +++ b/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java @@ -23,8 +23,6 @@ public class WebInitializer implements WebApplicationInitializer { ctx.register(EmailConfiguration.class); // ctx.setServletContext(container); - //ctx.register(TilesApplicationConfiguration.class); - // Manage the lifecycle of the root application context container.addListener(new ContextLoaderListener(ctx)); diff --git a/spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestUnitTest.java b/spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java similarity index 96% rename from spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestUnitTest.java rename to spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java index 2e88935c1b..e75990e0b0 100644 --- a/spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestUnitTest.java +++ b/spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java @@ -20,7 +20,7 @@ import com.baeldung.matrix.config.MatrixWebConfig; @WebAppConfiguration @ContextConfiguration(classes = { MatrixWebConfig.class, MultipartPostRequestController.class }) @RunWith(SpringJUnit4ClassRunner.class) -public class MultipartPostRequestUnitTest { +public class MultipartPostRequestControllerUnitTest { @Autowired private WebApplicationContext webApplicationContext; diff --git a/spring-mvc-views/README.md b/spring-mvc-views/README.md index 7aa05699f3..0323349130 100644 --- a/spring-mvc-views/README.md +++ b/spring-mvc-views/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Spring MVC Themes](https://www.baeldung.com/spring-mvc-themes) +- [Apache Tiles Integration with Spring MVC](https://www.baeldung.com/spring-mvc-apache-tiles) diff --git a/spring-mvc-views/pom.xml b/spring-mvc-views/pom.xml index b23403fe31..452805bd53 100644 --- a/spring-mvc-views/pom.xml +++ b/spring-mvc-views/pom.xml @@ -74,6 +74,12 @@ spring-security-taglibs ${spring.security.version} + + + org.apache.tiles + tiles-jsp + ${apache-tiles.version} + @@ -115,6 +121,7 @@ 2.5.0 5.4.9.Final enter-location-of-server + 3.0.8 \ No newline at end of file diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/TilesApplicationConfiguration.java b/spring-mvc-views/src/main/java/com/baeldung/themes/config/TilesApplicationConfiguration.java similarity index 93% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/TilesApplicationConfiguration.java rename to spring-mvc-views/src/main/java/com/baeldung/themes/config/TilesApplicationConfiguration.java index de2b7fe68f..886c8987e8 100644 --- a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/TilesApplicationConfiguration.java +++ b/spring-mvc-views/src/main/java/com/baeldung/themes/config/TilesApplicationConfiguration.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.configuration; +package com.baeldung.themes.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -12,7 +12,7 @@ import org.springframework.web.servlet.view.tiles3.TilesViewResolver; @Configuration @EnableWebMvc -@ComponentScan(basePackages = "com.baeldung.spring.controller.tiles") +@ComponentScan(basePackages = "com.baeldung.themes") public class TilesApplicationConfiguration implements WebMvcConfigurer { /** diff --git a/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java b/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java index 3fbe8d043d..3333d664d7 100644 --- a/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java +++ b/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java @@ -14,6 +14,7 @@ public class WebInitializer implements WebApplicationInitializer { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(DataSourceConfig.class); context.register(ThemeMVCConfig.class); + //context.register(TilesApplicationConfiguration.class); servletContext.addListener(new ContextLoaderListener(context)); diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/tiles/TilesController.java b/spring-mvc-views/src/main/java/com/baeldung/themes/controllers/TilesController.java similarity index 94% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/tiles/TilesController.java rename to spring-mvc-views/src/main/java/com/baeldung/themes/controllers/TilesController.java index 319340b886..11a3d3d197 100644 --- a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/tiles/TilesController.java +++ b/spring-mvc-views/src/main/java/com/baeldung/themes/controllers/TilesController.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.controller.tiles; +package com.baeldung.themes.controllers; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp new file mode 100644 index 0000000000..47157a5d2a --- /dev/null +++ b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp @@ -0,0 +1,12 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Home + + +

Welcome to Apache Tiles integration with Spring MVC

+ + \ No newline at end of file diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp new file mode 100644 index 0000000000..497e04901a --- /dev/null +++ b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp @@ -0,0 +1,12 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Spring MVC + + +

Spring MVC configured to work with Apache Tiles

+ + \ No newline at end of file diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/tiles.xml b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/tiles.xml similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/tiles.xml rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/tiles.xml diff --git a/spring-mvc-views/src/main/webapp/static/css/app.css b/spring-mvc-views/src/main/webapp/static/css/app.css new file mode 100644 index 0000000000..9976e5406e --- /dev/null +++ b/spring-mvc-views/src/main/webapp/static/css/app.css @@ -0,0 +1,36 @@ +.flex-container { + display: -webkit-flex; + display: flex; + -webkit-flex-flow: row wrap; + flex-flow: row wrap; + text-align: center; +} + +.flex-container > * { + padding: 15px; + -webkit-flex: 1 100%; + flex: 1 100%; +} + +.article { + text-align: left; +} + +header {background: black;color:white;} +footer {background: #aaa;color:white;} +.nav {background:#eee;} + +.nav ul { + list-style-type: none; + padding: 0; +} + +.nav ul a { + text-decoration: none; +} + +@media all and (min-width: 768px) { + .nav {text-align:left;-webkit-flex: 1 auto;flex:1 auto;-webkit-order:1;order:1;} + .article {-webkit-flex:5 0px;flex:5 0px;-webkit-order:2;order:2;} + footer {-webkit-order:3;order:3;} +} \ No newline at end of file diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md index 4bb0eea16c..a6244ec0ad 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md +++ b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md @@ -1,4 +1,4 @@ ## Relevant articles: -- [Spring Security Kerberos Integration](https://www.baeldung.com/spring-security-kerberos-integration) +- [Spring Security Kerberos Integration With MiniKdc](https://www.baeldung.com/spring-security-kerberos-integration) - [Introduction to SPNEGO/Kerberos Authentication in Spring](https://www.baeldung.com/spring-security-kerberos) diff --git a/spring-soap/pom.xml b/spring-soap/pom.xml index d0987329c0..137ff03c31 100644 --- a/spring-soap/pom.xml +++ b/spring-soap/pom.xml @@ -83,8 +83,4 @@ - - 2.1.2.RELEASE - -