diff --git a/core-java-modules/core-java-networking-2/README.md b/core-java-modules/core-java-networking-2/README.md index 5cbb4894fb0c..6c1362b15845 100644 --- a/core-java-modules/core-java-networking-2/README.md +++ b/core-java-modules/core-java-networking-2/README.md @@ -7,11 +7,9 @@ This module contains articles about networking in Java - [Checking if a URL Exists in Java](https://www.baeldung.com/java-check-url-exists) - [Making a JSON POST Request With HttpURLConnection](https://www.baeldung.com/httpurlconnection-post) - [Using Curl in Java](https://www.baeldung.com/java-curl) -- [Do a Simple HTTP Request in Java](https://www.baeldung.com/java-http-request) -- [Sending Emails with Java](https://www.baeldung.com/java-email) - [Authentication with HttpUrlConnection](https://www.baeldung.com/java-http-url-connection) -- [Download a File From an URL in Java](https://www.baeldung.com/java-download-file) - [Handling java.net.ConnectException](https://www.baeldung.com/java-net-connectexception) - [Getting MAC Addresses in Java](https://www.baeldung.com/java-mac-address) - [Sending Emails with Attachments in Java](https://www.baeldung.com/java-send-emails-attachments) +- [Connecting Through Proxy Servers in Core Java](https://www.baeldung.com/java-connect-via-proxy-server) - [[<-- Prev]](/core-java-modules/core-java-networking) [[Next --> ]](/core-java-modules/core-java-networking-3) diff --git a/core-java-modules/core-java-networking-2/pom.xml b/core-java-modules/core-java-networking-2/pom.xml index effa9cf770de..058e15a3405b 100644 --- a/core-java-modules/core-java-networking-2/pom.xml +++ b/core-java-modules/core-java-networking-2/pom.xml @@ -29,27 +29,12 @@ angus-mail ${angus.mail.version} - - org.asynchttpclient - async-http-client - ${async-http-client.version} - - - jakarta.xml.bind - jakarta.xml.bind-api - ${jakarta.bind.version} - com.icegreen greenmail ${greenmail.version} test - - org.apache.httpcomponents.client5 - httpclient5 - ${apache.httpclient.version} - @@ -57,10 +42,7 @@ - 5.3.1 2.0.1 - 2.4.5 - 2.3.3 2.0.0-alpha-3 1.16.0 diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java similarity index 100% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java rename to core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java similarity index 79% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java rename to core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java index 6bb3d612ea80..d5d6a92bc1b7 100644 --- a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java +++ b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java @@ -1,7 +1,11 @@ package com.baeldung.networking.proxies; import java.io.IOException; -import java.net.*; +import java.net.HttpURLConnection; +import java.net.Proxy; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; public class DirectProxyDemo { diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java similarity index 85% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java rename to core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java index 4b53e89fdddf..afce37b266b8 100644 --- a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java +++ b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java @@ -1,7 +1,11 @@ package com.baeldung.networking.proxies; -import java.io.IOException; -import java.net.*; +import java.net.HttpURLConnection; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.net.Socket; +import java.net.URI; +import java.net.URL; public class SocksProxyDemo { diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java similarity index 100% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java rename to core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java similarity index 100% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java rename to core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java similarity index 80% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java rename to core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java index 333e3b3fb059..cffa3a160f69 100644 --- a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java +++ b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java @@ -1,7 +1,10 @@ package com.baeldung.networking.proxies; -import java.io.IOException; -import java.net.*; +import java.net.HttpURLConnection; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.net.URI; +import java.net.URL; public class WebProxyDemo { diff --git a/core-java-modules/core-java-networking-3/README.md b/core-java-modules/core-java-networking-3/README.md index 8830ee8daced..ffe9c8d60e2a 100644 --- a/core-java-modules/core-java-networking-3/README.md +++ b/core-java-modules/core-java-networking-3/README.md @@ -6,7 +6,6 @@ This module contains articles about networking in Java - [Finding a Free Port in Java](https://www.baeldung.com/java-free-port) - [Downloading Email Attachments in Java](https://www.baeldung.com/java-download-email-attachments) -- [Connection Timeout vs. Read Timeout for Java Sockets](https://www.baeldung.com/java-socket-connection-read-timeout) - [Find Whether an IP Address Is in the Specified Range or Not in Java](https://www.baeldung.com/java-check-ip-address-range) - [Find the IP Address of a Client Connected to a Server](https://www.baeldung.com/java-client-get-ip-address) - [Unix Domain Socket in Java 16](https://www.baeldung.com/java-unix-domain-socket) diff --git a/core-java-modules/core-java-networking-4/README.md b/core-java-modules/core-java-networking-4/README.md index 13b82f6c1022..578bf6238f94 100644 --- a/core-java-modules/core-java-networking-4/README.md +++ b/core-java-modules/core-java-networking-4/README.md @@ -4,7 +4,6 @@ - [Validating IPv4 Address in Java](https://www.baeldung.com/java-validate-ipv4-address) - [Download a Webpage in Java](https://www.baeldung.com/java-download-webpage) - [URL Query Manipulation in Java](https://www.baeldung.com/java-url-query-manipulation) -- [Understanding the java.net.SocketException Broken Pipe Error](https://www.baeldung.com/java-socketexception-broken-pipe-error) - [Normalize a URL in Java](https://www.baeldung.com/java-url-normalization) - [Translating Space Characters in URLEncoder](https://www.baeldung.com/java-urlencoder-translate-space-characters) - [Creating a Custom URL Connection](https://www.baeldung.com/java-custom-url-connection) diff --git a/core-java-modules/core-java-networking-5/README.md b/core-java-modules/core-java-networking-5/README.md index 2dbb37e72916..85457e6fccae 100644 --- a/core-java-modules/core-java-networking-5/README.md +++ b/core-java-modules/core-java-networking-5/README.md @@ -2,4 +2,10 @@ - [Finding the Redirected URL of a URL in Java](https://www.baeldung.com/java-find-redirected-url) - [How to Read Text Inside Mail Body](https://www.baeldung.com/java-read-text-inside-mail-body) - [Finding the Size of a Web File Using URLConnection in Java](https://www.baeldung.com/java-urlconnection-web-file-size) +- [Broadcasting and Multicasting in Java](http://www.baeldung.com/java-broadcast-multicast) +- [A Guide to UDP In Java](https://www.baeldung.com/udp-in-java) +- [Difference Between URL and URI](https://www.baeldung.com/java-url-vs-uri) +- [A Guide to HTTP Cookies in Java](https://www.baeldung.com/cookies-java) +- [Working with Network Interfaces in Java](http://www.baeldung.com/java-network-interfaces) +- [Read an InputStream using the Java Server Socket](https://www.baeldung.com/java-inputstream-server-socket) - [[<-- Prev]](/core-java-modules/core-java-networking-4) diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/cookies/PersistentCookieStore.java b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/cookies/PersistentCookieStore.java similarity index 91% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/cookies/PersistentCookieStore.java rename to core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/cookies/PersistentCookieStore.java index 4f34972b1eb8..48e3717551b2 100644 --- a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/cookies/PersistentCookieStore.java +++ b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/cookies/PersistentCookieStore.java @@ -1,6 +1,9 @@ package com.baeldung.networking.cookies; -import java.net.*; +import java.net.CookieManager; +import java.net.CookieStore; +import java.net.HttpCookie; +import java.net.URI; import java.util.List; public class PersistentCookieStore implements CookieStore, Runnable { diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java similarity index 82% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java rename to core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java index 9fbbee8501ab..bd2090e7a592 100644 --- a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java +++ b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java @@ -1,6 +1,10 @@ package com.baeldung.networking.cookies; -import java.net.*; +import java.net.CookiePolicy; +import java.net.HttpCookie; +import java.net.InetAddress; +import java.net.URI; +import java.net.UnknownHostException; public class ProxyAcceptCookiePolicy implements CookiePolicy { String acceptedProxy; diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/EchoClient.java b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/udp/EchoClient.java similarity index 100% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/EchoClient.java rename to core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/udp/EchoClient.java diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/EchoServer.java b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/udp/EchoServer.java similarity index 100% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/EchoServer.java rename to core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/udp/EchoServer.java diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingClient.java b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingClient.java similarity index 100% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingClient.java rename to core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingClient.java diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingEchoServer.java b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingEchoServer.java similarity index 100% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingEchoServer.java rename to core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/udp/broadcast/BroadcastingEchoServer.java diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/multicast/MulticastEchoServer.java b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/udp/multicast/MulticastEchoServer.java similarity index 100% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/multicast/MulticastEchoServer.java rename to core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/udp/multicast/MulticastEchoServer.java diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/multicast/MulticastingClient.java b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/udp/multicast/MulticastingClient.java similarity index 100% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/udp/multicast/MulticastingClient.java rename to core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/udp/multicast/MulticastingClient.java diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/uriurl/URIDemo.java b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/uriurl/URIDemo.java similarity index 99% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/uriurl/URIDemo.java rename to core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/uriurl/URIDemo.java index 91f6e212935c..e48ba314fc03 100644 --- a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/uriurl/URIDemo.java +++ b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/uriurl/URIDemo.java @@ -1,7 +1,6 @@ package com.baeldung.networking.uriurl; import java.io.BufferedReader; -import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/uriurl/URLDemo.java b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/uriurl/URLDemo.java similarity index 94% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/uriurl/URLDemo.java rename to core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/uriurl/URLDemo.java index 3682a1b1bb77..d302451fa323 100644 --- a/core-java-modules/core-java-networking/src/main/java/com/baeldung/networking/uriurl/URLDemo.java +++ b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/networking/uriurl/URLDemo.java @@ -3,7 +3,11 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.net.*; +import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLConnection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/read/Client.java b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/socket/read/Client.java similarity index 88% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/read/Client.java rename to core-java-modules/core-java-networking-5/src/main/java/com/baeldung/socket/read/Client.java index 5e2a84a76723..f115c4da8d62 100644 --- a/core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/read/Client.java +++ b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/socket/read/Client.java @@ -1,8 +1,10 @@ package com.baeldung.socket.read; -import java.net.*; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.Socket; import java.nio.charset.StandardCharsets; -import java.io.*; public class Client { diff --git a/core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/read/Server.java b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/socket/read/Server.java similarity index 94% rename from core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/read/Server.java rename to core-java-modules/core-java-networking-5/src/main/java/com/baeldung/socket/read/Server.java index 2ab91c6cdc38..a9d799b1672e 100644 --- a/core-java-modules/core-java-networking/src/main/java/com/baeldung/socket/read/Server.java +++ b/core-java-modules/core-java-networking-5/src/main/java/com/baeldung/socket/read/Server.java @@ -1,8 +1,10 @@ package com.baeldung.socket.read; -import java.net.*; +import java.io.BufferedInputStream; +import java.io.DataInputStream; +import java.net.ServerSocket; +import java.net.Socket; import java.nio.charset.StandardCharsets; -import java.io.*; public class Server { diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/interfaces/NetworkInterfaceManualTest.java b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/interfaces/NetworkInterfaceManualTest.java similarity index 92% rename from core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/interfaces/NetworkInterfaceManualTest.java rename to core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/interfaces/NetworkInterfaceManualTest.java index 47a598f5994c..42f5498c2a5b 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/interfaces/NetworkInterfaceManualTest.java +++ b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/interfaces/NetworkInterfaceManualTest.java @@ -1,12 +1,20 @@ package com.baeldung.networking.interfaces; -import org.junit.Test; - -import java.net.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.net.InetAddress; +import java.net.InterfaceAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; import java.util.Enumeration; import java.util.List; -import static org.junit.Assert.*; +import org.junit.Test; public class NetworkInterfaceManualTest { @Test diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/UDPLiveTest.java b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/udp/UDPLiveTest.java similarity index 100% rename from core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/UDPLiveTest.java rename to core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/udp/UDPLiveTest.java index 7337be6e3d63..4892ffa28159 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/UDPLiveTest.java +++ b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/udp/UDPLiveTest.java @@ -1,13 +1,13 @@ package com.baeldung.networking.udp; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; public class UDPLiveTest { private EchoClient client; diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/broadcast/BroadcastLiveTest.java b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/udp/broadcast/BroadcastLiveTest.java similarity index 100% rename from core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/broadcast/BroadcastLiveTest.java rename to core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/udp/broadcast/BroadcastLiveTest.java index 51e5bfc6697f..48d4f921475e 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/broadcast/BroadcastLiveTest.java +++ b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/udp/broadcast/BroadcastLiveTest.java @@ -1,11 +1,11 @@ package com.baeldung.networking.udp.broadcast; -import org.junit.After; -import org.junit.Test; +import static org.junit.Assert.assertEquals; import java.io.IOException; -import static org.junit.Assert.assertEquals; +import org.junit.After; +import org.junit.Test; public class BroadcastLiveTest { private BroadcastingClient client; diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/multicast/MulticastLiveTest.java b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/udp/multicast/MulticastLiveTest.java similarity index 100% rename from core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/multicast/MulticastLiveTest.java rename to core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/udp/multicast/MulticastLiveTest.java index 83d0482f4427..78c58d18c49a 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/udp/multicast/MulticastLiveTest.java +++ b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/udp/multicast/MulticastLiveTest.java @@ -1,11 +1,11 @@ package com.baeldung.networking.udp.multicast; -import org.junit.After; -import org.junit.Test; +import static org.junit.Assert.assertEquals; import java.io.IOException; -import static org.junit.Assert.assertEquals; +import org.junit.After; +import org.junit.Test; public class MulticastLiveTest { private MulticastingClient client; diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URIDemoLiveTest.java b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/uriurl/URIDemoLiveTest.java similarity index 89% rename from core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URIDemoLiveTest.java rename to core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/uriurl/URIDemoLiveTest.java index 3b73cc094337..fbda53cfdabf 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URIDemoLiveTest.java +++ b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/uriurl/URIDemoLiveTest.java @@ -2,17 +2,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.net.URLConnection; import org.junit.BeforeClass; import org.junit.FixMethodOrder; @@ -20,8 +14,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.baeldung.networking.uriurl.URLDemo; - @FixMethodOrder public class URIDemoLiveTest { private final Logger log = LoggerFactory.getLogger(URIDemoLiveTest.class); diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URIvsURLUnitTest.java b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/uriurl/URIvsURLUnitTest.java similarity index 96% rename from core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URIvsURLUnitTest.java rename to core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/uriurl/URIvsURLUnitTest.java index ce78ecc03712..919852eafdd1 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URIvsURLUnitTest.java +++ b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/uriurl/URIvsURLUnitTest.java @@ -1,12 +1,15 @@ package com.baeldung.networking.uriurl; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; + import org.apache.commons.io.IOUtils; -import static org.junit.Assert.*; import org.junit.Test; public class URIvsURLUnitTest { diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URLDemoLiveTest.java b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/uriurl/URLDemoLiveTest.java similarity index 97% rename from core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URLDemoLiveTest.java rename to core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/uriurl/URLDemoLiveTest.java index 69c9abcf9c16..b18e125b8b1c 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/networking/uriurl/URLDemoLiveTest.java +++ b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/networking/uriurl/URLDemoLiveTest.java @@ -7,7 +7,10 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.net.*; +import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URL; +import java.net.URLConnection; import org.junit.BeforeClass; import org.junit.FixMethodOrder; @@ -15,8 +18,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.baeldung.networking.uriurl.URLDemo; - @FixMethodOrder public class URLDemoLiveTest { private final Logger log = LoggerFactory.getLogger(URLDemoLiveTest.class); diff --git a/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/read/SocketReadAllDataLiveTest.java b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/socket/read/SocketReadAllDataLiveTest.java similarity index 99% rename from core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/read/SocketReadAllDataLiveTest.java rename to core-java-modules/core-java-networking-5/src/test/java/com/baeldung/socket/read/SocketReadAllDataLiveTest.java index da7f5b8d3f8f..ab0676737f42 100644 --- a/core-java-modules/core-java-networking/src/test/java/com/baeldung/socket/read/SocketReadAllDataLiveTest.java +++ b/core-java-modules/core-java-networking-5/src/test/java/com/baeldung/socket/read/SocketReadAllDataLiveTest.java @@ -1,6 +1,7 @@ package com.baeldung.socket.read; import java.util.concurrent.TimeUnit; + import org.junit.jupiter.api.Test; public class SocketReadAllDataLiveTest { diff --git a/core-java-modules/core-java-networking/README.md b/core-java-modules/core-java-networking/README.md index 893efa4c55b2..e8a9e5a04c05 100644 --- a/core-java-modules/core-java-networking/README.md +++ b/core-java-modules/core-java-networking/README.md @@ -4,14 +4,12 @@ This module contains articles about networking in Java ### Relevant Articles -- [Connecting Through Proxy Servers in Core Java](https://www.baeldung.com/java-connect-via-proxy-server) -- [Broadcasting and Multicasting in Java](http://www.baeldung.com/java-broadcast-multicast) -- [A Guide to UDP In Java](https://www.baeldung.com/udp-in-java) -- [A Guide to HTTP Cookies in Java](https://www.baeldung.com/cookies-java) - [A Guide to the Java URL](http://www.baeldung.com/java-url) -- [Working with Network Interfaces in Java](http://www.baeldung.com/java-network-interfaces) - [A Guide to Java Sockets](http://www.baeldung.com/a-guide-to-java-sockets) - [Guide to Java URL Encoding/Decoding](http://www.baeldung.com/java-url-encoding-decoding) -- [Difference Between URL and URI](https://www.baeldung.com/java-url-vs-uri) -- [Read an InputStream using the Java Server Socket](https://www.baeldung.com/java-inputstream-server-socket) +- [Sending Emails with Java](https://www.baeldung.com/java-email) +- [Download a File From an URL in Java](https://www.baeldung.com/java-download-file) +- [Do a Simple HTTP Request in Java](https://www.baeldung.com/java-http-request) +- [Understanding the java.net.SocketException Broken Pipe Error](https://www.baeldung.com/java-socketexception-broken-pipe-error) +- [Connection Timeout vs. Read Timeout for Java Sockets](https://www.baeldung.com/java-socket-connection-read-timeout) - [[More -->]](/core-java-modules/core-java-networking-2) diff --git a/core-java-modules/core-java-networking/pom.xml b/core-java-modules/core-java-networking/pom.xml index 2028d9b2189b..8b38c8771653 100644 --- a/core-java-modules/core-java-networking/pom.xml +++ b/core-java-modules/core-java-networking/pom.xml @@ -24,6 +24,31 @@ httpclient ${apache.httpclient.version} + + com.icegreen + greenmail + ${greenmail.version} + + + org.apache.httpcomponents.client5 + httpclient5 + ${apache.httpclient5.version} + + + org.asynchttpclient + async-http-client + ${async-http-client.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + jakarta.xml.bind + jakarta.xml.bind-api + ${jakarta.bind.version} + @@ -33,6 +58,10 @@ 4.3.4.RELEASE 4.5.14 + 2.0.0-alpha-3 + 5.3.1 + 2.4.5 + 2.3.3 \ No newline at end of file diff --git a/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/download/FileDownload.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/download/FileDownload.java similarity index 92% rename from core-java-modules/core-java-networking-2/src/main/java/com/baeldung/download/FileDownload.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/download/FileDownload.java index 9426f6a1b71a..7d4662773d0e 100644 --- a/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/download/FileDownload.java +++ b/core-java-modules/core-java-networking/src/main/java/com/baeldung/download/FileDownload.java @@ -1,14 +1,10 @@ package com.baeldung.download; -import org.apache.commons.io.FileUtils; -import org.apache.hc.client5.http.classic.methods.HttpGet; -import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.impl.classic.HttpClients; -import org.apache.hc.core5.http.HttpEntity; -import org.apache.hc.core5.http.io.entity.EntityUtils; -import org.asynchttpclient.*; - -import java.io.*; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -20,6 +16,18 @@ import java.nio.file.StandardCopyOption; import java.util.concurrent.ExecutionException; +import org.apache.commons.io.FileUtils; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.asynchttpclient.AsyncCompletionHandler; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.Dsl; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.Response; + public class FileDownload { public static void downloadWithJavaIO(String url, String localFilename) { diff --git a/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/download/ResumableDownload.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/download/ResumableDownload.java similarity index 89% rename from core-java-modules/core-java-networking-2/src/main/java/com/baeldung/download/ResumableDownload.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/download/ResumableDownload.java index 55ff485e40c9..d8fba52b18a4 100644 --- a/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/download/ResumableDownload.java +++ b/core-java-modules/core-java-networking/src/main/java/com/baeldung/download/ResumableDownload.java @@ -1,7 +1,15 @@ package com.baeldung.download; -import java.io.*; -import java.net.*; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.ProtocolException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URLConnection; public class ResumableDownload { diff --git a/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/httprequest/FullResponseBuilder.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/httprequest/FullResponseBuilder.java similarity index 100% rename from core-java-modules/core-java-networking-2/src/main/java/com/baeldung/httprequest/FullResponseBuilder.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/httprequest/FullResponseBuilder.java diff --git a/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/httprequest/ParameterStringBuilder.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/httprequest/ParameterStringBuilder.java similarity index 100% rename from core-java-modules/core-java-networking-2/src/main/java/com/baeldung/httprequest/ParameterStringBuilder.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/httprequest/ParameterStringBuilder.java diff --git a/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/mail/EmailService.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/mail/EmailService.java similarity index 100% rename from core-java-modules/core-java-networking-2/src/main/java/com/baeldung/mail/EmailService.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/mail/EmailService.java diff --git a/core-java-modules/core-java-networking-4/src/main/java/com/baeldung/socketexception/brokenpipe/Client.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/socketexception/brokenpipe/Client.java similarity index 100% rename from core-java-modules/core-java-networking-4/src/main/java/com/baeldung/socketexception/brokenpipe/Client.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/socketexception/brokenpipe/Client.java diff --git a/core-java-modules/core-java-networking-4/src/main/java/com/baeldung/socketexception/brokenpipe/Server.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/socketexception/brokenpipe/Server.java similarity index 100% rename from core-java-modules/core-java-networking-4/src/main/java/com/baeldung/socketexception/brokenpipe/Server.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/socketexception/brokenpipe/Server.java diff --git a/core-java-modules/core-java-networking-3/src/main/java/com/baeldung/timeout/TcpClientSocket.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/timeout/TcpClientSocket.java similarity index 100% rename from core-java-modules/core-java-networking-3/src/main/java/com/baeldung/timeout/TcpClientSocket.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/timeout/TcpClientSocket.java diff --git a/core-java-modules/core-java-networking-3/src/main/java/com/baeldung/timeout/TcpServerSocket.java b/core-java-modules/core-java-networking/src/main/java/com/baeldung/timeout/TcpServerSocket.java similarity index 100% rename from core-java-modules/core-java-networking-3/src/main/java/com/baeldung/timeout/TcpServerSocket.java rename to core-java-modules/core-java-networking/src/main/java/com/baeldung/timeout/TcpServerSocket.java diff --git a/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/download/FileDownloadIntegrationTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/download/FileDownloadIntegrationTest.java similarity index 100% rename from core-java-modules/core-java-networking-2/src/test/java/com/baeldung/download/FileDownloadIntegrationTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/download/FileDownloadIntegrationTest.java diff --git a/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/httprequest/HttpRequestLiveTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/httprequest/HttpRequestLiveTest.java similarity index 95% rename from core-java-modules/core-java-networking-2/src/test/java/com/baeldung/httprequest/HttpRequestLiveTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/httprequest/HttpRequestLiveTest.java index 63aff3912345..7b4d087fed6e 100644 --- a/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/httprequest/HttpRequestLiveTest.java +++ b/core-java-modules/core-java-networking/src/test/java/com/baeldung/httprequest/HttpRequestLiveTest.java @@ -1,17 +1,26 @@ package com.baeldung.httprequest; -import org.apache.commons.lang3.StringUtils; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -import java.io.*; -import java.net.*; +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.CookieManager; +import java.net.HttpCookie; +import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; public class HttpRequestLiveTest { diff --git a/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/mail/EmailServiceLiveTest.java b/core-java-modules/core-java-networking/src/test/java/com/baeldung/mail/EmailServiceLiveTest.java similarity index 97% rename from core-java-modules/core-java-networking-2/src/test/java/com/baeldung/mail/EmailServiceLiveTest.java rename to core-java-modules/core-java-networking/src/test/java/com/baeldung/mail/EmailServiceLiveTest.java index 4d03e6b2913d..3403d3630c7f 100644 --- a/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/mail/EmailServiceLiveTest.java +++ b/core-java-modules/core-java-networking/src/test/java/com/baeldung/mail/EmailServiceLiveTest.java @@ -1,88 +1,88 @@ -package com.baeldung.mail; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -import com.icegreen.greenmail.junit.GreenMailRule; -import com.icegreen.greenmail.util.ServerSetupTest; - -import jakarta.mail.Address; -import jakarta.mail.MessagingException; -import jakarta.mail.internet.InternetAddress; -import jakarta.mail.internet.MimeMessage; -import jakarta.mail.internet.MimeMultipart; - -public class EmailServiceLiveTest { - - @Rule - public final GreenMailRule greenMail = new GreenMailRule(ServerSetupTest.SMTP); - - private EmailService emailService; - - @Before - public void setup() { - emailService = new EmailService("localhost", greenMail.getSmtp() - .getPort()); - } - - @Test - public void givenEmailMessageWithAttachment_whenEmailIsSent_MessageIsReceived() throws Exception { - - emailService.sendMail(); - - MimeMessage[] receivedMessages = greenMail.getReceivedMessages(); - assertEquals(1, receivedMessages.length); - - MimeMessage receivedMessage = receivedMessages[0]; - assertEquals("Mail Subject", subjectFromMessage(receivedMessage)); - assertEquals("This is my first email using JavaMailer", emailTextFrom(receivedMessage)); - assertEquals("This is my bold-red email using JavaMailer", emailStyledTextFrom(receivedMessage)); - assertEquals("sample attachment content", attachmentContentsFrom(receivedMessage)); - } - - @Test - public void givenEmailMessageWithMultipleRecipients_whenEmailIsSent_AllRecipientReceivedMessage() throws Exception { - emailService.sendMailToMultipleRecipients(); - - MimeMessage[] receivedMessages = greenMail.getReceivedMessages(); - assertEquals(4, receivedMessages.length); - - for (MimeMessage mimeMessage : receivedMessages) { - Address[] recipients = new Address[4]; - recipients[0] = new InternetAddress("to@gmail.com"); - recipients[1] = new InternetAddress("to1@gmail.com"); - recipients[2] = new InternetAddress("to2@gmail.com"); - recipients[3] = new InternetAddress("to3@gmail.com"); - assertArrayEquals(recipients, mimeMessage.getAllRecipients()); - } - } - - private static String subjectFromMessage(MimeMessage receivedMessage) throws MessagingException { - return receivedMessage.getSubject(); - } - - private static String emailTextFrom(MimeMessage receivedMessage) throws IOException, MessagingException { - return ((MimeMultipart) receivedMessage.getContent()).getBodyPart(0) - .getContent() - .toString(); - } - - private static String emailStyledTextFrom(MimeMessage receivedMessage) throws IOException, MessagingException { - return ((MimeMultipart) receivedMessage.getContent()).getBodyPart(1) - .getContent() - .toString(); - } - - private static String attachmentContentsFrom(MimeMessage receivedMessage) throws Exception { - return ((MimeMultipart) receivedMessage.getContent()).getBodyPart(2) - .getContent() - .toString(); - } - -} +package com.baeldung.mail; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import com.icegreen.greenmail.junit.GreenMailRule; +import com.icegreen.greenmail.util.ServerSetupTest; + +import jakarta.mail.Address; +import jakarta.mail.MessagingException; +import jakarta.mail.internet.InternetAddress; +import jakarta.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMultipart; + +public class EmailServiceLiveTest { + + @Rule + public final GreenMailRule greenMail = new GreenMailRule(ServerSetupTest.SMTP); + + private EmailService emailService; + + @Before + public void setup() { + emailService = new EmailService("localhost", greenMail.getSmtp() + .getPort()); + } + + @Test + public void givenEmailMessageWithAttachment_whenEmailIsSent_MessageIsReceived() throws Exception { + + emailService.sendMail(); + + MimeMessage[] receivedMessages = greenMail.getReceivedMessages(); + assertEquals(1, receivedMessages.length); + + MimeMessage receivedMessage = receivedMessages[0]; + assertEquals("Mail Subject", subjectFromMessage(receivedMessage)); + assertEquals("This is my first email using JavaMailer", emailTextFrom(receivedMessage)); + assertEquals("This is my bold-red email using JavaMailer", emailStyledTextFrom(receivedMessage)); + assertEquals("sample attachment content", attachmentContentsFrom(receivedMessage)); + } + + @Test + public void givenEmailMessageWithMultipleRecipients_whenEmailIsSent_AllRecipientReceivedMessage() throws Exception { + emailService.sendMailToMultipleRecipients(); + + MimeMessage[] receivedMessages = greenMail.getReceivedMessages(); + assertEquals(4, receivedMessages.length); + + for (MimeMessage mimeMessage : receivedMessages) { + Address[] recipients = new Address[4]; + recipients[0] = new InternetAddress("to@gmail.com"); + recipients[1] = new InternetAddress("to1@gmail.com"); + recipients[2] = new InternetAddress("to2@gmail.com"); + recipients[3] = new InternetAddress("to3@gmail.com"); + assertArrayEquals(recipients, mimeMessage.getAllRecipients()); + } + } + + private static String subjectFromMessage(MimeMessage receivedMessage) throws MessagingException { + return receivedMessage.getSubject(); + } + + private static String emailTextFrom(MimeMessage receivedMessage) throws IOException, MessagingException { + return ((MimeMultipart) receivedMessage.getContent()).getBodyPart(0) + .getContent() + .toString(); + } + + private static String emailStyledTextFrom(MimeMessage receivedMessage) throws IOException, MessagingException { + return ((MimeMultipart) receivedMessage.getContent()).getBodyPart(1) + .getContent() + .toString(); + } + + private static String attachmentContentsFrom(MimeMessage receivedMessage) throws Exception { + return ((MimeMultipart) receivedMessage.getContent()).getBodyPart(2) + .getContent() + .toString(); + } + +}