From 3fb5bc40bce836b314b215a1429153ae9977e5c8 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 19 Dec 2021 19:35:20 +0100 Subject: [PATCH] bugfixes --- .deployment/docker-compose.yml | 2 +- .../tapas/TapasAuctionHouseApplication.java | 4 +- .../web/AuctionHouseDiscoveryHttpAdapter.java | 41 +++++++++++-------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/.deployment/docker-compose.yml b/.deployment/docker-compose.yml index 8fe036d..c13b0f7 100644 --- a/.deployment/docker-compose.yml +++ b/.deployment/docker-compose.yml @@ -67,7 +67,7 @@ services: - ./:/data/ environment: mqtt.broker.uri: tcp://broker.hivemq.com:1883 - discovery.endpoint.uri: http://tapas-auction-house.86-119-34-242.nip.io/ + discovery.endpoint.uri: http://tapas-auction-house.86-119-34-242.nip.io auction.house.uri: https://tapas-auction-house.86-119-35-40.nip.io labels: - "traefik.enable=true" diff --git a/tapas-auction-house/src/main/java/ch/unisg/tapas/TapasAuctionHouseApplication.java b/tapas-auction-house/src/main/java/ch/unisg/tapas/TapasAuctionHouseApplication.java index 39fb610..f329cad 100644 --- a/tapas-auction-house/src/main/java/ch/unisg/tapas/TapasAuctionHouseApplication.java +++ b/tapas-auction-house/src/main/java/ch/unisg/tapas/TapasAuctionHouseApplication.java @@ -46,8 +46,6 @@ public class TapasAuctionHouseApplication { * Discovers auction houses and subscribes to WebSub notifications */ private static void bootstrapMarketplaceWithWebSub() { - discoverAuctionHouseEndpoints(); - WebSubSubscriber subscriber = new WebSubSubscriber(ENVIRONMENT.getProperty("auction.house.uri")); try { @@ -57,6 +55,8 @@ public class TapasAuctionHouseApplication { e.printStackTrace(); } + discoverAuctionHouseEndpoints(); + // for (AuctionHouseDiscoveryInformation endpoint : AuctionHouseDiscovery.getInstance().getAuctionHouseDiscoveryList()) { // System.out.println(endpoint.getWebSubUri().getValue()); // if (!endpoint.getWebSubUri().getValue().toString().equalsIgnoreCase("https://tapas-auction-house.86-119-35-40.nip.io/websub/auctions")) { diff --git a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/out/web/AuctionHouseDiscoveryHttpAdapter.java b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/out/web/AuctionHouseDiscoveryHttpAdapter.java index e9f5a04..f7f13c3 100644 --- a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/out/web/AuctionHouseDiscoveryHttpAdapter.java +++ b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/out/web/AuctionHouseDiscoveryHttpAdapter.java @@ -6,6 +6,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.json.JSONArray; import org.json.JSONObject; +import org.springframework.http.HttpStatus; import java.io.IOException; import java.net.URI; @@ -30,27 +31,31 @@ public class AuctionHouseDiscoveryHttpAdapter implements AuctionHouseDiscoveryPo .uri(auctionHouseURI) .GET() .build(); - var response = client.send(request, HttpResponse.BodyHandlers.ofString()); - LOGGER.info(response.body()); - var responseBody = new JSONObject(response.body()); + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + LOGGER.info("Response status code: " + response.statusCode()); + LOGGER.info("Response body:" + response.body()); + if (response.statusCode() == HttpStatus.OK.value()) { + var responseBody = new JSONObject(response.body()); - var arrayOfInformation = responseBody.getJSONArray("auctionHouseInfo"); - var returnList = new LinkedList(); + var arrayOfInformation = responseBody.getJSONArray("auctionHouseInfo"); + var returnList = new LinkedList(); - for(int i = 0; i < arrayOfInformation.length(); i++) - { - var informationJSON = arrayOfInformation.getJSONObject(i); - var information = new AuctionHouseDiscoveryInformation( - new AuctionHouseDiscoveryInformation.AuctionHouseUri(URI.create(informationJSON.getString("auctionHouseUri"))), - new AuctionHouseDiscoveryInformation.WebSubUri(URI.create(informationJSON.getString("webSubUri"))), - new AuctionHouseDiscoveryInformation.TaskTypes(getTaskTypes(informationJSON.getJSONArray("taskTypes"))), - new AuctionHouseDiscoveryInformation.TimeStamp(Timestamp.valueOf(informationJSON.getString("timeStamp"))), - new AuctionHouseDiscoveryInformation.GroupName(informationJSON.getString("groupName")) - ); - returnList.add(information); + for(int i = 0; i < arrayOfInformation.length(); i++) + { + var informationJSON = arrayOfInformation.getJSONObject(i); + var information = new AuctionHouseDiscoveryInformation( + new AuctionHouseDiscoveryInformation.AuctionHouseUri(URI.create(informationJSON.getString("auctionHouseUri"))), + new AuctionHouseDiscoveryInformation.WebSubUri(URI.create(informationJSON.getString("webSubUri"))), + new AuctionHouseDiscoveryInformation.TaskTypes(getTaskTypes(informationJSON.getJSONArray("taskTypes"))), + new AuctionHouseDiscoveryInformation.TimeStamp(Timestamp.valueOf(informationJSON.getString("timeStamp"))), + new AuctionHouseDiscoveryInformation.GroupName(informationJSON.getString("groupName")) + ); + returnList.add(information); + } + + return returnList; } - - return returnList; + return Collections.emptyList(); } catch (IOException e) { e.printStackTrace();