diff --git a/commons-http-server/src/main/java/io/gitlab/jfronny/commons/http/server/JLHTTPServer.java b/commons-http-server/src/main/java/io/gitlab/jfronny/commons/http/server/JLHTTPServer.java index d7e97ee..cb131df 100644 --- a/commons-http-server/src/main/java/io/gitlab/jfronny/commons/http/server/JLHTTPServer.java +++ b/commons-http-server/src/main/java/io/gitlab/jfronny/commons/http/server/JLHTTPServer.java @@ -112,6 +112,8 @@ import java.util.zip.GZIPOutputStream; * @since 2008-07-24 */ public class JLHTTPServer { + private static final System.Logger LOGGER = System.getLogger("commons-http-server"); + /** * The SimpleDateFormat-compatible formats of dates which must be supported. * Note that all generated date fields must be in the RFC 1123 format only, @@ -443,9 +445,10 @@ public class JLHTTPServer { * or the default virtual host */ public VirtualHost getVirtualHost() { - return host != null ? host - : (host = JLHTTPServer.this.getVirtualHost(getBaseURL().getHost())) != null ? host - : (host = JLHTTPServer.this.getVirtualHost(null)); + if (host != null) return host; + URL baseUrl = getBaseURL(); + if (baseUrl != null && (host = JLHTTPServer.this.getVirtualHost(baseUrl.getHost())) != null) return host; + return host = JLHTTPServer.this.getVirtualHost(null); } /** @@ -981,6 +984,7 @@ public class JLHTTPServer { resp = new Response(out); // ignore whatever headers may have already been set resp.getHeaders().add("Connection", "close"); // about to close connection resp.sendError(500, "Error processing request: " + t.getMessage()); + LOGGER.log(System.Logger.Level.WARNING, "Error processing request", t); } // otherwise just abort the connection since we can't recover break; // proceed to close connection } finally {