diff --git a/apache-olingo/pom.xml b/apache-olingo/pom.xml index 5de0dfd511..25aab0ec97 100644 --- a/apache-olingo/pom.xml +++ b/apache-olingo/pom.xml @@ -83,4 +83,4 @@ 2.0.11 - + \ No newline at end of file diff --git a/core-java-modules/core-java-9-new-features/pom.xml b/core-java-modules/core-java-9-new-features/pom.xml index ce90a0f04a..78ffaff010 100644 --- a/core-java-modules/core-java-9-new-features/pom.xml +++ b/core-java-modules/core-java-9-new-features/pom.xml @@ -34,6 +34,28 @@ + + core-java-9-new-features + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + + apache.snapshots + https://repository.apache.org/snapshots/ + + + incubator-features @@ -126,28 +148,6 @@ - - core-java-9-new-features - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${maven.compiler.source} - ${maven.compiler.target} - - - - - - - - apache.snapshots - https://repository.apache.org/snapshots/ - - - 3.0.0 4.0.2 diff --git a/core-java-modules/core-java-concurrency-advanced-4/README.md b/core-java-modules/core-java-concurrency-advanced-4/README.md index ba838dbc72..808db89b12 100644 --- a/core-java-modules/core-java-concurrency-advanced-4/README.md +++ b/core-java-modules/core-java-concurrency-advanced-4/README.md @@ -5,3 +5,4 @@ - [Start Two Threads at the Exact Same Time in Java](https://www.baeldung.com/java-start-two-threads-at-same-time) - [Volatile Variables and Thread Safety](https://www.baeldung.com/java-volatile-variables-thread-safety) - [Producer-Consumer Problem With Example in Java](https://www.baeldung.com/java-producer-consumer-problem) +- [Acquire a Lock by a Key in Java](https://www.baeldung.com/java-acquire-lock-by-key) diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/Consumer.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/Consumer.java new file mode 100644 index 0000000000..5a059b74df --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/Consumer.java @@ -0,0 +1,51 @@ +package com.baeldung.producerconsumer; + +public class Consumer implements Runnable { + private final DataQueue dataQueue; + private volatile boolean runFlag; + + public Consumer(DataQueue dataQueue) { + this.dataQueue = dataQueue; + runFlag = true; + } + + @Override + public void run() { + consume(); + } + + public void consume() { + while (runFlag) { + Message message; + if (dataQueue.isEmpty()) { + try { + dataQueue.waitOnEmpty(); + } catch (InterruptedException e) { + e.printStackTrace(); + break; + } + } + if (!runFlag) { + break; + } + message = dataQueue.remove(); + dataQueue.notifyAllForFull(); + useMessage(message); + } + System.out.println("Consumer Stopped"); + } + + private void useMessage(Message message) { + if (message != null) { + System.out.printf("[%s] Consuming Message. Id: %d, Data: %f\n", Thread.currentThread().getName(), message.getId(), message.getData()); + + //Sleeping on random time to make it realistic + ThreadUtil.sleep((long) (message.getData() * 100)); + } + } + + public void stop() { + runFlag = false; + dataQueue.notifyAllForEmpty(); + } +} diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/DataQueue.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/DataQueue.java new file mode 100644 index 0000000000..6ab4fa2bc3 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/DataQueue.java @@ -0,0 +1,59 @@ +package com.baeldung.producerconsumer; + +import java.util.LinkedList; +import java.util.Queue; + +public class DataQueue { + private final Queue queue = new LinkedList<>(); + private final int maxSize; + private final Object FULL_QUEUE = new Object(); + private final Object EMPTY_QUEUE = new Object(); + + DataQueue(int maxSize) { + this.maxSize = maxSize; + } + + public boolean isFull() { + return queue.size() == maxSize; + } + + public boolean isEmpty() { + return queue.isEmpty(); + } + + public void waitOnFull() throws InterruptedException { + synchronized (FULL_QUEUE) { + FULL_QUEUE.wait(); + } + } + + public void waitOnEmpty() throws InterruptedException { + synchronized (EMPTY_QUEUE) { + EMPTY_QUEUE.wait(); + } + } + + public void notifyAllForFull() { + synchronized (FULL_QUEUE) { + FULL_QUEUE.notifyAll(); + } + } + + public void notifyAllForEmpty() { + synchronized (EMPTY_QUEUE) { + EMPTY_QUEUE.notifyAll(); + } + } + + public void add(Message message) { + synchronized (queue) { + queue.add(message); + } + } + + public Message remove() { + synchronized (queue) { + return queue.poll(); + } + } +} diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/Message.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/Message.java new file mode 100644 index 0000000000..48f6e986df --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/Message.java @@ -0,0 +1,27 @@ +package com.baeldung.producerconsumer; + +public class Message { + private int id; + private double data; + + public Message(int id, double data) { + this.id = id; + this.data = data; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public double getData() { + return data; + } + + public void setData(double data) { + this.data = data; + } +} diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/Producer.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/Producer.java new file mode 100644 index 0000000000..80d693bd97 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/Producer.java @@ -0,0 +1,53 @@ +package com.baeldung.producerconsumer; + +public class Producer implements Runnable { + private final DataQueue dataQueue; + private volatile boolean runFlag; + + private static int idSequence = 0; + + public Producer(DataQueue dataQueue) { + this.dataQueue = dataQueue; + runFlag = true; + } + + @Override + public void run() { + produce(); + } + + public void produce() { + while (runFlag) { + Message message = generateMessage(); + while (dataQueue.isFull()) { + try { + dataQueue.waitOnFull(); + } catch (InterruptedException e) { + e.printStackTrace(); + break; + } + } + if (!runFlag) { + break; + } + dataQueue.add(message); + dataQueue.notifyAllForEmpty(); + } + System.out.println("Producer Stopped"); + } + + private Message generateMessage() { + Message message = new Message(++idSequence, Math.random()); + System.out.printf("[%s] Generated Message. Id: %d, Data: %f\n", Thread.currentThread().getName(), message.getId(), message.getData()); + + //Sleeping on random time to make it realistic + ThreadUtil.sleep((long) (message.getData() * 100)); + + return message; + } + + public void stop() { + runFlag = false; + dataQueue.notifyAllForFull(); + } +} diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/ProducerConsumerDemonstrator.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/ProducerConsumerDemonstrator.java new file mode 100644 index 0000000000..96d7b9f865 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/ProducerConsumerDemonstrator.java @@ -0,0 +1,69 @@ +package com.baeldung.producerconsumer; + +import java.util.ArrayList; +import java.util.List; + +import static com.baeldung.producerconsumer.ThreadUtil.*; + +public class ProducerConsumerDemonstrator { + private static final int MAX_QUEUE_CAPACITY = 5; + + public static void demoSingleProducerAndSingleConsumer() { + DataQueue dataQueue = new DataQueue(MAX_QUEUE_CAPACITY); + + Producer producer = new Producer(dataQueue); + Thread producerThread = new Thread(producer); + + Consumer consumer = new Consumer(dataQueue); + Thread consumerThread = new Thread(consumer); + + producerThread.start(); + consumerThread.start(); + + List threads = new ArrayList<>(); + threads.add(producerThread); + threads.add(consumerThread); + + // let threads run for two seconds + sleep(2000); + + // Stop threads + producer.stop(); + consumer.stop(); + + waitForAllThreadsToComplete(threads); + } + + public static void demoMultipleProducersAndMultipleConsumers() { + DataQueue dataQueue = new DataQueue(MAX_QUEUE_CAPACITY); + int producerCount = 3; + int consumerCount = 3; + List threads = new ArrayList<>(); + Producer producer = new Producer(dataQueue); + for(int i = 0; i < producerCount; i++) { + Thread producerThread = new Thread(producer); + producerThread.start(); + threads.add(producerThread); + } + Consumer consumer = new Consumer(dataQueue); + for(int i = 0; i < consumerCount; i++) { + Thread consumerThread = new Thread(consumer); + consumerThread.start(); + threads.add(consumerThread); + } + + // let threads run for two seconds + sleep(2000); + + // Stop threads + producer.stop(); + consumer.stop(); + + waitForAllThreadsToComplete(threads); + } + + public static void main(String[] args) { + demoSingleProducerAndSingleConsumer(); + demoMultipleProducersAndMultipleConsumers(); + } +} diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/SimpleProducerConsumerDemonstrator.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/SimpleProducerConsumerDemonstrator.java new file mode 100644 index 0000000000..f1f6e1cc9c --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/SimpleProducerConsumerDemonstrator.java @@ -0,0 +1,60 @@ +package com.baeldung.producerconsumer; + +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingDeque; + +import static com.baeldung.producerconsumer.ThreadUtil.sleep; + +public class SimpleProducerConsumerDemonstrator { + BlockingQueue blockingQueue = new LinkedBlockingDeque<>(5); + + private void produce() { + while (true) { + double value = generateValue(); + try { + blockingQueue.put(value); + } catch (InterruptedException e) { + e.printStackTrace(); + break; + } + System.out.printf("[%s] Value produced: %f\n", Thread.currentThread().getName(), value); + } + } + + private void consume() { + while (true) { + Double value; + try { + value = blockingQueue.take(); + } catch (InterruptedException e) { + e.printStackTrace(); + break; + } + // Consume value + System.out.printf("[%s] Value consumed: %f\n", Thread.currentThread().getName(), value); + } + } + + private double generateValue() { + return Math.random(); + } + + private void runProducerConsumer() { + for (int i = 0; i < 2; i++) { + Thread producerThread = new Thread(this::produce); + producerThread.start(); + } + + for (int i = 0; i < 3; i++) { + Thread consumerThread = new Thread(this::consume); + consumerThread.start(); + } + } + + public static void main(String[] args) { + SimpleProducerConsumerDemonstrator simpleProducerConsumerDemonstrator = new SimpleProducerConsumerDemonstrator(); + simpleProducerConsumerDemonstrator.runProducerConsumer(); + sleep(2000); + System.exit(0); + } +} diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/ThreadUtil.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/ThreadUtil.java new file mode 100644 index 0000000000..e49a9019fd --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/ThreadUtil.java @@ -0,0 +1,24 @@ +package com.baeldung.producerconsumer; + +import java.util.List; + +public class ThreadUtil { + public static void waitForAllThreadsToComplete(List threads) { + for(Thread thread: threads) { + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + public static void sleep(long interval) { + try { + // Wait for some time to demonstrate threads + Thread.sleep(interval); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/core-java-modules/core-java-concurrency-basic-3/pom.xml b/core-java-modules/core-java-concurrency-basic-3/pom.xml index 20615e3250..7771d1200c 100644 --- a/core-java-modules/core-java-concurrency-basic-3/pom.xml +++ b/core-java-modules/core-java-concurrency-basic-3/pom.xml @@ -24,4 +24,4 @@ - + \ No newline at end of file diff --git a/core-java-modules/core-java-date-operations-1/pom.xml b/core-java-modules/core-java-date-operations-1/pom.xml index ea9f94fa56..c5d46723d8 100644 --- a/core-java-modules/core-java-date-operations-1/pom.xml +++ b/core-java-modules/core-java-date-operations-1/pom.xml @@ -25,7 +25,6 @@ commons-lang3 ${commons-lang3.version} - com.darwinsys hirondelle-date4j diff --git a/core-java-modules/core-java-exceptions-4/README.md b/core-java-modules/core-java-exceptions-4/README.md index e77787a8a3..7df8ef65b9 100644 --- a/core-java-modules/core-java-exceptions-4/README.md +++ b/core-java-modules/core-java-exceptions-4/README.md @@ -2,3 +2,4 @@ - [Java ArrayIndexOutOfBoundsException](https://www.baeldung.com/java-arrayindexoutofboundsexception) - [Java Missing Return Statement](https://www.baeldung.com/java-missing-return-statement) +- [Convert long to int Type in Java](https://www.baeldung.com/java-convert-long-to-int) diff --git a/core-java-modules/core-java-jar/pom.xml b/core-java-modules/core-java-jar/pom.xml index 714a370287..19da9b8a56 100644 --- a/core-java-modules/core-java-jar/pom.xml +++ b/core-java-modules/core-java-jar/pom.xml @@ -259,7 +259,7 @@ - + diff --git a/core-java-modules/core-java-jvm/pom.xml b/core-java-modules/core-java-jvm/pom.xml index e4c0f949c2..d26c72323f 100644 --- a/core-java-modules/core-java-jvm/pom.xml +++ b/core-java-modules/core-java-jvm/pom.xml @@ -64,13 +64,6 @@ - - 3.27.0-GA - 1.8.0 - 0.10 - 8.0.1 - 6.5.0 - @@ -181,4 +174,12 @@ + + 3.27.0-GA + 1.8.0 + 0.10 + 8.0.1 + 6.5.0 + + \ No newline at end of file diff --git a/core-java-modules/core-java-lang-4/README.md b/core-java-modules/core-java-lang-4/README.md index e2a74b36af..a145633d2b 100644 --- a/core-java-modules/core-java-lang-4/README.md +++ b/core-java-modules/core-java-lang-4/README.md @@ -10,3 +10,4 @@ This module contains articles about core features in the Java language - [Tiered Compilation in JVM](https://www.baeldung.com/jvm-tiered-compilation) - [Fixing the “Declared package does not match the expected package” Error](https://www.baeldung.com/java-declared-expected-package-error) - [Chaining Constructors in Java](https://www.baeldung.com/java-chain-constructors) +- [Difference Between POJO, JavaBeans, DTO and VO](https://www.baeldung.com/java-pojo-javabeans-dto-vo) diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeeBean.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeeBean.java new file mode 100644 index 0000000000..ed75a7157c --- /dev/null +++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeeBean.java @@ -0,0 +1,48 @@ +package com.baeldung.employee; + +import java.io.Serializable; +import java.time.LocalDate; + +public class EmployeeBean implements Serializable { + + private static final long serialVersionUID = -3760445487636086034L; + + private String firstName; + private String lastName; + private LocalDate startDate; + + public EmployeeBean() { + + } + + public EmployeeBean(String firstName, String lastName, LocalDate startDate) { + this.firstName = firstName; + this.lastName = lastName; + this.startDate = startDate; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public LocalDate getStartDate() { + return startDate; + } + + public void setStartDate(LocalDate startDate) { + this.startDate = startDate; + } + +} diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeeDTO.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeeDTO.java new file mode 100644 index 0000000000..beb6bf3ce5 --- /dev/null +++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeeDTO.java @@ -0,0 +1,34 @@ +package com.baeldung.employee; + +import java.time.LocalDate; + +public class EmployeeDTO { + + private String firstName; + private String lastName; + private LocalDate startDate; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public LocalDate getStartDate() { + return startDate; + } + + public void setStartDate(LocalDate startDate) { + this.startDate = startDate; + } +} diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeePOJO.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeePOJO.java new file mode 100644 index 0000000000..50f17d965f --- /dev/null +++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeePOJO.java @@ -0,0 +1,49 @@ +package com.baeldung.employee; + +import java.time.LocalDate; +import java.util.Objects; + +public class EmployeePOJO { + + private String firstName; + private String lastName; + private LocalDate startDate; + + public EmployeePOJO(String firstName, String lastName, LocalDate startDate) { + this.firstName = firstName; + this.lastName = lastName; + this.startDate = startDate; + } + + public String name() { + return this.firstName + " " + this.lastName; + } + + public LocalDate getStart() { + return this.startDate; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public LocalDate getStartDate() { + return startDate; + } + + public void setStartDate(LocalDate startDate) { + this.startDate = startDate; + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeeVO.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeeVO.java new file mode 100644 index 0000000000..7a1775f79d --- /dev/null +++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/employee/EmployeeVO.java @@ -0,0 +1,40 @@ +package com.baeldung.employee; + +import java.time.LocalDate; +import java.util.Objects; + +public class EmployeeVO { + private String firstName; + private String lastName; + private LocalDate startDate; + + public EmployeeVO(String firstName, String lastName, LocalDate startDate) { + this.firstName = firstName; + this.lastName = lastName; + this.startDate = startDate; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public LocalDate getStartDate() { + return startDate; + } + + @Override + public boolean equals(Object obj) { + return Objects.equals(firstName, this.firstName) + && Objects.equals(lastName, this.lastName) + && Objects.equals(startDate, this.startDate); + } + + @Override + public int hashCode() { + return Objects.hash(firstName, lastName, startDate); + } +} diff --git a/core-java-modules/core-java-serialization/pom.xml b/core-java-modules/core-java-serialization/pom.xml index 315ed8cdad..c82ae9d1d6 100644 --- a/core-java-modules/core-java-serialization/pom.xml +++ b/core-java-modules/core-java-serialization/pom.xml @@ -64,7 +64,6 @@ true - org.apache.maven.plugins diff --git a/core-java-modules/core-java-string-algorithms-3/pom.xml b/core-java-modules/core-java-string-algorithms-3/pom.xml index dc8ad3851d..147ea22375 100644 --- a/core-java-modules/core-java-string-algorithms-3/pom.xml +++ b/core-java-modules/core-java-string-algorithms-3/pom.xml @@ -54,4 +54,5 @@ 1.7 3.12.0 + \ No newline at end of file diff --git a/core-java-modules/core-java/pom.xml b/core-java-modules/core-java/pom.xml index 188c6a6f63..bb19b525d0 100644 --- a/core-java-modules/core-java/pom.xml +++ b/core-java-modules/core-java/pom.xml @@ -69,7 +69,6 @@ true - org.apache.maven.plugins diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 60319b4de4..2f684beea0 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -137,4 +137,4 @@ - + \ No newline at end of file diff --git a/ddd-modules/infrastructure/pom.xml b/ddd-modules/infrastructure/pom.xml index abf90935c3..232e5ff4b4 100644 --- a/ddd-modules/infrastructure/pom.xml +++ b/ddd-modules/infrastructure/pom.xml @@ -1,13 +1,11 @@ - 4.0.0 com.baeldung.dddmodules.infrastructure infrastructure 1.0 - jar diff --git a/ddd-modules/mainapp/pom.xml b/ddd-modules/mainapp/pom.xml index 6b913df979..a2d3b8f3ea 100644 --- a/ddd-modules/mainapp/pom.xml +++ b/ddd-modules/mainapp/pom.xml @@ -1,6 +1,5 @@ - 4.0.0 diff --git a/ddd-modules/ordercontext/pom.xml b/ddd-modules/ordercontext/pom.xml index 8dee3a5148..eaf44badd3 100644 --- a/ddd-modules/ordercontext/pom.xml +++ b/ddd-modules/ordercontext/pom.xml @@ -1,6 +1,5 @@ - 4.0.0 @@ -13,7 +12,6 @@ com.baeldung.dddmodules ddd-modules 1.0 - ../ diff --git a/ddd-modules/pom.xml b/ddd-modules/pom.xml index 134a9d0566..d2932ee515 100644 --- a/ddd-modules/pom.xml +++ b/ddd-modules/pom.xml @@ -1,6 +1,5 @@ - 4.0.0 @@ -14,7 +13,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - ../ @@ -70,10 +68,8 @@ 9 9 - 3.8.1 - 1.0 - + \ No newline at end of file diff --git a/ddd-modules/sharedkernel/pom.xml b/ddd-modules/sharedkernel/pom.xml index 1afddf1e22..3966e1c26e 100644 --- a/ddd-modules/sharedkernel/pom.xml +++ b/ddd-modules/sharedkernel/pom.xml @@ -1,6 +1,5 @@ - 4.0.0 @@ -13,7 +12,6 @@ com.baeldung.dddmodules ddd-modules 1.0 - ../ diff --git a/ddd-modules/shippingcontext/pom.xml b/ddd-modules/shippingcontext/pom.xml index 25b5882ef1..a6e6167b69 100644 --- a/ddd-modules/shippingcontext/pom.xml +++ b/ddd-modules/shippingcontext/pom.xml @@ -1,6 +1,5 @@ - 4.0.0 @@ -13,7 +12,6 @@ com.baeldung.dddmodules ddd-modules 1.0 - ../ diff --git a/geotools/pom.xml b/geotools/pom.xml index b9a6a7c91f..05cae922a4 100644 --- a/geotools/pom.xml +++ b/geotools/pom.xml @@ -15,6 +15,14 @@ 1.0.0-SNAPSHOT + + + osgeo-release + OSGeo Repository + https://repo.osgeo.org/repository/release/ + + + org.geotools @@ -33,14 +41,6 @@ - - - osgeo-release - OSGeo Repository - https://repo.osgeo.org/repository/release/ - - - 15.2 15.2 diff --git a/graphql/graphql-dgs/pom.xml b/graphql/graphql-dgs/pom.xml index 1dc3630276..6165ae839f 100644 --- a/graphql/graphql-dgs/pom.xml +++ b/graphql/graphql-dgs/pom.xml @@ -33,26 +33,22 @@ spring-boot-starter 2.6.2 - org.springframework.boot spring-boot-starter-test 2.6.2 test - com.netflix.graphql.dgs.codegen graphql-dgs-codegen-client-core 5.1.14 - org.springframework.boot spring-boot-starter-web 2.6.2 - com.netflix.graphql.dgs graphql-dgs-spring-boot-starter @@ -88,4 +84,4 @@ - + \ No newline at end of file diff --git a/httpclient-2/pom.xml b/httpclient-2/pom.xml index 85fc1d87e7..287ff27e35 100644 --- a/httpclient-2/pom.xml +++ b/httpclient-2/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 httpclient-2 0.1-SNAPSHOT diff --git a/jakarta-ee/README.md b/jakarta-ee/README.md new file mode 100644 index 0000000000..54f372f736 --- /dev/null +++ b/jakarta-ee/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Introduction to Jakarta EE MVC / Eclipse Krazo](https://www.baeldung.com/java-ee-mvc-eclipse-krazo) diff --git a/java-collections-maps-3/pom.xml b/java-collections-maps-3/pom.xml index a54061404d..729b357b76 100644 --- a/java-collections-maps-3/pom.xml +++ b/java-collections-maps-3/pom.xml @@ -22,7 +22,6 @@ junit-jupiter-api 5.8.1 - org.springframework spring-core diff --git a/java-numbers-4/README.md b/java-numbers-4/README.md index f053a82b80..a6d866218c 100644 --- a/java-numbers-4/README.md +++ b/java-numbers-4/README.md @@ -4,3 +4,4 @@ - [Understanding the & 0xff Value in Java](https://www.baeldung.com/java-and-0xff) - [Determine if an Integer’s Square Root Is an Integer in Java](https://www.baeldung.com/java-find-if-square-root-is-integer) - [Guide to Java BigInteger](https://www.baeldung.com/java-biginteger) +- [Automorphic Numbers in Java](https://www.baeldung.com/java-automorphic-numbers) diff --git a/java-numbers-4/src/main/java/com/baeldung/automorphicnumber/AutomorphicNumber.java b/java-numbers-4/src/main/java/com/baeldung/automorphicnumber/AutomorphicNumber.java new file mode 100644 index 0000000000..926b13deda --- /dev/null +++ b/java-numbers-4/src/main/java/com/baeldung/automorphicnumber/AutomorphicNumber.java @@ -0,0 +1,31 @@ +package com.baeldung.automorphicnumber; + +public class AutomorphicNumber { + + public static void main(String[] args) { + System.out.println(isAutomorphicUsingLoop(76)); + System.out.println(isAutomorphicUsingMath(76)); + } + + public static boolean isAutomorphicUsingMath(int number) { + int square = number * number; + + int numberOfDigits = (int) Math.floor(Math.log10(number) + 1); + int lastDigits = (int) (square % (Math.pow(10, numberOfDigits))); + + return number == lastDigits; + } + + public static boolean isAutomorphicUsingLoop(int number) { + int square = number * number; + + while (number > 0) { + if (number % 10 != square % 10) { + return false; + } + number /= 10; + square /= 10; + } + return true; + } +} \ No newline at end of file diff --git a/java-numbers-4/src/test/java/com/baeldung/automorphicnumber/AutomorphicNumberUnitTest.java b/java-numbers-4/src/test/java/com/baeldung/automorphicnumber/AutomorphicNumberUnitTest.java new file mode 100644 index 0000000000..8e31de9f47 --- /dev/null +++ b/java-numbers-4/src/test/java/com/baeldung/automorphicnumber/AutomorphicNumberUnitTest.java @@ -0,0 +1,19 @@ +package com.baeldung.automorphicnumber; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.jupiter.api.Test; + +public class AutomorphicNumberUnitTest { + + @Test + void givenANumber_whenPassed_thenShouldDetermineAutomorphicOrNot() { + int number1 = 76; // automorphic + int number2 = 16; // not automorphic + assertTrue(AutomorphicNumber.isAutomorphicUsingLoop(number1)); + assertFalse(AutomorphicNumber.isAutomorphicUsingLoop(number2)); + assertTrue(AutomorphicNumber.isAutomorphicUsingMath(number1)); + assertFalse(AutomorphicNumber.isAutomorphicUsingMath(number2)); + } +} diff --git a/javax-servlets-2/pom.xml b/javax-servlets-2/pom.xml index 34c00c3d05..5d8310f2b2 100644 --- a/javax-servlets-2/pom.xml +++ b/javax-servlets-2/pom.xml @@ -57,4 +57,5 @@ 4.5.13 4.0.1 - + + \ No newline at end of file diff --git a/javaxval/pom.xml b/javaxval/pom.xml index 4131ddeb97..e6ecee6cfb 100644 --- a/javaxval/pom.xml +++ b/javaxval/pom.xml @@ -37,35 +37,13 @@ - + 6.0.13.Final @@ -77,4 +55,4 @@ 5.0.2.RELEASE - + \ No newline at end of file diff --git a/jta/pom.xml b/jta/pom.xml index e62c480c81..906d28a7ea 100644 --- a/jta/pom.xml +++ b/jta/pom.xml @@ -15,7 +15,7 @@ 0.0.1-SNAPSHOT ../parent-boot-2 - + diff --git a/ksqldb/pom.xml b/ksqldb/pom.xml index ee4906090f..e55398d635 100644 --- a/ksqldb/pom.xml +++ b/ksqldb/pom.xml @@ -11,7 +11,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - ../pom.xml diff --git a/libraries-concurrency/pom.xml b/libraries-concurrency/pom.xml index d8f48a1959..eb581ce3a0 100644 --- a/libraries-concurrency/pom.xml +++ b/libraries-concurrency/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 libraries-concurrency libraries-concurrency @@ -78,5 +78,5 @@ 0.8.0 - + \ No newline at end of file diff --git a/lombok-2/pom.xml b/lombok-2/pom.xml index 3c67e959a4..bde328444e 100644 --- a/lombok-2/pom.xml +++ b/lombok-2/pom.xml @@ -22,4 +22,4 @@ - + \ No newline at end of file diff --git a/lombok/pom.xml b/lombok/pom.xml index d4f89ab4f2..24a04783d1 100644 --- a/lombok/pom.xml +++ b/lombok/pom.xml @@ -62,18 +62,9 @@ false - + diff --git a/maven-modules/maven-classifier/maven-classifier-example-consumer/pom.xml b/maven-modules/maven-classifier/maven-classifier-example-consumer/pom.xml index cbf046ed5a..b280f21b4b 100644 --- a/maven-modules/maven-classifier/maven-classifier-example-consumer/pom.xml +++ b/maven-modules/maven-classifier/maven-classifier-example-consumer/pom.xml @@ -1,22 +1,16 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + maven-classifier-example-consumer + maven-classifier com.baeldung 0.0.1-SNAPSHOT - 4.0.0 - - maven-classifier-example-consumer - - - 8 - 8 - - com.baeldung @@ -29,13 +23,14 @@ 0.0.1-SNAPSHOT arbitrary - - - - - - - + + + + + + + com.baeldung maven-classifier-example-provider @@ -50,4 +45,9 @@ - + + 8 + 8 + + + \ No newline at end of file diff --git a/maven-modules/maven-classifier/maven-classifier-example-provider/pom.xml b/maven-modules/maven-classifier/maven-classifier-example-provider/pom.xml index 12cb4fa1a2..111996c995 100644 --- a/maven-modules/maven-classifier/maven-classifier-example-provider/pom.xml +++ b/maven-modules/maven-classifier/maven-classifier-example-provider/pom.xml @@ -1,9 +1,10 @@ - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + maven-classifier-example-provider + 0.0.1-SNAPSHOT maven-classifier @@ -11,15 +12,6 @@ 0.0.1-SNAPSHOT - maven-classifier-example-provider - 0.0.1-SNAPSHOT - - - 8 - 8 - - - @@ -39,21 +31,22 @@ true - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -76,18 +69,19 @@ test-jar - - - - - - - - - - - - + + + + + + + + + + + + @@ -119,4 +113,11 @@ - + + + 8 + 8 + + + + \ No newline at end of file diff --git a/maven-modules/maven-classifier/pom.xml b/maven-modules/maven-classifier/pom.xml index 6b75f60893..ba5f248ff6 100644 --- a/maven-modules/maven-classifier/pom.xml +++ b/maven-modules/maven-classifier/pom.xml @@ -1,9 +1,8 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - maven-classifier pom 0.0.1-SNAPSHOT @@ -24,4 +23,4 @@ 8 - + \ No newline at end of file diff --git a/maven-modules/maven-copy-files/copy-rename-maven-plugin/pom.xml b/maven-modules/maven-copy-files/copy-rename-maven-plugin/pom.xml index 06a44ed4fb..dbc27b61f2 100644 --- a/maven-modules/maven-copy-files/copy-rename-maven-plugin/pom.xml +++ b/maven-modules/maven-copy-files/copy-rename-maven-plugin/pom.xml @@ -3,9 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.baeldung copy-rename-maven-plugin - 1.0-SNAPSHOT copy-rename-maven-plugin diff --git a/maven-modules/maven-copy-files/copy-rename-maven-plugin/src/test/java/org/baeldung/CopyFileUnitTest.java b/maven-modules/maven-copy-files/copy-rename-maven-plugin/src/test/java/com/baeldung/CopyFileUnitTest.java similarity index 94% rename from maven-modules/maven-copy-files/copy-rename-maven-plugin/src/test/java/org/baeldung/CopyFileUnitTest.java rename to maven-modules/maven-copy-files/copy-rename-maven-plugin/src/test/java/com/baeldung/CopyFileUnitTest.java index a98db61fa9..94fa31a3ed 100644 --- a/maven-modules/maven-copy-files/copy-rename-maven-plugin/src/test/java/org/baeldung/CopyFileUnitTest.java +++ b/maven-modules/maven-copy-files/copy-rename-maven-plugin/src/test/java/com/baeldung/CopyFileUnitTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; diff --git a/maven-modules/maven-copy-files/maven-antrun-plugin/pom.xml b/maven-modules/maven-copy-files/maven-antrun-plugin/pom.xml index b005f4b125..430d0a1f5b 100644 --- a/maven-modules/maven-copy-files/maven-antrun-plugin/pom.xml +++ b/maven-modules/maven-copy-files/maven-antrun-plugin/pom.xml @@ -3,9 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.baeldung maven-antrun-plugin - 1.0-SNAPSHOT maven-antrun-plugin diff --git a/maven-modules/maven-copy-files/maven-antrun-plugin/src/test/java/org/baeldung/CopyFileUnitTest.java b/maven-modules/maven-copy-files/maven-antrun-plugin/src/test/java/com/baeldung/CopyFileUnitTest.java similarity index 94% rename from maven-modules/maven-copy-files/maven-antrun-plugin/src/test/java/org/baeldung/CopyFileUnitTest.java rename to maven-modules/maven-copy-files/maven-antrun-plugin/src/test/java/com/baeldung/CopyFileUnitTest.java index a98db61fa9..94fa31a3ed 100644 --- a/maven-modules/maven-copy-files/maven-antrun-plugin/src/test/java/org/baeldung/CopyFileUnitTest.java +++ b/maven-modules/maven-copy-files/maven-antrun-plugin/src/test/java/com/baeldung/CopyFileUnitTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; diff --git a/maven-modules/maven-copy-files/maven-resources-plugin/pom.xml b/maven-modules/maven-copy-files/maven-resources-plugin/pom.xml index a49095f528..b2e99f80bc 100644 --- a/maven-modules/maven-copy-files/maven-resources-plugin/pom.xml +++ b/maven-modules/maven-copy-files/maven-resources-plugin/pom.xml @@ -3,9 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.baeldung maven-resources-plugin - 1.0-SNAPSHOT maven-resources-plugin diff --git a/maven-modules/maven-copy-files/maven-resources-plugin/src/test/java/org/baeldung/CopyFileUnitTest.java b/maven-modules/maven-copy-files/maven-resources-plugin/src/test/java/com/baeldung/CopyFileUnitTest.java similarity index 94% rename from maven-modules/maven-copy-files/maven-resources-plugin/src/test/java/org/baeldung/CopyFileUnitTest.java rename to maven-modules/maven-copy-files/maven-resources-plugin/src/test/java/com/baeldung/CopyFileUnitTest.java index a98db61fa9..94fa31a3ed 100644 --- a/maven-modules/maven-copy-files/maven-resources-plugin/src/test/java/org/baeldung/CopyFileUnitTest.java +++ b/maven-modules/maven-copy-files/maven-resources-plugin/src/test/java/com/baeldung/CopyFileUnitTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; diff --git a/maven-modules/maven-generate-war/pom.xml b/maven-modules/maven-generate-war/pom.xml index b388cfdadd..51eb54846c 100644 --- a/maven-modules/maven-generate-war/pom.xml +++ b/maven-modules/maven-generate-war/pom.xml @@ -6,8 +6,8 @@ com.baeldung maven-generate-war 0.0.1-SNAPSHOT - war maven-generate-war + war Spring boot project to demonstrate war file generation diff --git a/maven-modules/maven-simple/maven-dependency/pom.xml b/maven-modules/maven-simple/maven-dependency/pom.xml index 628c1b62d4..ba63e53a1a 100644 --- a/maven-modules/maven-simple/maven-dependency/pom.xml +++ b/maven-modules/maven-simple/maven-dependency/pom.xml @@ -4,13 +4,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 maven-dependency - 1.0.0-SNAPSHOT pom com.baeldung maven-simple - 0.0.1-SNAPSHOT + 1.0.0-SNAPSHOT diff --git a/maven-modules/maven-simple/parent-project/core/pom.xml b/maven-modules/maven-simple/parent-project/core/pom.xml index 8f7371639f..6553889c24 100644 --- a/maven-modules/maven-simple/parent-project/core/pom.xml +++ b/maven-modules/maven-simple/parent-project/core/pom.xml @@ -3,14 +3,24 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.baeldung core core parent-project com.baeldung - 1.0.0-SNAPSHOT + 1.0-SNAPSHOT - + + + org.springframework + spring-core + ${spring-core.version} + + + + + 4.3.30.RELEASE + + \ No newline at end of file diff --git a/maven-modules/maven-simple/parent-project/pom.xml b/maven-modules/maven-simple/parent-project/pom.xml index fce9aa3f72..bde903b1b5 100644 --- a/maven-modules/maven-simple/parent-project/pom.xml +++ b/maven-modules/maven-simple/parent-project/pom.xml @@ -4,6 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 parent-project + 1.0-SNAPSHOT parent-project pom @@ -18,4 +19,18 @@ service webapp - + + + + + org.springframework + spring-core + ${spring-core.version} + + + + + + 5.3.16 + + \ No newline at end of file diff --git a/maven-modules/maven-simple/parent-project/service/pom.xml b/maven-modules/maven-simple/parent-project/service/pom.xml index 39945af248..78d458c55a 100644 --- a/maven-modules/maven-simple/parent-project/service/pom.xml +++ b/maven-modules/maven-simple/parent-project/service/pom.xml @@ -3,14 +3,13 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.baeldung service service parent-project com.baeldung - 1.0.0-SNAPSHOT + 1.0-SNAPSHOT - + \ No newline at end of file diff --git a/maven-modules/maven-simple/parent-project/webapp/pom.xml b/maven-modules/maven-simple/parent-project/webapp/pom.xml index 1ab1321b20..f6cee60cbf 100644 --- a/maven-modules/maven-simple/parent-project/webapp/pom.xml +++ b/maven-modules/maven-simple/parent-project/webapp/pom.xml @@ -3,14 +3,31 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.baeldung webapp webapp + war + parent-project com.baeldung - 1.0.0-SNAPSHOT + 1.0-SNAPSHOT - + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + + + + 3.3.2 + + \ No newline at end of file diff --git a/metrics/pom.xml b/metrics/pom.xml index abdfb14dc6..37b10ef484 100644 --- a/metrics/pom.xml +++ b/metrics/pom.xml @@ -92,4 +92,4 @@ 1.1.0 - + \ No newline at end of file diff --git a/netty/pom.xml b/netty/pom.xml index 817b1f2e70..c235ec9f4a 100644 --- a/netty/pom.xml +++ b/netty/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 netty 0.0.1-SNAPSHOT @@ -11,20 +12,18 @@ parent-modules 1.0.0-SNAPSHOT - + io.netty netty-all ${netty.version} - - + org.conscrypt conscrypt-openjdk-uber ${conscrypt-openjdk-uber.version} - diff --git a/nginx-forward-proxy/README.md b/nginx-forward-proxy/README.md new file mode 100644 index 0000000000..68ef37dcfb --- /dev/null +++ b/nginx-forward-proxy/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Using Nginx as a Forward Proxy](https://www.baeldung.com/nginx-forward-proxy) diff --git a/patterns/enterprise-patterns/pom.xml b/patterns/enterprise-patterns/pom.xml index 999b359170..2228cc9505 100644 --- a/patterns/enterprise-patterns/pom.xml +++ b/patterns/enterprise-patterns/pom.xml @@ -16,6 +16,25 @@ wire-tap + + + + org.apache.camel.springboot + camel-spring-boot-dependencies + ${camel.version} + pom + import + + + org.apache.logging.log4j + log4j-bom + ${log4j2.version} + import + pom + + + + org.apache.camel.springboot @@ -39,25 +58,6 @@ - - - - org.apache.camel.springboot - camel-spring-boot-dependencies - ${camel.version} - pom - import - - - org.apache.logging.log4j - log4j-bom - ${log4j2.version} - import - pom - - - - @@ -70,7 +70,7 @@ 3.7.4 2.2.2.RELEASE - 2.17.1 + 2.17.1 \ No newline at end of file diff --git a/persistence-modules/fauna/README.md b/persistence-modules/fauna/README.md new file mode 100644 index 0000000000..f0899ceaf7 --- /dev/null +++ b/persistence-modules/fauna/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Building a web app Using Fauna and Spring for Your First web Agency Client](https://www.baeldung.com/faunadb-spring-web-app) diff --git a/persistence-modules/hibernate-mapping-2/pom.xml b/persistence-modules/hibernate-mapping-2/pom.xml index 06a1535442..8cec8d5d34 100644 --- a/persistence-modules/hibernate-mapping-2/pom.xml +++ b/persistence-modules/hibernate-mapping-2/pom.xml @@ -54,22 +54,22 @@ com.h2database h2 ${h2.version} - - - com.sun.xml.bind - jaxb-core - ${com.sun.xml.version} - - - javax.xml.bind - jaxb-api - ${javax.xml.bind.version} - - - com.sun.xml.bind - jaxb-impl - ${com.sun.xml.version} - + + + com.sun.xml.bind + jaxb-core + ${com.sun.xml.version} + + + javax.xml.bind + jaxb-api + ${javax.xml.bind.version} + + + com.sun.xml.bind + jaxb-impl + ${com.sun.xml.version} + diff --git a/persistence-modules/java-cassandra/pom.xml b/persistence-modules/java-cassandra/pom.xml index b0b98b040a..0dd148e528 100644 --- a/persistence-modules/java-cassandra/pom.xml +++ b/persistence-modules/java-cassandra/pom.xml @@ -77,4 +77,4 @@ 4.1.71.Final - + \ No newline at end of file diff --git a/persistence-modules/java-mongodb-2/.gitignore b/persistence-modules/java-mongodb-2/.gitignore new file mode 100644 index 0000000000..79ba317cb5 --- /dev/null +++ b/persistence-modules/java-mongodb-2/.gitignore @@ -0,0 +1,5 @@ +.classpath +.project +.settings +target +build \ No newline at end of file diff --git a/persistence-modules/java-mongodb-2/README.md b/persistence-modules/java-mongodb-2/README.md new file mode 100644 index 0000000000..1b49e11499 --- /dev/null +++ b/persistence-modules/java-mongodb-2/README.md @@ -0,0 +1,5 @@ +## MongoDB + +This module contains articles about MongoDB in Java. + + diff --git a/persistence-modules/java-mongodb-2/pom.xml b/persistence-modules/java-mongodb-2/pom.xml new file mode 100644 index 0000000000..ffc8da0b64 --- /dev/null +++ b/persistence-modules/java-mongodb-2/pom.xml @@ -0,0 +1,53 @@ + + + 4.0.0 + java-mongodb-2 + 1.0-SNAPSHOT + java-mongodb-2 + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + de.flapdoodle.embedmongo + de.flapdoodle.embedmongo + ${flapdoodle.version} + test + + + org.mongodb + mongo-java-driver + ${mongo.version} + + + dev.morphia.morphia + core + ${morphia.version} + + + org.testcontainers + mongodb + 1.16.3 + test + + + org.testcontainers + junit-jupiter + 1.16.3 + test + + + + + 3.12.1 + 1.11 + 1.5.3 + + + diff --git a/persistence-modules/java-mongodb-2/src/main/java/com/baeldung/mongo/update/PustSetOperation.java b/persistence-modules/java-mongodb-2/src/main/java/com/baeldung/mongo/update/PustSetOperation.java new file mode 100644 index 0000000000..bb7eca4f23 --- /dev/null +++ b/persistence-modules/java-mongodb-2/src/main/java/com/baeldung/mongo/update/PustSetOperation.java @@ -0,0 +1,54 @@ +package com.baeldung.mongo.update; + +import org.bson.Document; + +import com.mongodb.MongoClient; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.Updates; +import com.mongodb.client.result.UpdateResult; + +public class PustSetOperation { + + private static MongoClient mongoClient; + + private static String testCollectionName; + private static String databaseName; + + public static void setUp() { + if (mongoClient == null) { + mongoClient = new MongoClient("localhost", 27017); + } + databaseName = "baeldung"; + testCollectionName = "marks"; + } + + public static void pushSetSolution() { + + MongoDatabase database = mongoClient.getDatabase(databaseName); + MongoCollection collection = database.getCollection(testCollectionName); + + Document subjectData = new Document().append("subjectId", 126) + .append("subjectName", "Java Programming") + .append("marks", 70); + UpdateResult updateQueryResult = collection.updateOne(Filters.eq("studentId", 1023), Updates.combine(Updates.set("totalMarks", 170), Updates.push("subjectDetails", subjectData))); + System.out.println("updateQueryResult:- " + updateQueryResult); + + } + + public static void main(String args[]) { + + // + // Connect to cluster (default is localhost:27017) + // + setUp(); + + // + // Push document into the array and set a field + // + pushSetSolution(); + + } +} + diff --git a/persistence-modules/java-mongodb-2/src/main/resources/logback.xml b/persistence-modules/java-mongodb-2/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/persistence-modules/java-mongodb-2/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/java-mongodb-2/src/test/java/com/baeldung/mongo/update/PustSetOperationLiveTest.java b/persistence-modules/java-mongodb-2/src/test/java/com/baeldung/mongo/update/PustSetOperationLiveTest.java new file mode 100644 index 0000000000..6279747429 --- /dev/null +++ b/persistence-modules/java-mongodb-2/src/test/java/com/baeldung/mongo/update/PustSetOperationLiveTest.java @@ -0,0 +1,53 @@ +package com.baeldung.update; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +import org.bson.Document; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.mongodb.MongoClient; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.Updates; +import com.mongodb.client.result.UpdateResult; + +public class PustSetOperationLiveTest { + + private static MongoClient mongoClient; + private static MongoDatabase db; + private static MongoCollection collection; + + @BeforeClass + public static void setup() { + if (mongoClient == null) { + mongoClient = new MongoClient("localhost", 27017); + db = mongoClient.getDatabase("baeldung"); + collection = db.getCollection("marks"); + + collection.insertOne(Document.parse("{\n" + " \"studentId\": 1023,\n" + " \"studentName\":\"James Broad\",\n" + " \"joiningYear\":\"2018\",\n" + " \"totalMarks\":100,\n" + " \"subjectDetails\":[\n" + + " {\n" + " \"subjectId\":123,\n" + " \"subjectName\":\"Operating Systems Concepts\",\n" + " \"marks\":4,\n" + " },\n" + " {\n" + + " \"subjectId\":124,\n" + " \"subjectName\":\"Numerical Analysis\",\n" + " \"marks\":60\n" + " }\n" + " ]\n" + " }")); + + } + } + + @Test + public void givenMarksCollection_whenPushSetOperation_thenCheckingForDocument() { + + Document subjectData = new Document().append("subjectId", 126) + .append("subjectName", "Java Programming") + .append("marks", 70); + UpdateResult updateQueryResult = collection.updateOne(Filters.eq("studentId", 1023), Updates.combine(Updates.set("totalMarks", 170), Updates.push("subjectDetails", subjectData))); + + Document studentDetail = collection.find(Filters.eq("studentId", 1023)) + .first(); + assertNotNull(studentDetail); + assertFalse(studentDetail.isEmpty()); + + } + +} + diff --git a/persistence-modules/java-mongodb/README.md b/persistence-modules/java-mongodb/README.md index 2b7fcd3de0..6f6bcba250 100644 --- a/persistence-modules/java-mongodb/README.md +++ b/persistence-modules/java-mongodb/README.md @@ -14,3 +14,7 @@ This module contains articles about MongoDB in Java. - [How to Check Field Existence in MongoDB?](https://www.baeldung.com/mongodb-check-field-exists) - [Get Last Inserted Document ID in MongoDB With Java Driver](https://www.baeldung.com/java-mongodb-last-inserted-id) - [Update Multiple Fields in a MongoDB Document](https://www.baeldung.com/mongodb-update-multiple-fields) +- [Update Documents in MongoDB](https://www.baeldung.com/mongodb-update-documents) +- [Check Collection Existence in MongoDB](https://www.baeldung.com/java-check-collection-existence-mongodb) +- [Case Insensitive Sorting in MongoDB](https://www.baeldung.com/java-mongodb-case-insensitive-sorting) +- [Push and Set Operations in Same MongoDB Update](https://www.baeldung.com/java-mongodb-push-set) diff --git a/persistence-modules/java-mongodb/pom.xml b/persistence-modules/java-mongodb/pom.xml index 03229e72bd..88f0d18a5b 100644 --- a/persistence-modules/java-mongodb/pom.xml +++ b/persistence-modules/java-mongodb/pom.xml @@ -30,6 +30,18 @@ core ${morphia.version} + + org.testcontainers + mongodb + 1.16.3 + test + + + org.testcontainers + junit-jupiter + 1.16.3 + test + diff --git a/persistence-modules/java-mongodb/src/test/java/com/baeldung/ordering/caseinsensitive/CaseInsensitiveOrderingLiveTest.java b/persistence-modules/java-mongodb/src/test/java/com/baeldung/ordering/caseinsensitive/CaseInsensitiveOrderingLiveTest.java new file mode 100644 index 0000000000..ec2c332018 --- /dev/null +++ b/persistence-modules/java-mongodb/src/test/java/com/baeldung/ordering/caseinsensitive/CaseInsensitiveOrderingLiveTest.java @@ -0,0 +1,108 @@ +package com.baeldung.ordering.caseinsensitive; + +import com.mongodb.MongoClient; +import com.mongodb.client.*; +import com.mongodb.client.model.Collation; +import com.mongodb.client.model.Projections; +import com.mongodb.client.model.Sorts; +import org.bson.Document; +import org.bson.conversions.Bson; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.MongoDBContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static com.mongodb.client.model.Aggregates.project; +import static com.mongodb.client.model.Aggregates.sort; +import static com.mongodb.client.model.Sorts.ascending; +import static org.junit.Assert.assertEquals; + +@Testcontainers +class CaseInsensitiveOrderingLiveTest { + + private static MongoCollection userCollections; + + @Container + private static final MongoDBContainer mongoDBContainer = new MongoDBContainer(DockerImageName.parse("mongo:4.0.10")); + + @BeforeAll + private static void setup() { + + MongoClient mongoClient = new MongoClient(mongoDBContainer.getContainerIpAddress(), mongoDBContainer.getMappedPort(27017)); + MongoDatabase database = mongoClient.getDatabase("test"); + userCollections = database.getCollection("users"); + + List list = new ArrayList<>(); + list.add(Document.parse("{'name': 'ben', surname: 'ThisField' }")); + list.add(Document.parse("{'name': 'aen', surname: 'Does' }")); + list.add(Document.parse("{'name': 'Ben', surname: 'Not' }")); + list.add(Document.parse("{'name': 'cen', surname: 'Matter' }")); + list.add(Document.parse("{'name': 'Aen', surname: 'Really' }")); + list.add(Document.parse("{'name': 'Cen', surname: 'TrustMe' }")); + + userCollections.insertMany(list); + } + + @Test + void givenMongoCollection_whenUsingFindWithSort_caseIsConsideredByDefault() { + FindIterable nameDoc = userCollections.find().sort(ascending("name")); + MongoCursor cursor = nameDoc.cursor(); + + List expectedNamesOrdering = Arrays.asList("Aen", "Ben", "Cen", "aen", "ben", "cen"); + List actualNamesOrdering = new ArrayList<>(); + while (cursor.hasNext()) { + Document document = cursor.next(); + actualNamesOrdering.add(document.get("name").toString()); + } + + assertEquals(expectedNamesOrdering, actualNamesOrdering); + } + + @Test + void givenMongoCollection_whenUsingFindWithSortAndCollation_caseIsNotConsidered() { + FindIterable nameDoc = userCollections.find().sort(ascending("name")) + .collation(Collation.builder().locale("en").build()); + MongoCursor cursor = nameDoc.cursor(); + List expectedNamesOrdering = Arrays.asList("aen", "Aen", "ben", "Ben", "cen", "Cen"); + List actualNamesOrdering = new ArrayList<>(); + while (cursor.hasNext()) { + Document document = cursor.next(); + actualNamesOrdering.add(document.get("name").toString()); + } + + assertEquals(expectedNamesOrdering, actualNamesOrdering); + + } + + @Test + void givenMongoCollection_whenUsingFindWithSortAndAggregate_caseIsNotConsidered() { + + Bson projectBson = project( + Projections.fields( + Projections.include("name", "surname"), + Projections.computed("lowerName", Projections.computed("$toLower", "$name")))); + + AggregateIterable nameDoc = userCollections.aggregate( + Arrays.asList(projectBson, + sort(Sorts.ascending("lowerName")))); + + MongoCursor cursor = nameDoc.cursor(); + + List expectedNamesOrdering = Arrays.asList("aen", "Aen", "ben", "Ben", "cen", "Cen"); + List actualNamesOrdering = new ArrayList<>(); + while (cursor.hasNext()) { + Document document = cursor.next(); + actualNamesOrdering.add(document.get("name").toString()); + } + + assertEquals(expectedNamesOrdering, actualNamesOrdering); + } + + +} diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 64a9519a8b..f8e3cb05e8 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -43,6 +43,7 @@ java-jpa-2 java-jpa-3 java-mongodb + java-mongodb-2 jnosql jooq jpa-hibernate-cascade-type @@ -104,4 +105,4 @@ 42.2.20 - \ No newline at end of file + diff --git a/persistence-modules/spring-data-jdbc/pom.xml b/persistence-modules/spring-data-jdbc/pom.xml index 168b171337..630fe141b3 100644 --- a/persistence-modules/spring-data-jdbc/pom.xml +++ b/persistence-modules/spring-data-jdbc/pom.xml @@ -36,4 +36,4 @@ - + \ No newline at end of file diff --git a/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springmultipledatasources/todos/TodoDatasourceConfiguration.java b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springmultipledatasources/todos/TodoDatasourceConfiguration.java index b6a16eb7e4..c599c26d01 100644 --- a/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springmultipledatasources/todos/TodoDatasourceConfiguration.java +++ b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springmultipledatasources/todos/TodoDatasourceConfiguration.java @@ -19,6 +19,7 @@ public class TodoDatasourceConfiguration { @Bean @Primary + @ConfigurationProperties("spring.datasource.todos.hikari") public DataSource todosDataSource() { return todosDataSourceProperties() .initializeDataSourceBuilder() diff --git a/persistence-modules/spring-data-jdbc/src/main/resources/application-multipledatasources.properties b/persistence-modules/spring-data-jdbc/src/main/resources/application-multipledatasources.properties index 0f2b643498..d9f859ea40 100644 --- a/persistence-modules/spring-data-jdbc/src/main/resources/application-multipledatasources.properties +++ b/persistence-modules/spring-data-jdbc/src/main/resources/application-multipledatasources.properties @@ -3,6 +3,7 @@ spring.datasource.todos.url=jdbc:h2:mem:todos spring.datasource.todos.username=sa spring.datasource.todos.password=null spring.datasource.todos.driverClassName=org.h2.Driver +spring.datasource.todos.hikari.connectionTimeout=44444 spring.datasource.topics.url=jdbc:h2:mem:topics spring.datasource.topics.username=sa spring.datasource.topics.password=null diff --git a/persistence-modules/spring-data-jpa-query-3/pom.xml b/persistence-modules/spring-data-jpa-query-3/pom.xml index 66a4486bc8..135d31aaba 100644 --- a/persistence-modules/spring-data-jpa-query-3/pom.xml +++ b/persistence-modules/spring-data-jpa-query-3/pom.xml @@ -29,4 +29,4 @@ - + \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-5/pom.xml b/persistence-modules/spring-hibernate-5/pom.xml index ba18c5a221..3f5d00733d 100644 --- a/persistence-modules/spring-hibernate-5/pom.xml +++ b/persistence-modules/spring-hibernate-5/pom.xml @@ -107,22 +107,22 @@ com.h2database h2 ${h2.version} - - - com.sun.xml.bind - jaxb-core - ${com.sun.xml.version} - - - javax.xml.bind - jaxb-api - ${javax.xml.bind.version} - - - com.sun.xml.bind - jaxb-impl - ${com.sun.xml.version} - + + + com.sun.xml.bind + jaxb-core + ${com.sun.xml.version} + + + javax.xml.bind + jaxb-api + ${javax.xml.bind.version} + + + com.sun.xml.bind + jaxb-impl + ${com.sun.xml.version} + diff --git a/pom.xml b/pom.xml index a6202230d4..daaf9db6d2 100644 --- a/pom.xml +++ b/pom.xml @@ -1206,6 +1206,7 @@ wicket wildfly xml + xml-2 xstream diff --git a/quarkus-jandex/hello-sender-application-properties/pom.xml b/quarkus-jandex/hello-sender-application-properties/pom.xml index f63bb9be81..6658123bee 100644 --- a/quarkus-jandex/hello-sender-application-properties/pom.xml +++ b/quarkus-jandex/hello-sender-application-properties/pom.xml @@ -23,4 +23,4 @@ - + \ No newline at end of file diff --git a/reactive-systems/inventory-service/pom.xml b/reactive-systems/inventory-service/pom.xml index 86575d498c..4aeec24922 100644 --- a/reactive-systems/inventory-service/pom.xml +++ b/reactive-systems/inventory-service/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + reactive-systems 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/reactive-systems/order-service/pom.xml b/reactive-systems/order-service/pom.xml index e6453732b4..b9e5d36d3a 100644 --- a/reactive-systems/order-service/pom.xml +++ b/reactive-systems/order-service/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + reactive-systems 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/reactive-systems/pom.xml b/reactive-systems/pom.xml index 81462090b8..b984fc7cd8 100644 --- a/reactive-systems/pom.xml +++ b/reactive-systems/pom.xml @@ -10,8 +10,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 diff --git a/reactive-systems/shipping-service/pom.xml b/reactive-systems/shipping-service/pom.xml index f725ca72d1..5fac674bbc 100644 --- a/reactive-systems/shipping-service/pom.xml +++ b/reactive-systems/shipping-service/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-2 + reactive-systems 0.0.1-SNAPSHOT - ../../parent-boot-2 diff --git a/spring-5-data-reactive/pom.xml b/spring-5-data-reactive/pom.xml index 023eda856b..24971c0289 100644 --- a/spring-5-data-reactive/pom.xml +++ b/spring-5-data-reactive/pom.xml @@ -13,7 +13,7 @@ 0.0.1-SNAPSHOT ../parent-boot-2 - + diff --git a/spring-5-reactive-3/pom.xml b/spring-5-reactive-3/pom.xml index 89af34732f..fea72cc736 100644 --- a/spring-5-reactive-3/pom.xml +++ b/spring-5-reactive-3/pom.xml @@ -41,4 +41,5 @@ 1.0.1.RELEASE + \ No newline at end of file diff --git a/spring-activiti/pom.xml b/spring-activiti/pom.xml index 2ede13a152..898f88285b 100644 --- a/spring-activiti/pom.xml +++ b/spring-activiti/pom.xml @@ -16,7 +16,7 @@ 0.0.1-SNAPSHOT ../parent-boot-1 - + diff --git a/spring-boot-modules/spring-boot-camel/.gitignore b/spring-boot-modules/spring-boot-camel/.gitignore new file mode 100644 index 0000000000..16be8f2193 --- /dev/null +++ b/spring-boot-modules/spring-boot-camel/.gitignore @@ -0,0 +1 @@ +/output/ diff --git a/spring-boot-modules/spring-boot-camel/pom.xml b/spring-boot-modules/spring-boot-camel/pom.xml index 5bda1b2351..ecf7143808 100644 --- a/spring-boot-modules/spring-boot-camel/pom.xml +++ b/spring-boot-modules/spring-boot-camel/pom.xml @@ -44,6 +44,12 @@ spring-boot-starter-test test + + org.apache.camel + camel-test-spring-junit5 + ${camel.version} + test + @@ -57,6 +63,9 @@ repackage + + com.baeldung.camel.boot.testing.GreetingsFileSpringApplication + diff --git a/spring-boot-modules/spring-boot-camel/src/main/java/com/baeldung/camel/boot/testing/GreetingsFileRouter.java b/spring-boot-modules/spring-boot-camel/src/main/java/com/baeldung/camel/boot/testing/GreetingsFileRouter.java new file mode 100644 index 0000000000..670af5e08c --- /dev/null +++ b/spring-boot-modules/spring-boot-camel/src/main/java/com/baeldung/camel/boot/testing/GreetingsFileRouter.java @@ -0,0 +1,19 @@ +package com.baeldung.camel.boot.testing; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; + +@Component +public class GreetingsFileRouter extends RouteBuilder { + + @Override + public void configure() throws Exception { + + from("direct:start") + .routeId("greetings-route") + .setBody(constant("Hello Baeldung Readers!")) + .to("file:output"); + + } + +} diff --git a/spring-boot-modules/spring-boot-camel/src/main/java/com/baeldung/camel/boot/testing/GreetingsFileSpringApplication.java b/spring-boot-modules/spring-boot-camel/src/main/java/com/baeldung/camel/boot/testing/GreetingsFileSpringApplication.java new file mode 100644 index 0000000000..a4e862e65d --- /dev/null +++ b/spring-boot-modules/spring-boot-camel/src/main/java/com/baeldung/camel/boot/testing/GreetingsFileSpringApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.camel.boot.testing; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class GreetingsFileSpringApplication { + + public static void main(String[] args) { + SpringApplication.run(GreetingsFileSpringApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-camel/src/test/java/com/baeldung/camel/boot/testing/GreetingsFileRouterUnitTest.java b/spring-boot-modules/spring-boot-camel/src/test/java/com/baeldung/camel/boot/testing/GreetingsFileRouterUnitTest.java new file mode 100644 index 0000000000..baeb1fd39c --- /dev/null +++ b/spring-boot-modules/spring-boot-camel/src/test/java/com/baeldung/camel/boot/testing/GreetingsFileRouterUnitTest.java @@ -0,0 +1,32 @@ +package com.baeldung.camel.boot.testing; + +import org.apache.camel.EndpointInject; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.apache.camel.test.spring.junit5.MockEndpoints; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +@CamelSpringBootTest +@MockEndpoints("file:output") +class GreetingsFileRouterUnitTest { + + @Autowired + private ProducerTemplate template; + + @EndpointInject("mock:file:output") + private MockEndpoint mock; + + @Test + void whenSendBody_thenGreetingReceivedSuccessfully() throws InterruptedException { + mock.expectedBodiesReceived("Hello Baeldung Readers!"); + + template.sendBody("direct:start", null); + + mock.assertIsSatisfied(); + } + +} diff --git a/spring-boot-modules/spring-boot-multiple-datasources/pom.xml b/spring-boot-modules/spring-boot-multiple-datasources/pom.xml index d66095bc2c..9355de8a36 100644 --- a/spring-boot-modules/spring-boot-multiple-datasources/pom.xml +++ b/spring-boot-modules/spring-boot-multiple-datasources/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-boot-multiple-datasources 0.1.0-SNAPSHOT @@ -55,4 +55,4 @@ 2.6.3 - + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/README.md b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/README.md new file mode 100644 index 0000000000..a7ff3285ee --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Set List of Objects in Swagger API Response](https://www.baeldung.com/java-swagger-set-list-response) diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java new file mode 100644 index 0000000000..913544b459 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.swaggerresponseapi; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SwaggerResponseApiApplication { + + public static void main(String[] args) { + SpringApplication.run(SwaggerResponseApiApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java new file mode 100644 index 0000000000..364a7e8a66 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java @@ -0,0 +1,38 @@ +package com.baeldung.swaggerresponseapi.controller; + +import com.baeldung.swaggerresponseapi.model.Product; +import com.baeldung.swaggerresponseapi.service.ProductService; + +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +public class ProductController { + private final ProductService productService; + + public ProductController(ProductService productService) { + this.productService = productService; + } + + @PostMapping("/create") + public Product addProduct(@RequestBody Product product) { + return productService.addProducts(product); + } + + @ApiResponses(value = { @ApiResponse(content = { @Content(mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = Product.class))) }) }) + @GetMapping("/products") + public List getProductsList() { + return productService.getProductsList(); + } +} diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java new file mode 100644 index 0000000000..036ecbc853 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java @@ -0,0 +1,28 @@ +package com.baeldung.swaggerresponseapi.model; + +public class Product { + String code; + String name; + + public Product(String code, String name) { + this.code = code; + this.name = name; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} + diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java new file mode 100644 index 0000000000..5e7533d6f4 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java @@ -0,0 +1,21 @@ +package com.baeldung.swaggerresponseapi.service; + +import com.baeldung.swaggerresponseapi.model.Product; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class ProductService { + List productsList = new ArrayList<>(); + + public Product addProducts(Product product) { + productsList.add(product); + return product; + } + + public List getProductsList() { + return productsList; + } +} diff --git a/spring-boot-modules/spring-boot-swagger-keycloak/pom.xml b/spring-boot-modules/spring-boot-swagger-keycloak/pom.xml index a7f3e01014..de2c8c68c4 100644 --- a/spring-boot-modules/spring-boot-swagger-keycloak/pom.xml +++ b/spring-boot-modules/spring-boot-swagger-keycloak/pom.xml @@ -72,4 +72,4 @@ 2.17.1 - + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-swagger/pom.xml b/spring-boot-modules/spring-boot-swagger/pom.xml index b6ed50534e..749442c225 100644 --- a/spring-boot-modules/spring-boot-swagger/pom.xml +++ b/spring-boot-modules/spring-boot-swagger/pom.xml @@ -84,4 +84,4 @@ 3.1.1 - + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/XmlBeanApplication.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/xmlapplicationcontext/XmlBeanApplication.java similarity index 100% rename from spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/XmlBeanApplication.java rename to spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/xmlapplicationcontext/XmlBeanApplication.java diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/domain/Employee.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/xmlapplicationcontext/domain/Employee.java similarity index 100% rename from spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/domain/Employee.java rename to spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/xmlapplicationcontext/domain/Employee.java diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeService.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeService.java similarity index 100% rename from spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeService.java rename to spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeService.java diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeServiceImpl.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeServiceImpl.java similarity index 100% rename from spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeServiceImpl.java rename to spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeServiceImpl.java diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeServiceTestImpl.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeServiceTestImpl.java similarity index 100% rename from spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeServiceTestImpl.java rename to spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeServiceTestImpl.java diff --git a/spring-boot-modules/spring-boot-testing/src/main/resources/application-context.xml b/spring-boot-modules/spring-boot-testing-2/src/main/resources/application-context.xml similarity index 100% rename from spring-boot-modules/spring-boot-testing/src/main/resources/application-context.xml rename to spring-boot-modules/spring-boot-testing-2/src/main/resources/application-context.xml diff --git a/spring-boot-modules/spring-boot-testing/src/main/webapp/WEB-INF/application-context.xml b/spring-boot-modules/spring-boot-testing-2/src/main/webapp/WEB-INF/application-context.xml similarity index 100% rename from spring-boot-modules/spring-boot-testing/src/main/webapp/WEB-INF/application-context.xml rename to spring-boot-modules/spring-boot-testing-2/src/main/webapp/WEB-INF/application-context.xml diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceAppContextIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceAppContextIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceAppContextIntegrationTest.java rename to spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceAppContextIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceTestContextIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceTestContextIntegrationTest.java similarity index 100% rename from spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceTestContextIntegrationTest.java rename to spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceTestContextIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-testing/src/test/resources/test-context.xml b/spring-boot-modules/spring-boot-testing-2/src/test/resources/test-context.xml similarity index 100% rename from spring-boot-modules/spring-boot-testing/src/test/resources/test-context.xml rename to spring-boot-modules/spring-boot-testing-2/src/test/resources/test-context.xml diff --git a/spring-cloud/spring-cloud-archaius/zookeeper-config/pom.xml b/spring-cloud/spring-cloud-archaius/zookeeper-config/pom.xml index bdd75d0635..7700a2219d 100644 --- a/spring-cloud/spring-cloud-archaius/zookeeper-config/pom.xml +++ b/spring-cloud/spring-cloud-archaius/zookeeper-config/pom.xml @@ -45,7 +45,7 @@ 2.0.0.RELEASE 3.4.13 - 2.17.1 + 2.17.1 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-eureka-self-preservation/pom.xml b/spring-cloud/spring-cloud-eureka-self-preservation/pom.xml index e22ad6b7c9..5000adc164 100644 --- a/spring-cloud/spring-cloud-eureka-self-preservation/pom.xml +++ b/spring-cloud/spring-cloud-eureka-self-preservation/pom.xml @@ -14,7 +14,12 @@ spring-cloud 1.0.0-SNAPSHOT - + + + spring-cloud-eureka-server + spring-cloud-eureka-client + + @@ -27,11 +32,6 @@ - - spring-cloud-eureka-server - spring-cloud-eureka-client - - org.springframework.boot diff --git a/spring-cloud/spring-cloud-eureka/pom.xml b/spring-cloud/spring-cloud-eureka/pom.xml index 795eab7d6e..63190f7f20 100644 --- a/spring-cloud/spring-cloud-eureka/pom.xml +++ b/spring-cloud/spring-cloud-eureka/pom.xml @@ -14,7 +14,14 @@ spring-cloud 1.0.0-SNAPSHOT - + + + spring-cloud-eureka-server + spring-cloud-eureka-client + spring-cloud-eureka-feign-client + spring-cloud-eureka-feign-client-integration-test + + @@ -27,13 +34,6 @@ - - spring-cloud-eureka-server - spring-cloud-eureka-client - spring-cloud-eureka-feign-client - spring-cloud-eureka-feign-client-integration-test - - org.springframework.boot diff --git a/spring-cloud/spring-cloud-functions/pom.xml b/spring-cloud/spring-cloud-functions/pom.xml index 3dc68e2824..d9f90c7a56 100644 --- a/spring-cloud/spring-cloud-functions/pom.xml +++ b/spring-cloud/spring-cloud-functions/pom.xml @@ -10,7 +10,7 @@ jar Demo project for Spring Cloud Function - + com.baeldung.spring.cloud spring-cloud 1.0.0-SNAPSHOT diff --git a/spring-cloud/spring-cloud-gateway/pom.xml b/spring-cloud/spring-cloud-gateway/pom.xml index a352bbd4e4..e8949cc039 100644 --- a/spring-cloud/spring-cloud-gateway/pom.xml +++ b/spring-cloud/spring-cloud-gateway/pom.xml @@ -83,31 +83,28 @@ org.springframework.boot spring-boot-devtools - org.springframework.boot spring-boot-starter-oauth2-resource-server - org.springframework.boot spring-boot-starter-oauth2-client - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - ${java.version} - ${java.version} - - + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + org.springframework.boot spring-boot-maven-plugin @@ -123,15 +120,6 @@ - - - - 6.0.2.Final - 0.7.2 - 9.19 - - - quotes-application @@ -177,7 +165,6 @@ - gateway-url-rewrite @@ -192,6 +179,16 @@ - + + + + + + 6.0.2.Final + 0.7.2 + 9.19 + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-kubernetes/pom.xml b/spring-cloud/spring-cloud-kubernetes/pom.xml index c41c500a1b..698bdce1e5 100644 --- a/spring-cloud/spring-cloud-kubernetes/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/pom.xml @@ -15,6 +15,15 @@ 1.0.0-SNAPSHOT + + kubernetes-minikube/demo-frontend + kubernetes-minikube/demo-backend + kubernetes-selfhealing/liveness-example + kubernetes-selfhealing/readiness-example + kubernetes-guide/client-service + kubernetes-guide/travel-agency-service + + @@ -27,15 +36,6 @@ - - kubernetes-minikube/demo-frontend - kubernetes-minikube/demo-backend - kubernetes-selfhealing/liveness-example - kubernetes-selfhealing/readiness-example - kubernetes-guide/client-service - kubernetes-guide/travel-agency-service - - 2021.0.0 diff --git a/spring-cloud/spring-cloud-load-balancer/pom.xml b/spring-cloud/spring-cloud-load-balancer/pom.xml index 65cf83de09..3b81def641 100644 --- a/spring-cloud/spring-cloud-load-balancer/pom.xml +++ b/spring-cloud/spring-cloud-load-balancer/pom.xml @@ -19,7 +19,7 @@ spring-cloud-loadbalancer-server spring-cloud-loadbalancer-client - + @@ -44,7 +44,7 @@ 2.6.1 2021.0.0 - 2.17.1 + 2.17.1 - + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-client/pom.xml b/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-client/pom.xml index fc6e2854aa..c141452695 100644 --- a/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-client/pom.xml +++ b/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-client/pom.xml @@ -3,17 +3,30 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + com.baeldung.springcloud.loadbalancer + spring-cloud-loadbalancer-client + 0.0.1-SNAPSHOT + spring-cloud-loadbalancer-client + Spring Cloud Load Balancer Demo - Client + com.baeldung.spring.cloud spring-cloud-loadbalancer 1.0.0-SNAPSHOT - com.baeldung.springcloud.loadbalancer - spring-cloud-loadbalancer-client - 0.0.1-SNAPSHOT - spring-cloud-loadbalancer-client - Spring Cloud Load Balancer Demo - Client + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + org.springframework.boot @@ -30,17 +43,6 @@ test - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - @@ -51,4 +53,4 @@ - + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-server/pom.xml b/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-server/pom.xml index 139996994d..3e61ecc90d 100644 --- a/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-server/pom.xml +++ b/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-server/pom.xml @@ -3,24 +3,23 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - com.baeldung.spring.cloud - spring-cloud-loadbalancer - 1.0.0-SNAPSHOT - - com.baeldung.spring.cloud.loadbalancer spring-cloud-loadbalancer-server 0.0.1-SNAPSHOT spring-cloud-loadbalancer-server Spring Cloud Load Balancer Demo - Server + + com.baeldung.spring.cloud + spring-cloud-loadbalancer + 1.0.0-SNAPSHOT + + org.springframework.boot spring-boot-starter-web - org.springframework.boot spring-boot-starter-test @@ -37,4 +36,4 @@ - + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-openfeign/README.md b/spring-cloud/spring-cloud-openfeign/README.md index 44f4d15b16..c1bd5ad43e 100644 --- a/spring-cloud/spring-cloud-openfeign/README.md +++ b/spring-cloud/spring-cloud-openfeign/README.md @@ -5,3 +5,4 @@ - [File Upload With Open Feign](https://www.baeldung.com/java-feign-file-upload) - [Feign Logging Configuration](https://www.baeldung.com/java-feign-logging) - [Provide an OAuth2 Token to a Feign Client](https://www.baeldung.com/spring-cloud-feign-oauth-token) +- [Retrieve Original Message From Feign ErrorDecoder](https://www.baeldung.com/feign-retrieve-original-message) diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml index b2cb66744b..3960cfde5d 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml @@ -52,7 +52,7 @@ test - + 2.17.1 diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml index 466291650c..c9bc120e4d 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml @@ -52,7 +52,7 @@ test - + 2.17.1 diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml index 27afc3eb69..76d899447f 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml @@ -60,8 +60,8 @@ test - - + + 2.17.1 diff --git a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/pom.xml b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/pom.xml index 4727859ea2..5df22c78c8 100644 --- a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/pom.xml +++ b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/pom.xml @@ -13,7 +13,7 @@ spring-cloud-zuul 0.0.1-SNAPSHOT - + diff --git a/spring-ejb/ejb-beans/pom.xml b/spring-ejb/ejb-beans/pom.xml index 6f20d949b0..37b67beec4 100644 --- a/spring-ejb/ejb-beans/pom.xml +++ b/spring-ejb/ejb-beans/pom.xml @@ -38,7 +38,6 @@ tomee-embedded ${tomee-embedded.version} - org.springframework spring-context diff --git a/spring-reactive/pom.xml b/spring-reactive/pom.xml index d31ee04d82..d755c03ae0 100644 --- a/spring-reactive/pom.xml +++ b/spring-reactive/pom.xml @@ -1,8 +1,9 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + spring-reactive com.baeldung @@ -11,8 +12,6 @@ ../parent-boot-2 - spring-reactive - org.springframework.boot diff --git a/spring-security-modules/spring-5-security-oauth/pom.xml b/spring-security-modules/spring-5-security-oauth/pom.xml index 706cdb3082..8449b01ec0 100644 --- a/spring-security-modules/spring-5-security-oauth/pom.xml +++ b/spring-security-modules/spring-5-security-oauth/pom.xml @@ -15,8 +15,8 @@ 0.0.1-SNAPSHOT ../../parent-boot-2 - - + + org.apache.logging.log4j @@ -27,7 +27,6 @@ - @@ -85,7 +84,7 @@ is available --> 2.5.2 com.baeldung.oauth2.SpringOAuthApplication - 2.17.1 + 2.17.1 \ No newline at end of file diff --git a/spring-security-modules/spring-security-legacy-oidc/pom.xml b/spring-security-modules/spring-security-legacy-oidc/pom.xml index 9dd898f9dd..e98486b0ff 100644 --- a/spring-security-modules/spring-security-legacy-oidc/pom.xml +++ b/spring-security-modules/spring-security-legacy-oidc/pom.xml @@ -14,8 +14,8 @@ 0.0.1-SNAPSHOT ../../parent-boot-2 - - + + org.apache.logging.log4j @@ -62,7 +62,7 @@ 1.0.9.RELEASE 0.3.0 2.4.7 - 2.17.1 + 2.17.1 \ No newline at end of file diff --git a/spring-security-modules/spring-security-web-boot-1/pom.xml b/spring-security-modules/spring-security-web-boot-1/pom.xml index 3f6001686d..18cdd0ae5c 100644 --- a/spring-security-modules/spring-security-web-boot-1/pom.xml +++ b/spring-security-modules/spring-security-web-boot-1/pom.xml @@ -179,7 +179,6 @@ - entryPoints diff --git a/spring-security-modules/spring-security-web-boot-3/README.md b/spring-security-modules/spring-security-web-boot-3/README.md index 2f98e0f4a0..400039dbfe 100644 --- a/spring-security-modules/spring-security-web-boot-3/README.md +++ b/spring-security-modules/spring-security-web-boot-3/README.md @@ -13,4 +13,5 @@ The "REST With Spring" Classes: http://github.learnspringsecurity.com - [Fixing 401s with CORS Preflights and Spring Security](https://www.baeldung.com/spring-security-cors-preflight) - [Content Security Policy with Spring Security](https://www.baeldung.com/spring-security-csp) - [Enable Logging for Spring Security](https://www.baeldung.com/spring-security-enable-logging) +- [Authentication With Spring Security and MongoDB](https://www.baeldung.com/spring-security-authentication-mongodb) - More articles: [[<-- prev]](/spring-security-modules/spring-security-web-boot-2) diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index d66d9cb35a..a5c23c1649 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -50,4 +50,4 @@ spring-web-url - + \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-basics-5/pom.xml b/spring-web-modules/spring-mvc-basics-5/pom.xml index 3b64f15c4b..5e8cd1b44e 100644 --- a/spring-web-modules/spring-mvc-basics-5/pom.xml +++ b/spring-web-modules/spring-mvc-basics-5/pom.xml @@ -41,7 +41,7 @@ - spring-mvc-basics + spring-mvc-basics-5 org.springframework.boot diff --git a/testing-modules/cucumber/pom.xml b/testing-modules/cucumber/pom.xml index 531b16ddec..ffa5c0d250 100644 --- a/testing-modules/cucumber/pom.xml +++ b/testing-modules/cucumber/pom.xml @@ -12,7 +12,6 @@ parent-boot-2 0.0.1-SNAPSHOT ../../parent-boot-2 - diff --git a/xml-2/.gitignore b/xml-2/.gitignore new file mode 100644 index 0000000000..68b918851c --- /dev/null +++ b/xml-2/.gitignore @@ -0,0 +1 @@ +xml/.idea diff --git a/xml-2/README.md b/xml-2/README.md new file mode 100644 index 0000000000..bc599f8480 --- /dev/null +++ b/xml-2/README.md @@ -0,0 +1,7 @@ +## XML + +This module contains articles about eXtensible Markup Language (XML) + +### Relevant Articles: + +- [Pretty-Print XML in Java](https://www.baeldung.com/java-pretty-print-xml) diff --git a/xml-2/pom.xml b/xml-2/pom.xml new file mode 100644 index 0000000000..025ad682ad --- /dev/null +++ b/xml-2/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + xml-2 + 0.1-SNAPSHOT + xml-2 + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + + org.dom4j + dom4j + ${dom4j.version} + + + + + xml-2 + + + src/main/resources + true + + + + + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + org.apache.maven.plugins + maven-surefire-plugin + + + + + + + 2.1.3 + + + \ No newline at end of file diff --git a/xml-2/src/main/java/com/baeldung/xml/prettyprint/XmlPrettyPrinter.java b/xml-2/src/main/java/com/baeldung/xml/prettyprint/XmlPrettyPrinter.java new file mode 100644 index 0000000000..85fd751325 --- /dev/null +++ b/xml-2/src/main/java/com/baeldung/xml/prettyprint/XmlPrettyPrinter.java @@ -0,0 +1,91 @@ +package com.baeldung.xml.prettyprint; + +import org.dom4j.DocumentHelper; +import org.dom4j.io.OutputFormat; +import org.dom4j.io.XMLWriter; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import java.io.*; + +public class XmlPrettyPrinter { + + public static String prettyPrintByTransformer(String xmlString, int indent, boolean ignoreDeclaration) { + + try { + final InputSource src = new InputSource(new StringReader(xmlString)); + final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src); + + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setAttribute("indent-number", indent); + Transformer transformer = transformerFactory.newTransformer(new StreamSource(new StringReader(readPrettyPrintXslt()))); + // Using the default transformer will create empty lines in Java9+ +// Transformer transformer = transformerFactory.newTransformer(); + transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, ignoreDeclaration ? "yes" : "no"); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + // Alternatively, we can set indent-size on the transformer object + // transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent)); + Writer out = new StringWriter(); + transformer.transform(new DOMSource(document), new StreamResult(out)); + return out.toString(); + } catch (Exception e) { + throw new RuntimeException("Error occurs when pretty-printing xml:\n" + xmlString, e); + } + } + + + public static String prettyPrintByDom4j(String xmlString, int indent, boolean skipDeclaration) { + try { + final OutputFormat format = OutputFormat.createPrettyPrint(); + format.setEncoding("UTF-8"); + format.setIndentSize(indent); + format.setSuppressDeclaration(skipDeclaration); + + final org.dom4j.Document document = DocumentHelper.parseText(xmlString); + final StringWriter sw = new StringWriter(); + final XMLWriter writer = new XMLWriter(sw, format); + writer.write(document); + return sw.toString(); + } catch (Exception e) { + throw new RuntimeException("Error occurs when pretty-printing xml:\n" + xmlString, e); + } + } + + public static void main(String[] args) throws IOException { + InputStream inputStream = XmlPrettyPrinter.class.getResourceAsStream("/xml/emails.xml"); + String xmlString = readFromInputStream(inputStream); + System.out.println("Pretty printing by Transformer"); + System.out.println("============================================="); + System.out.println(prettyPrintByTransformer(xmlString, 2, true)); + System.out.println("============================================="); + System.out.println("Pretty printing by Dom4j"); + System.out.println("============================================="); + System.out.println(prettyPrintByDom4j(xmlString, 8, false)); + System.out.println("============================================="); + } + + + private static String readPrettyPrintXslt() throws IOException { + InputStream inputStream = XmlPrettyPrinter.class.getResourceAsStream("/xml/prettyprint.xsl"); + return readFromInputStream(inputStream); + } + + private static String readFromInputStream(InputStream inputStream) throws IOException { + StringBuilder resultStringBuilder = new StringBuilder(); + try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { + String line; + while ((line = br.readLine()) != null) { + resultStringBuilder.append(line).append("\n"); + } + } + return resultStringBuilder.toString(); + } +} diff --git a/xml-2/src/main/resources/logback.xml b/xml-2/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/xml-2/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/xml-2/src/main/resources/xml/emails.xml b/xml-2/src/main/resources/xml/emails.xml new file mode 100644 index 0000000000..03338a28fc --- /dev/null +++ b/xml-2/src/main/resources/xml/emails.xml @@ -0,0 +1,4 @@ + Kai Amanda +I am flying to you +Jerry Tom Hey Tom, catch me if you can! + \ No newline at end of file diff --git a/xml-2/src/main/resources/xml/prettyprint.xsl b/xml-2/src/main/resources/xml/prettyprint.xsl new file mode 100644 index 0000000000..3941269f40 --- /dev/null +++ b/xml-2/src/main/resources/xml/prettyprint.xsl @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file