Commit 324c19ff by Patryk Czarnik

Ustawienia

parent 9a941116
...@@ -13,7 +13,7 @@ public class Klient01_URL { ...@@ -13,7 +13,7 @@ public class Klient01_URL {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
URL url = new URL("http://localhost:8080/PC32-RestSerwer/products.json"); URL url = new URL(Ustawienia.ADRES_USLUGI + "/products.json");
try(InputStream inputStream = url.openStream()) { try(InputStream inputStream = url.openStream()) {
Files.copy(inputStream, Paths.get("wynik01.json"), StandardCopyOption.REPLACE_EXISTING); Files.copy(inputStream, Paths.get("wynik01.json"), StandardCopyOption.REPLACE_EXISTING);
System.out.println("OK"); System.out.println("OK");
......
...@@ -21,7 +21,7 @@ public class Klient03_HttpClient { ...@@ -21,7 +21,7 @@ public class Klient03_HttpClient {
public static void main(String[] args) { public static void main(String[] args) {
HttpClient httpClient = HttpClient.newHttpClient(); HttpClient httpClient = HttpClient.newHttpClient();
try { try {
URI uri = new URI("http://localhost:8080/PC32-RestSerwer/products.json"); URI uri = new URI(Ustawienia.ADRES_USLUGI + "/products.json");
HttpRequest request = HttpRequest.newBuilder(uri).build(); HttpRequest request = HttpRequest.newBuilder(uri).build();
HttpResponse<Path> response = httpClient.send(request, BodyHandlers.ofFile(Paths.get("wynik03.json"))); HttpResponse<Path> response = httpClient.send(request, BodyHandlers.ofFile(Paths.get("wynik03.json")));
System.out.println("response " + response); System.out.println("response " + response);
......
...@@ -19,7 +19,7 @@ public class Klient04_HttpClient_String { ...@@ -19,7 +19,7 @@ public class Klient04_HttpClient_String {
public static void main(String[] args) { public static void main(String[] args) {
HttpClient httpClient = HttpClient.newHttpClient(); HttpClient httpClient = HttpClient.newHttpClient();
try { try {
URI uri = new URI("http://localhost:8080/PC32-RestSerwer/products.json"); URI uri = new URI(Ustawienia.ADRES_USLUGI + "/products.json");
HttpRequest request = HttpRequest.newBuilder(uri).build(); HttpRequest request = HttpRequest.newBuilder(uri).build();
HttpResponse<String> response = httpClient.send(request, BodyHandlers.ofString()); HttpResponse<String> response = httpClient.send(request, BodyHandlers.ofString());
System.out.println("response " + response); System.out.println("response " + response);
......
package sklep.klient;
public class Ustawienia {
public static final String ADRES_USLUGI = "http://localhost:8080/PC32-RestSerwer";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment