Commit b7f3dc4b by Patryk Czarnik

Adres w pliku Ustawienia

parent 2ad5ee6e
...@@ -11,7 +11,7 @@ public class P01_Url { ...@@ -11,7 +11,7 @@ public class P01_Url {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
URL url = new URL("http://localhost:8080/PC33-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");
......
...@@ -13,7 +13,7 @@ public class P02_Url_Json { ...@@ -13,7 +13,7 @@ public class P02_Url_Json {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
URL url = new URL("http://localhost:8080/PC33-RestSerwer/products.json"); URL url = new URL(Ustawienia.ADRES_USLUGI + "/products.json");
try(InputStream inputStream = url.openStream(); try(InputStream inputStream = url.openStream();
JsonReader reader = Json.createReader(inputStream)) { JsonReader reader = Json.createReader(inputStream)) {
JsonArray array = reader.readArray(); JsonArray array = reader.readArray();
......
...@@ -13,7 +13,7 @@ public class P03_HttpClient { ...@@ -13,7 +13,7 @@ public class P03_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/PC33-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);
......
...@@ -19,7 +19,7 @@ public class P04_HttpClient_Json { ...@@ -19,7 +19,7 @@ public class P04_HttpClient_Json {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
JsonArray array = pobierzJsona("http://localhost:8080/PC33-RestSerwer/products.json"); JsonArray array = pobierzJsona(Ustawienia.ADRES_USLUGI + "/products.json");
for(JsonValue jsonValue : array) { for(JsonValue jsonValue : array) {
JsonObject jsonObject = jsonValue.asJsonObject(); JsonObject jsonObject = jsonValue.asJsonObject();
System.out.println(jsonObject.getString("productName")); System.out.println(jsonObject.getString("productName"));
......
package sklep.klient_rest;
public class Ustawienia {
public static final String ADRES_USLUGI = "http://localhost:8080/PC33-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