Merge branch 'eugenp:master' into master

This commit is contained in:
sebx59 2022-06-27 15:09:27 +02:00 committed by GitHub
commit 02e904b225
2868 changed files with 6351 additions and 4052 deletions

3
akka-modules/README.md Normal file
View File

@ -0,0 +1,3 @@
## Akka
This module contains modules about Akka.

View File

@ -8,7 +8,7 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<artifactId>akka-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

View File

@ -8,7 +8,7 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<artifactId>akka-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

33
akka-modules/pom.xml Normal file
View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>akka-modules</artifactId>
<name>akka-modules</name>
<packaging>pom</packaging>
<parent>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modules>
<module>akka-http</module>
<module>akka-streams</module>
<module>spring-akka</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -9,7 +9,7 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<artifactId>akka-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

View File

@ -4,6 +4,4 @@ This module contains articles about Apache CXF
## Relevant Articles:
- [Apache CXF Support for RESTful Web Services](https://www.baeldung.com/apache-cxf-rest-api)
- [A Guide to Apache CXF with Spring](https://www.baeldung.com/apache-cxf-with-spring)
- [Introduction to Apache CXF](https://www.baeldung.com/introduction-to-apache-cxf)
- [Introduction to Apache CXF Aegis Data Binding](https://www.baeldung.com/aegis-data-binding-in-apache-cxf)

View File

@ -1,2 +1,2 @@
### Relevant Articles:
- [Introduction to Apache CXF](http://www.baeldung.com/introduction-to-apache-cxf)
- [Introduction to Apache CXF](https://www.baeldung.com/introduction-to-apache-cxf)

View File

@ -19,7 +19,7 @@
<dependency>
<groupId>org.axonframework</groupId>
<artifactId>axon-bom</artifactId>
<version>${axon.version}</version>
<version>${axon-bom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -57,7 +57,7 @@
</dependencies>
<properties>
<axon.version>4.5.0</axon.version>
<axon-bom.version>4.5.13</axon-bom.version>
</properties>
</project>

View File

@ -10,10 +10,9 @@
<description>Demo project for CAS</description>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<groupId>com.baeldung.cas</groupId>
<artifactId>cas</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
</parent>
<dependencies>

View File

@ -88,7 +88,6 @@ public class CasSecuredApplication {
@Bean
public SingleSignOutFilter singleSignOutFilter() {
SingleSignOutFilter singleSignOutFilter = new SingleSignOutFilter();
singleSignOutFilter.setCasServerUrlPrefix("https://localhost:8443");
singleSignOutFilter.setLogoutCallbackPath("/exit/cas");
singleSignOutFilter.setIgnoreInitConfiguration(true);
return singleSignOutFilter;

22
cas/pom.xml Normal file
View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.cas</groupId>
<artifactId>cas</artifactId>
<name>cas</name>
<packaging>pom</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
</parent>
<modules>
<module>cas-secured-app</module>
</modules>
</project>

View File

@ -13,3 +13,4 @@ This module contains articles about Java 11 core features
- [Call Methods at Runtime Using Java Reflection](https://www.baeldung.com/java-method-reflection)
- [Java HttpClient Basic Authentication](https://www.baeldung.com/java-httpclient-basic-auth)
- [Java HttpClient With SSL](https://www.baeldung.com/java-httpclient-ssl)
- [Adding Parameters to Java HttpClient Requests](https://www.baeldung.com/java-httpclient-request-parameters)

View File

@ -0,0 +1,45 @@
package com.baeldung.httpclient.parameters;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class HttpClientParametersLiveTest {
private static HttpClient client;
@BeforeAll
public static void setUp() {
client = HttpClient.newHttpClient();
}
@Test
public void givenQueryParams_whenGetRequest_thenResponseOk() throws IOException, InterruptedException {
HttpRequest request = HttpRequest.newBuilder()
.version(HttpClient.Version.HTTP_2)
.uri(URI.create("https://postman-echo.com/get?param1=value1&param2=value2"))
.GET()
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assertEquals(response.statusCode(), 200);
}
@Test
public void givenQueryParams_whenGetRequestWithDefaultConfiguration_thenResponseOk() throws IOException, InterruptedException {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://postman-echo.com/get?param1=value1&param2=value2"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assertEquals(response.statusCode(), 200);
}
}

View File

@ -21,7 +21,7 @@ public class HttpClientSSLBypassUnitTest {
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://www.testingmcafeesites.com/"))
.uri(URI.create("https://wrong.host.badssl.com/"))
.build();
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

View File

@ -12,3 +12,4 @@ This module contains articles about Java 9 core features
- [Easy Ways to Write a Java InputStream to an OutputStream](https://www.baeldung.com/java-inputstream-to-outputstream)
- [Private Methods in Java Interfaces](https://www.baeldung.com/java-interface-private-methods)
- [Java Scanner useDelimiter with Examples](https://www.baeldung.com/java-scanner-usedelimiter)
- [Is There a Destructor in Java?](https://www.baeldung.com/java-destructor)

View File

@ -0,0 +1,17 @@
package com.bealdung.java9.finalizers;
import java.lang.ref.Cleaner;
class CleaningDemo {
public static void main(String[] args) {
final Cleaner cleaner = Cleaner.create();
try (Order order = new Order(cleaner)) {
for (int i = 0; i < 10; i++) {
order.register(new Product(i), i);
}
} catch (Exception e) {
System.err.println("Error: " + e);
}
}
}

View File

@ -0,0 +1,36 @@
package com.bealdung.java9.finalizers;
import java.lang.ref.Cleaner;
class Order implements AutoCloseable {
private final Cleaner cleaner;
private Cleaner.Cleanable cleanable;
public Order(Cleaner cleaner) {
this.cleaner = cleaner;
}
public void register(Product product, int id) {
this.cleanable = cleaner.register(product, new CleaningAction(id));
}
public void close() {
cleanable.clean();
System.out.println("Cleanable closed");
}
static class CleaningAction implements Runnable {
private final int id;
public CleaningAction(int id) {
this.id = id;
}
@Override
public void run() {
System.out.printf("Object with id %s is garbage collected. %n", id);
}
}
}

View File

@ -0,0 +1,13 @@
package com.bealdung.java9.finalizers;
class Product {
private final int id;
public Product(int id) {
this.id = id;
}
public int getId() {
return id;
}
}

View File

@ -0,0 +1,25 @@
package com.bealdung.java9.finalizers;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
class Resource implements AutoCloseable {
final BufferedReader reader;
public Resource(String filename) throws FileNotFoundException {
reader = new BufferedReader(new FileReader(filename));
}
public long getLineNumber() {
return reader.lines()
.count();
}
@Override
public void close() throws Exception {
reader.close();
System.out.println("BufferedReader resource closed");
}
}

View File

@ -0,0 +1,30 @@
package com.bealdung.java9.finalizers;
import org.junit.jupiter.api.Test;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals;
class FinalizeUnitTest {
@Test
void givenFilename_whenGetLineNumber_thenReturnCorrectNumber() throws IOException {
final File tmpFile = File.createTempFile("test", ".tmp");
final BufferedWriter writer = new BufferedWriter(new FileWriter(tmpFile));
writer.write("Baeldung");
writer.close();
long lineNumber = 0;
try (Resource resource = new Resource(tmpFile.getAbsolutePath())) {
lineNumber = resource.getLineNumber();
} catch (Exception e) {
System.err.println("Error " + e);
}
assertEquals(1, lineNumber);
}
}

View File

@ -32,7 +32,7 @@ public class EmptyMapInitializer {
return emptyMap;
}
public Map createGenericEmptyMapUsingMapsObject() {
public Map createGenericEmptyMapUsingGuavaMapsObject() {
Map genericEmptyMap = Maps.<String, Integer>newHashMap();
return genericEmptyMap;
}
@ -43,6 +43,11 @@ public class EmptyMapInitializer {
return emptyMapUsingGuava;
}
public static Map<String, String> createImmutableMapUsingGuava() {
Map<String, String> emptyImmutableMapUsingGuava = ImmutableMap.of();
return emptyImmutableMapUsingGuava;
}
public SortedMap<String, String> createEmptySortedMap() {
SortedMap<String, String> sortedMap = Collections.emptySortedMap();
return sortedMap;

View File

@ -28,4 +28,9 @@ public class EmptyMapInitializerUnitTest {
assertFalse(emptyMapUsingGuava.isEmpty());
}
@Test(expected=UnsupportedOperationException.class)
public void givenImmutableEmptyMapUsingGuava_whenAddingEntries_throwsException() {
Map<String, String> map = EmptyMapInitializer.createImmutableMapUsingGuava();
map.put("key", "value");
}
}

View File

@ -9,4 +9,4 @@ This module contains articles about conversions among Collection types and array
- [Converting List to Map With a Custom Supplier](https://www.baeldung.com/list-to-map-supplier)
- [Arrays.asList vs new ArrayList(Arrays.asList())](https://www.baeldung.com/java-arrays-aslist-vs-new-arraylist)
- [Iterate Over a Set in Java](https://www.baeldung.com/java-iterate-set)
- More articles: [[<-- prev]](../java-collections-conversions)
- More articles: [[<-- prev]](../core-java-collections-conversions)

View File

@ -3,9 +3,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>java-collections-conversions-2</artifactId>
<artifactId>core-java-collections-conversions-2</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>java-collections-conversions-2</name>
<name>core-java-collections-conversions-2</name>
<packaging>jar</packaging>
<parent>
@ -33,7 +33,7 @@
</dependencies>
<build>
<finalName>java-collections-conversions-2</finalName>
<finalName>core-java-collections-conversions-2</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>

View File

@ -12,4 +12,4 @@ This module contains articles about conversions among Collection types and array
- [Java 8 Collectors toMap](https://www.baeldung.com/java-collectors-tomap)
- [Converting Iterable to Collection in Java](https://www.baeldung.com/java-iterable-to-collection)
- [Converting Iterator to List](https://www.baeldung.com/java-convert-iterator-to-list)
- More articles: [[next -->]](../java-collections-conversions-2)
- More articles: [[next -->]](../core-java-collections-conversions-2)

View File

@ -3,9 +3,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>java-collections-conversions</artifactId>
<artifactId>core-java-collections-conversions</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>java-collections-conversions</name>
<name>core-java-collections-conversions</name>
<packaging>jar</packaging>
<parent>
@ -28,7 +28,7 @@
</dependencies>
<build>
<finalName>java-collections-conversions</finalName>
<finalName>core-java-collections-conversions</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>

View File

@ -13,5 +13,4 @@ This module contains articles about the Java List collection
- [Finding the Differences Between Two Lists in Java](https://www.baeldung.com/java-lists-difference)
- [List vs. ArrayList in Java](https://www.baeldung.com/java-list-vs-arraylist)
- [How to Store HashMap<String, ArrayList> Inside a List](https://www.baeldung.com/java-hashmap-inside-list)
- [Working With a List of Lists in Java](https://www.baeldung.com/java-list-of-lists)
- [[<-- Prev]](/core-java-modules/core-java-collections-list-2)

View File

@ -8,3 +8,4 @@
- [Java Map keySet() vs. entrySet() vs. values() Methods](https://www.baeldung.com/java-map-entries-methods)
- [Java IdentityHashMap Class and Its Use Cases](https://www.baeldung.com/java-identityhashmap)
- [How to Invert a Map in Java](https://www.baeldung.com/java-invert-map)
- More articles: [[<-- prev]](../core-java-collections-maps-4)

View File

@ -3,9 +3,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>java-collections-maps-3</artifactId>
<artifactId>core-java-collections-maps-5</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>java-collections-maps-3</name>
<name>core-java-collections-maps-5</name>
<packaging>jar</packaging>
<parent>

View File

@ -12,4 +12,5 @@ This module contains articles about date operations in Java.
- [Finding Leap Years in Java](https://www.baeldung.com/java-leap-year)
- [Getting the Week Number From Any Date](https://www.baeldung.com/java-get-week-number)
- [Subtract Days from a Date in Java](https://www.baeldung.com/java-subtract-days-from-date)
- [How to Calculate “Time Ago” in Java](https://www.baeldung.com/java-calculate-time-ago)
- [[<-- Prev]](/core-java-modules/core-java-date-operations-1)

View File

@ -30,11 +30,29 @@
<artifactId>hirondelle-date4j</artifactId>
<version>${hirondelle-date4j.version}</version>
</dependency>
<dependency>
<groupId>net.time4j</groupId>
<artifactId>time4j-base</artifactId>
<version>${time4j-base.version}</version>
</dependency>
<dependency>
<groupId>net.time4j</groupId>
<artifactId>time4j-sqlxml</artifactId>
<version>${time4j-sqlxml.version}</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.prettytime</groupId>
<artifactId>prettytime</artifactId>
<version>${prettytime.version}</version>
</dependency>
</dependencies>
<properties>
<joda-time.version>2.10</joda-time.version>
<hirondelle-date4j.version>1.5.1</hirondelle-date4j.version>
<prettytime.version>3.2.7.Final</prettytime.version>
<time4j-base.version>5.9</time4j-base.version>
<time4j-sqlxml.version>5.8</time4j-sqlxml.version>
</properties>
</project>

View File

@ -0,0 +1,94 @@
package com.baeldung.timeago.version7;
import java.util.Date;
import java.util.TimeZone;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Period;
import org.joda.time.format.PeriodFormat;
import org.joda.time.format.PeriodFormatter;
import org.joda.time.format.PeriodFormatterBuilder;
public class TimeAgoCalculator {
public static String calculateTimeAgoByTimeGranularity(Date pastTime, TimeGranularity granularity) {
Date currentTime = new Date();
long timeDifferenceInMillis = currentTime.getTime() - pastTime.getTime();
return timeDifferenceInMillis / granularity.toMillis() + " " + granularity.name()
.toLowerCase() + " ago";
}
public static String calculateHumanFriendlyTimeAgo(Date pastTime) {
Date currentTime = new Date();
long timeDifferenceInMillis = currentTime.getTime() - pastTime.getTime();
if (timeDifferenceInMillis / TimeGranularity.DECADES.toMillis() > 0)
return "several decades ago";
else if (timeDifferenceInMillis / TimeGranularity.YEARS.toMillis() > 0)
return "several years ago";
else if (timeDifferenceInMillis / TimeGranularity.MONTHS.toMillis() > 0)
return "several months ago";
else if (timeDifferenceInMillis / TimeGranularity.WEEKS.toMillis() > 0)
return "several weeks ago";
else if (timeDifferenceInMillis / TimeGranularity.DAYS.toMillis() > 0)
return "several days ago";
else if (timeDifferenceInMillis / TimeGranularity.HOURS.toMillis() > 0)
return "several hours ago";
else if (timeDifferenceInMillis / TimeGranularity.MINUTES.toMillis() > 0)
return "several minutes ago";
else
return "moments ago";
}
public static String calculateExactTimeAgoWithJodaTime(Date pastTime) {
Period period = new Period(new DateTime(pastTime.getTime()), new DateTime());
PeriodFormatter formatter = new PeriodFormatterBuilder().appendYears()
.appendSuffix(" year ", " years ")
.appendSeparator("and ")
.appendMonths()
.appendSuffix(" month ", " months ")
.appendSeparator("and ")
.appendWeeks()
.appendSuffix(" week ", " weeks ")
.appendSeparator("and ")
.appendDays()
.appendSuffix(" day ", " days ")
.appendSeparator("and ")
.appendHours()
.appendSuffix(" hour ", " hours ")
.appendSeparator("and ")
.appendMinutes()
.appendSuffix(" minute ", " minutes ")
.appendSeparator("and ")
.appendSeconds()
.appendSuffix(" second", " seconds")
.toFormatter();
return formatter.print(period);
}
public static String calculateHumanFriendlyTimeAgoWithJodaTime(Date pastTime) {
Period period = new Period(new DateTime(pastTime.getTime()), new DateTime());
if (period.getYears() != 0)
return "several years ago";
else if (period.getMonths() != 0)
return "several months ago";
else if (period.getWeeks() != 0)
return "several weeks ago";
else if (period.getDays() != 0)
return "several days ago";
else if (period.getHours() != 0)
return "several hours ago";
else if (period.getMinutes() != 0)
return "several minutes ago";
else
return "moments ago";
}
public static String calculateZonedTimeAgoWithJodaTime(Date pastTime, TimeZone zone) {
DateTimeZone dateTimeZone = DateTimeZone.forID(zone.getID());
Period period = new Period(new DateTime(pastTime.getTime(), dateTimeZone), new DateTime(dateTimeZone));
return PeriodFormat.getDefault()
.print(period);
}
}

Some files were not shown because too many files have changed in this diff Show More