diff --git a/data-collectors/traveltimes-a22/calls.http b/data-collectors/traveltimes-a22/calls.http index cc20f224..38c49b5d 100644 --- a/data-collectors/traveltimes-a22/calls.http +++ b/data-collectors/traveltimes-a22/calls.http @@ -5,7 +5,7 @@ @token = {{login.response.body.SubscribeResult.sessionId}} POST {{host}}/token Content-Type: application/json -User-Agent: NOI/A22TraveltimesConnector +User-Agent: NOI/A22TravelTimesConnector Accept: */* { @@ -14,8 +14,6 @@ Accept: */* "password": "{{$dotenv A22_CONNECTOR_PWD}}" } } - - ### De-authorize DELETE {{host}}/token/{{token}} User-Agent: NOI/A22TraveltimesConnector @@ -45,7 +43,7 @@ Accept: */* { "request": { "sessionId": "{{token}}", - "idtratto": "1840-1841", + "idtratto": "1867-1865", "fromData": "/Date({{fromTs}}000+0000)/", "toData": "/Date({{toTs}}999+0000)/" } diff --git a/data-collectors/traveltimes-a22/src/main/java/it/bz/noi/a22/traveltimes/Connector.java b/data-collectors/traveltimes-a22/src/main/java/it/bz/noi/a22/traveltimes/Connector.java index 13b34dec..3bda46f2 100644 --- a/data-collectors/traveltimes-a22/src/main/java/it/bz/noi/a22/traveltimes/Connector.java +++ b/data-collectors/traveltimes-a22/src/main/java/it/bz/noi/a22/traveltimes/Connector.java @@ -20,22 +20,22 @@ */ package it.bz.noi.a22.traveltimes; -import org.apache.commons.io.IOUtils; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * encapsulates the A22 API to query travel times */ @@ -44,7 +44,7 @@ public class Connector { private static final String USER_AGENT = "NOI/A22TravelTimesConnector"; private static final int WS_CONN_TIMEOUT_MSEC = 30000; private static final int WS_READ_TIMEOUT_MSEC = 1800000; - private static final boolean DEBUG = true; + private static final Logger LOG = LoggerFactory.getLogger(MainA22Traveltimes.class); private String token = null; private String url = null; @@ -109,9 +109,7 @@ public Connector(String url, String username, String password) throws IOExceptio this.url = url; this.token = session_id; - if (DEBUG) { - System.err.println("authentication OK new token = " + token); - } + LOG.debug("authentication OK new token = " + token); } @@ -167,9 +165,7 @@ public void close() throws IOException { throw new RuntimeException("de-authentication failure (de-authentication was not confirmed)"); } - if (DEBUG) { - System.err.println("de-authentication OK old token = " + token); - } + LOG.debug("de-authentication OK old token = " + token); this.url = null; this.token = null; @@ -250,9 +246,7 @@ public List> getTravelTimeSegments() throws IOException throw new RuntimeException("could not parse list of segments"); } - if (DEBUG) { - System.err.println("getTravelTimeSegments() OK: got " + output.size() + " segments"); - } + LOG.debug("getTravelTimeSegments() OK: got " + output.size() + " segments"); return output; @@ -285,6 +279,8 @@ public List> getTravelTimes(long fr, long to, String id) // (see the comment "Reverse engineering the A22 time stamp format" at the end of the file) String frTS = fr + "000+0000"; String toTS = to + "999+0000"; + + LOG.debug("Retrieving traveltimes for station %s with timestamps %s - %s", id, frTS, toTS); // retrieve events HttpURLConnection conn = (HttpURLConnection) (new URL(url + "/percorrenze/tempi")).openConnection(); @@ -353,9 +349,7 @@ public List> getTravelTimes(long fr, long to, String id) throw new RuntimeException("could not parse list of travel times"); } - if (DEBUG) { - System.err.println("getTravelTimes() OK: got " + output.size() + " travel times"); - } + LOG.debug("getTravelTimes() OK: got " + output.size() + " travel times"); return output;