From: markt Date: Sat, 8 May 2010 15:54:44 +0000 (+0000) Subject: Fix JULI configuration so JULI is actually used. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=7bfa6d8fb666b636f6898166af110b8c028b3d19;p=tomcat7.0 Fix JULI configuration so JULI is actually used. Fix FindBugs warnings git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@942407 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/test/org/apache/catalina/startup/TomcatBaseTest.java b/test/org/apache/catalina/startup/TomcatBaseTest.java index 9fd045102..c274176f4 100644 --- a/test/org/apache/catalina/startup/TomcatBaseTest.java +++ b/test/org/apache/catalina/startup/TomcatBaseTest.java @@ -25,15 +25,12 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.List; import java.util.Map; -import java.util.logging.ConsoleHandler; -import java.util.logging.LogManager; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleState; import org.apache.tomcat.util.buf.ByteChunk; @@ -82,17 +79,19 @@ public abstract class TomcatBaseTest extends TestCase { @Override public void setUp() throws Exception { - // Need to use JULI and to configure a ConsoleHandler so log messages - // from the tests are visible - System.setProperty("java.util.logging.config.class", + // Need to use JULI so log messages from the tests are visible + System.setProperty("java.util.logging.manager", "org.apache.juli.ClassLoaderLogManager"); - LogManager.getLogManager().getLogger("").addHandler( - new ConsoleHandler()); tempDir = new File(System.getProperty("tomcat.test.temp", "output/tmp")); - tempDir.mkdir(); + if (!tempDir.mkdir()) { + fail("Unable to create temporary directory for test"); + } + File appBase = new File(tempDir, "webapps"); - appBase.mkdir(); + if (!appBase.mkdir()) { + fail("Unable to create appBase for test"); + } tomcat = new Tomcat(); tomcat.setBaseDir(tempDir.getAbsolutePath()); @@ -139,9 +138,9 @@ public abstract class TomcatBaseTest extends TestCase { return out; } - public static int getUrl(String path, - ByteChunk out, - Map> resHead) throws IOException { + public static int getUrl(String path, ByteChunk out, + Map> resHead) throws IOException { + URL url = new URL(path); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); @@ -153,11 +152,22 @@ public abstract class TomcatBaseTest extends TestCase { resHead.putAll(head); } InputStream is = connection.getInputStream(); - BufferedInputStream bis = new BufferedInputStream(is); - byte[] buf = new byte[2048]; - int rd = 0; - while((rd = bis.read(buf)) > 0) { - out.append(buf, 0, rd); + BufferedInputStream bis = null; + try { + bis = new BufferedInputStream(is); + byte[] buf = new byte[2048]; + int rd = 0; + while((rd = bis.read(buf)) > 0) { + out.append(buf, 0, rd); + } + } finally { + if (bis != null) { + try { + bis.close(); + } catch (IOException e) { + // Ignore + } + } } return rc; }