diff --git a/pom.xml b/pom.xml
index a78af89..a406b19 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,8 +12,8 @@
1.0
jar
- 17
- 17
+ 11
+ 11
UTF-8
diff --git a/src/main/java/ru/molokoin/sourceListener/HttpClient.java b/src/main/java/ru/molokoin/sourceListener/HttpClient.java
deleted file mode 100644
index 766c927..0000000
--- a/src/main/java/ru/molokoin/sourceListener/HttpClient.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package ru.molokoin.sourceListener;
-import java.net.*;
-import java.io.*;
-
-/**
- * This program demonstrates a client socket application that connects to
- * a web server and send a HTTP HEAD request.
- *
- * @author www.codejava.net
- */
-public class HttpClient {
- URL url;
-
- public static void main(String[] args) {
- HttpClient cli = new HttpClient();
- try {
- cli.url = new URL("http://www.molokoin.ru");
- } catch (MalformedURLException ex) {
- ex.printStackTrace();
- return;
- }
-
- String hostname = cli.url.getHost();
- int port = 3000;
-
- try (Socket socket = new Socket(hostname, port)) {
-
- OutputStream output = socket.getOutputStream();
- PrintWriter writer = new PrintWriter(output, true);
-
- writer.println("HEAD " + cli.url.getPath() + " HTTP/1.1");
- writer.println("Host: " + hostname);
- writer.println("User-Agent: Simple Http Client");
- writer.println("Accept: text/html");
- writer.println("Accept-Language: en-EN");
- writer.println("Connection: close");
- writer.println();
-
- InputStream input = socket.getInputStream();
-
- BufferedReader reader = new BufferedReader(new InputStreamReader(input));
-
- String line;
-
- while ((line = reader.readLine()) != null) {
- System.out.println(line);
- }
- } catch (UnknownHostException ex) {
-
- System.out.println("Server not found: " + ex.getMessage());
-
- } catch (IOException ex) {
-
- System.out.println("I/O error: " + ex.getMessage());
- }
- }
-}
diff --git a/src/main/java/ru/molokoin/sourceListener/SourceListener.java b/src/main/java/ru/molokoin/sourceListener/SourceListener.java
index b83bfc9..d729cde 100644
--- a/src/main/java/ru/molokoin/sourceListener/SourceListener.java
+++ b/src/main/java/ru/molokoin/sourceListener/SourceListener.java
@@ -1,20 +1,29 @@
package ru.molokoin.sourceListener;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+
public class SourceListener {
public static void main(String[] args) {
- HttpClient client = HttpClient.newBuilder()
- .version(Version.HTTP_1_1)
- .followRedirects(Redirect.NORMAL)
- .connectTimeout(Duration.ofSeconds(20))
- .proxy(ProxySelector.of(new InetSocketAddress("www.ya.ru", 80)))
- .authenticator(Authenticator.getDefault())
- .build();
-
-
-HttpResponse response = client.send("GET", BodyHandlers.ofString());
-System.out.println(response.statusCode());
-System.out.println(response.body());
+ HttpClient client = HttpClient.newHttpClient();
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(URI.create("http://molokoin.ru:3000/esoe/molokoin-client"))
+ .GET() // GET is default
+ .build();
+
+ try {
+ HttpResponse response = client.send(request,
+ HttpResponse.BodyHandlers.ofString());
+ System.out.println(response.statusCode());
+ System.out.println(response.headers());
+ System.out.println(response.body());
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ }
+
}
}
diff --git a/target/classes/ru/molokoin/sourceListener/HttpClient.class b/target/classes/ru/molokoin/sourceListener/HttpClient.class
deleted file mode 100644
index b98227d..0000000
Binary files a/target/classes/ru/molokoin/sourceListener/HttpClient.class and /dev/null differ
diff --git a/target/classes/ru/molokoin/sourceListener/SourceListener.class b/target/classes/ru/molokoin/sourceListener/SourceListener.class
index ef803fe..fe756fd 100644
Binary files a/target/classes/ru/molokoin/sourceListener/SourceListener.class and b/target/classes/ru/molokoin/sourceListener/SourceListener.class differ