From dad81d8093e83eaa17224d33d2fc6185c9d32088 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 19 Feb 2017 12:28:35 +1300 Subject: Handle unknown host exception --- src/org/traccar/Context.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index c9c2e633e..27e61d32d 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.ning.http.client.AsyncHttpClient; import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.Properties; import org.apache.velocity.app.VelocityEngine; @@ -281,9 +282,14 @@ public final class Context { velocityProperties.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogChute"); - String address = config.getString("web.address", InetAddress.getLocalHost().getHostAddress()); - int port = config.getInteger("web.port", 8082); - String webUrl = URIUtil.newURI("http", address, port, "", ""); + String address; + try { + address = config.getString("web.address", InetAddress.getLocalHost().getHostAddress()); + } catch (UnknownHostException e) { + address = "localhost"; + } + + String webUrl = URIUtil.newURI("http", address, config.getInteger("web.port", 8082), "", ""); webUrl = Context.getConfig().getString("web.url", webUrl); velocityProperties.setProperty("web.url", webUrl); -- cgit v1.2.3