Added more Error Handling and improved log readability
This commit is contained in:
parent
d9dc23c524
commit
4adfd86fb5
3 changed files with 15 additions and 5 deletions
|
@ -17,7 +17,7 @@ import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
public class Main {
|
public class Main {
|
||||||
private static final String version = "0.5";
|
private static final String version = "0.6";
|
||||||
private static final HashMap<String, Integer> data = new HashMap<>();
|
private static final HashMap<String, Integer> data = new HashMap<>();
|
||||||
public static Settings conf;
|
public static Settings conf;
|
||||||
static OebbCheck check = new OebbCheck();
|
static OebbCheck check = new OebbCheck();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package be.jaud;
|
package be.jaud;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -68,7 +69,11 @@ public class OebbCheck {
|
||||||
private static JSONArray getData(String Station, String Time, String maxjourneys) throws IOException, URISyntaxException {
|
private static JSONArray getData(String Station, String Time, String maxjourneys) throws IOException, URISyntaxException {
|
||||||
URL url = new URI("https://fahrplan.oebb.at/bin/stboard.exe/dn?L=vs_scotty.vs_liveticker&evaId=" + Station + "&boardType=dep&time="+ Time +"&productsFilter=1011110111011&additionalTime=0&maxJourneys=" + maxjourneys + "&outputMode=tickerDataOnly&start=yes&selectDate=today").toURL();
|
URL url = new URI("https://fahrplan.oebb.at/bin/stboard.exe/dn?L=vs_scotty.vs_liveticker&evaId=" + Station + "&boardType=dep&time="+ Time +"&productsFilter=1011110111011&additionalTime=0&maxJourneys=" + maxjourneys + "&outputMode=tickerDataOnly&start=yes&selectDate=today").toURL();
|
||||||
JSONObject jo = getJsonObject(url);
|
JSONObject jo = getJsonObject(url);
|
||||||
|
if(jo!=null) {
|
||||||
return jo.getJSONArray("journey");
|
return jo.getJSONArray("journey");
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JSONObject getJsonObject(URL url) throws IOException {
|
private static JSONObject getJsonObject(URL url) throws IOException {
|
||||||
|
@ -83,6 +88,11 @@ public class OebbCheck {
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
String sub = content.substring(14);
|
String sub = content.substring(14);
|
||||||
|
try {
|
||||||
return new JSONObject(sub);
|
return new JSONObject(sub);
|
||||||
|
} catch (JSONException e){
|
||||||
|
LOG.error("Json Error! {} {}", e.getMessage(), sub);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,14 @@
|
||||||
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder
|
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder
|
||||||
by default -->
|
by default -->
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%ex%n
|
<pattern>%d{dd.MM.yyyy HH:mm:ss} [%thread] %-5level %logger{36} - %msg%ex%n
|
||||||
</pattern>
|
</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
<appender name="FILE"
|
<appender name="FILE"
|
||||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %ex %n</pattern>
|
<pattern>%d{dd.MM.yyyy HH:mm:ss} [%thread] %-5level %logger{35} - %msg %ex %n</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
<file>logs/logfile.log</file>
|
<file>logs/logfile.log</file>
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue