BAEL-2174: rename core-java-net module to core-java-networking (#5837)

* BAEL-2246: add link back to article

* BAEL-2174: rename core-java-net module to core-java-networking
This commit is contained in:
KevinGilmore
2018-12-08 08:58:16 -06:00
committed by Eugen
parent 5072291b32
commit 0b0aedc287
11 changed files with 5 additions and 5 deletions

25
core-java-networking/.gitignore vendored Normal file
View File

@@ -0,0 +1,25 @@
*.class
0.*
#folders#
/target
/neoDb*
/data
/src/main/webapp/WEB-INF/classes
*/META-INF/*
.resourceCache
# Packaged files #
*.jar
*.war
*.ear
# Files generated by integration tests
backup-pom.xml
/bin/
/temp
#IntelliJ specific
.idea/
*.iml

View File

@@ -0,0 +1,3 @@
=========
## Core Java Net

View File

@@ -0,0 +1,19 @@
<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>core-java-networking</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>core-java-networking</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<build>
<finalName>core-java-networking</finalName>
</build>
</project>

View File

@@ -0,0 +1,17 @@
package com.baeldung.networking.proxies;
import java.net.URL;
import java.net.URLConnection;
public class CommandLineProxyDemo {
public static final String RESOURCE_URL = "http://www.google.com";
public static void main(String[] args) throws Exception {
URL url = new URL(RESOURCE_URL);
URLConnection con = url.openConnection();
System.out.println(UrlConnectionUtils.contentAsString(con));
}
}

View File

@@ -0,0 +1,20 @@
package com.baeldung.networking.proxies;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL;
public class DirectProxyDemo {
private static final String URL_STRING = "http://www.google.com";
public static void main(String... args) throws IOException {
URL weburl = new URL(URL_STRING);
HttpURLConnection directConnection
= (HttpURLConnection) weburl.openConnection(Proxy.NO_PROXY);
System.out.println(UrlConnectionUtils.contentAsString(directConnection));
}
}

View File

@@ -0,0 +1,32 @@
package com.baeldung.networking.proxies;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Socket;
import java.net.URL;
public class SocksProxyDemo {
private static final String URL_STRING = "http://www.google.com";
private static final String SOCKET_SERVER_HOST = "someserver.baeldung.com";
private static final int SOCKET_SERVER_PORT = 1111;
public static void main(String... args) throws IOException {
URL weburl = new URL(URL_STRING);
Proxy socksProxy
= new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 1080));
HttpURLConnection socksConnection
= (HttpURLConnection) weburl.openConnection(socksProxy);
System.out.println(UrlConnectionUtils.contentAsString(socksConnection));
Socket proxySocket = new Socket(socksProxy);
InetSocketAddress socketHost
= new InetSocketAddress(SOCKET_SERVER_HOST, SOCKET_SERVER_PORT);
proxySocket.connect(socketHost);
// do stuff with the socket
}
}

View File

@@ -0,0 +1,23 @@
package com.baeldung.networking.proxies;
import java.net.URL;
import java.net.URLConnection;
public class SystemPropertyProxyDemo {
public static final String RESOURCE_URL = "http://www.google.com";
public static void main(String[] args) throws Exception {
System.setProperty("http.proxyHost", "127.0.0.1");
System.setProperty("http.proxyPort", "3128");
URL url = new URL(RESOURCE_URL);
URLConnection con = url.openConnection();
System.out.println(UrlConnectionUtils.contentAsString(con));
System.setProperty("http.proxyHost", null);
// proxy will no longer be used for http connections
}
}

View File

@@ -0,0 +1,21 @@
package com.baeldung.networking.proxies;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLConnection;
class UrlConnectionUtils {
public static String contentAsString(URLConnection con) throws IOException {
StringBuilder builder = new StringBuilder();
try (BufferedReader reader
= new BufferedReader(new InputStreamReader(con.getInputStream()))){
while (reader.ready()) {
builder.append(reader.readLine());
}
}
return builder.toString();
}
}

View File

@@ -0,0 +1,23 @@
package com.baeldung.networking.proxies;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
public class WebProxyDemo {
private static final String URL_STRING = "http://www.google.com";
public static void main(String... args) throws IOException {
URL weburl = new URL(URL_STRING);
Proxy webProxy
= new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 3128));
HttpURLConnection webProxyConnection
= (HttpURLConnection) weburl.openConnection(webProxy);
System.out.println(UrlConnectionUtils.contentAsString(webProxyConnection));
}
}

View File

@@ -0,0 +1,13 @@
*.class
#folders#
/target
/neoDb*
/data
/src/main/webapp/WEB-INF/classes
*/META-INF/*
# Packaged files #
*.jar
*.war
*.ear