From 19e74fe5dacd03e0cb5582f840e15262e39fe24f Mon Sep 17 00:00:00 2001 From: Jiri Vanek Date: Wed, 25 Sep 2013 18:50:18 +0200 Subject: Introduced logging bottleneck --- .../sourceforge/jnlp/runtime/AppletAudioClip.java | 4 +- .../jnlp/runtime/AppletEnvironment.java | 11 +- .../sourceforge/jnlp/runtime/AppletInstance.java | 9 +- .../jnlp/runtime/ApplicationInstance.java | 23 ++-- netx/net/sourceforge/jnlp/runtime/Boot.java | 46 ++++---- .../jnlp/runtime/CachedJarFileCallback.java | 6 +- .../sourceforge/jnlp/runtime/FakePacEvaluator.java | 5 +- .../sourceforge/jnlp/runtime/JNLPClassLoader.java | 121 ++++++++------------- netx/net/sourceforge/jnlp/runtime/JNLPPolicy.java | 7 +- .../jnlp/runtime/JNLPProxySelector.java | 27 ++--- netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java | 120 +++++++++----------- .../jnlp/runtime/JNLPSecurityManager.java | 22 ++-- .../jnlp/runtime/PacEvaluatorFactory.java | 19 ++-- .../jnlp/runtime/RhinoBasedPacEvaluator.java | 17 ++- 14 files changed, 176 insertions(+), 261 deletions(-) (limited to 'netx/net/sourceforge/jnlp/runtime') diff --git a/netx/net/sourceforge/jnlp/runtime/AppletAudioClip.java b/netx/net/sourceforge/jnlp/runtime/AppletAudioClip.java index 4dd1a79..5aec6d2 100644 --- a/netx/net/sourceforge/jnlp/runtime/AppletAudioClip.java +++ b/netx/net/sourceforge/jnlp/runtime/AppletAudioClip.java @@ -19,6 +19,7 @@ package net.sourceforge.jnlp.runtime; import java.net.*; import java.applet.*; import javax.sound.sampled.*; +import net.sourceforge.jnlp.util.logging.OutputController; // based on Deane Richan's AppletAudioClip @@ -47,7 +48,8 @@ public class AppletAudioClip implements AudioClip { clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class)); clip.open(stream); } catch (Exception ex) { - System.err.println("Error loading sound:" + location.toString()); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "Error loading sound:" + location.toString()); + OutputController.getLogger().log(ex); clip = null; } } diff --git a/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java b/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java index 8e89530..17e9d14 100644 --- a/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java +++ b/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java @@ -16,6 +16,7 @@ package net.sourceforge.jnlp.runtime; +import net.sourceforge.jnlp.util.logging.OutputController; import java.applet.*; import java.awt.*; import java.awt.event.*; @@ -90,7 +91,7 @@ public class AppletEnvironment implements AppletContext, AppletStub { WindowListener closer = new WindowAdapter() { public void windowClosing(WindowEvent event) { appletInstance.destroy(); - System.exit(0); + JNLPRuntime.exit(0); } }; frame.addWindowListener(closer); @@ -194,8 +195,7 @@ public class AppletEnvironment implements AppletContext, AppletStub { } } catch (Exception ex) { - if (JNLPRuntime.isDebug()) - ex.printStackTrace(); + OutputController.getLogger().log(ex); // should also kill the applet? } @@ -221,10 +221,7 @@ public class AppletEnvironment implements AppletContext, AppletStub { */ public void setApplet(Applet applet) { if (this.applet != null) { - if (JNLPRuntime.isDebug()) { - Exception ex = new IllegalStateException("Applet can only be set once."); - ex.printStackTrace(); - } + OutputController.getLogger().log(new IllegalStateException("Applet can only be set once.")); return; } this.applet = applet; diff --git a/netx/net/sourceforge/jnlp/runtime/AppletInstance.java b/netx/net/sourceforge/jnlp/runtime/AppletInstance.java index 1f08817..757a9f7 100644 --- a/netx/net/sourceforge/jnlp/runtime/AppletInstance.java +++ b/netx/net/sourceforge/jnlp/runtime/AppletInstance.java @@ -20,6 +20,7 @@ import java.applet.*; import java.awt.*; import net.sourceforge.jnlp.*; +import net.sourceforge.jnlp.util.logging.OutputController; /** * Represents a launched application instance created from a JNLP @@ -56,10 +57,7 @@ public class AppletInstance extends ApplicationInstance { */ public void setApplet(Applet applet) { if (this.applet != null) { - if (JNLPRuntime.isDebug()) { - Exception ex = new IllegalStateException("Applet can only be set once."); - ex.printStackTrace(); - } + OutputController.getLogger().log(new IllegalStateException("Applet can only be set once.")); return; } this.applet = applet; @@ -129,8 +127,7 @@ public class AppletInstance extends ApplicationInstance { applet.stop(); applet.destroy(); } catch (Exception ex) { - if (JNLPRuntime.isDebug()) - ex.printStackTrace(); + OutputController.getLogger().log(ex); } environment.destroy(); diff --git a/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java b/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java index f74cce6..4d38be4 100644 --- a/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java +++ b/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java @@ -38,6 +38,7 @@ import net.sourceforge.jnlp.event.ApplicationEvent; import net.sourceforge.jnlp.event.ApplicationListener; import net.sourceforge.jnlp.security.SecurityDialogs; import net.sourceforge.jnlp.security.SecurityDialogs.AccessType; +import net.sourceforge.jnlp.util.logging.OutputController; import net.sourceforge.jnlp.util.WeakList; import net.sourceforge.jnlp.util.XDesktopEntry; @@ -149,10 +150,8 @@ public class ApplicationInstance { ShortcutDesc sd = file.getInformation().getShortcut(); File possibleDesktopFile = entry.getLinuxDesktopIconFile(); if (possibleDesktopFile.exists()) { - if (JNLPRuntime.isDebug()) { - System.out.println("ApplicationInstance.addMenuAndDesktopEntries(): file - " - + possibleDesktopFile.getAbsolutePath() + " already exists. Not proceeding with desktop additions"); - } + OutputController.getLogger().log("ApplicationInstance.addMenuAndDesktopEntries(): file - " + + possibleDesktopFile.getAbsolutePath() + " already exists. Not proceeding with desktop additions"); return; } if (shouldCreateShortcut(sd)) { @@ -163,10 +162,8 @@ public class ApplicationInstance { /* * Sun's WebStart implementation doesnt seem to do anything under GNOME */ - if (JNLPRuntime.isDebug()) { - System.err.println("ApplicationInstance.addMenuAndDesktopEntries():" - + " Adding menu entries NOT IMPLEMENTED"); - } + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "ApplicationInstance.addMenuAndDesktopEntries():" + + " Adding menu entries NOT IMPLEMENTED"); } } @@ -218,7 +215,7 @@ public class ApplicationInstance { * Only collectable if classloader and thread group are * also collectable so basically is almost never called (an * application would have to close its windows and exit its - * threads but not call System.exit). + * threads but not call JNLPRuntime.exit). */ public void finalize() { destroy(); @@ -294,9 +291,7 @@ public class ApplicationInstance { Thread threads[] = new Thread[group.activeCount() * 2]; int nthreads = group.enumerate(threads); for (int i = 0; i < nthreads; i++) { - if (JNLPRuntime.isDebug()) - System.out.println("Interrupt thread: " + threads[i]); - + OutputController.getLogger().log("Interrupt thread: " + threads[i]); threads[i].interrupt(); } @@ -304,9 +299,7 @@ public class ApplicationInstance { Thread.currentThread().yield(); nthreads = group.enumerate(threads); for (int i = 0; i < nthreads; i++) { - if (JNLPRuntime.isDebug()) - System.out.println("Stop thread: " + threads[i]); - + OutputController.getLogger().log("Stop thread: " + threads[i]); threads[i].stop(); } diff --git a/netx/net/sourceforge/jnlp/runtime/Boot.java b/netx/net/sourceforge/jnlp/runtime/Boot.java index 81d19c1..3f774cf 100644 --- a/netx/net/sourceforge/jnlp/runtime/Boot.java +++ b/netx/net/sourceforge/jnlp/runtime/Boot.java @@ -37,6 +37,7 @@ import net.sourceforge.jnlp.cache.UpdatePolicy; import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.security.viewer.CertificateViewer; import net.sourceforge.jnlp.services.ServiceUtil; +import net.sourceforge.jnlp.util.logging.OutputController; import sun.awt.AppContext; import sun.awt.SunToolkit; @@ -133,30 +134,29 @@ public final class Boot implements PrivilegedAction { try { CertificateViewer.main(null); - System.exit(0); + JNLPRuntime.exit(0); } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } } if (null != getOption("-license")) { - System.out.println(miniLicense); - System.exit(0); + OutputController.getLogger().printOutLn(miniLicense); + JNLPRuntime.exit(0); } if (null != getOption("-help")) { - System.out.println(helpMessage); - System.exit(0); + OutputController.getLogger().printOutLn(helpMessage); + JNLPRuntime.exit(0); } if (null != getOption("-about")) { - System.out.println(itwInfoMessage); + OutputController.getLogger().printOutLn(itwInfoMessage); if (null != getOption("-headless")) { - System.exit(0); + JNLPRuntime.exit(0); } else { - System.out.println(R("BLaunchAbout")); + OutputController.getLogger().printOutLn(R("BLaunchAbout")); AboutDialog.display(); return; } @@ -225,9 +225,7 @@ public final class Boot implements PrivilegedAction { } catch (LaunchException ex) { // default handler prints this } catch (Exception ex) { - if (JNLPRuntime.isDebug()) - ex.printStackTrace(); - + OutputController.getLogger().log(ex); fatalError(R("RUnexpected", ex.toString(), ex.getStackTrace()[0])); } @@ -235,8 +233,8 @@ public final class Boot implements PrivilegedAction { } private static void fatalError(String message) { - System.err.println("netx: " + message); - System.exit(1); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "netx: " + message); + JNLPRuntime.exit(1); } /** @@ -248,12 +246,11 @@ public final class Boot implements PrivilegedAction { String location = getJNLPFile(); if (location == null) { - System.out.println(helpMessage); - System.exit(1); + OutputController.getLogger().printOutLn(helpMessage); + JNLPRuntime.exit(1); } - if (JNLPRuntime.isDebug()) - System.out.println(R("BFileLoc") + ": " + location); + OutputController.getLogger().log(R("BFileLoc") + ": " + location); URL url = null; @@ -264,9 +261,8 @@ public final class Boot implements PrivilegedAction { else url = new URL(ServiceUtil.getBasicService().getCodeBase(), location); } catch (Exception e) { + OutputController.getLogger().log(e); fatalError("Invalid jnlp file " + location); - if (JNLPRuntime.isDebug()) - e.printStackTrace(); } return url; @@ -278,8 +274,8 @@ public final class Boot implements PrivilegedAction { private static String getJNLPFile() { if (args.length == 0) { - System.out.println(helpMessage); - System.exit(0); + OutputController.getLogger().printOutLn(helpMessage); + JNLPRuntime.exit(0); } else if (args.length == 1) { return args[args.length - 1]; } else { @@ -289,8 +285,8 @@ public final class Boot implements PrivilegedAction { if (doubleArgs.indexOf(secondLastArg) == -1) { return lastArg; } else { - System.out.println(helpMessage); - System.exit(0); + OutputController.getLogger().printOutLn(helpMessage); + JNLPRuntime.exit(0); } } return null; diff --git a/netx/net/sourceforge/jnlp/runtime/CachedJarFileCallback.java b/netx/net/sourceforge/jnlp/runtime/CachedJarFileCallback.java index 7824881..960d9ca 100644 --- a/netx/net/sourceforge/jnlp/runtime/CachedJarFileCallback.java +++ b/netx/net/sourceforge/jnlp/runtime/CachedJarFileCallback.java @@ -49,6 +49,7 @@ import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import net.sourceforge.jnlp.util.logging.OutputController; import net.sourceforge.jnlp.util.JarFile; import net.sourceforge.jnlp.util.UrlUtils; @@ -103,9 +104,8 @@ final class CachedJarFileCallback implements URLJarFileCallBack { // 2) For the plug-in, we want to cache files from class-path so we do it manually returnFile.getManifest().getMainAttributes().putValue("Class-Path", ""); - if (JNLPRuntime.isDebug()) { - System.err.println("Class-Path attribute cleared for " + returnFile.getName()); - } + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Class-Path attribute cleared for " + returnFile.getName()); + } catch (NullPointerException npe) { // Discard NPE here. Maybe there was no manifest, maybe there were no attributes, etc. diff --git a/netx/net/sourceforge/jnlp/runtime/FakePacEvaluator.java b/netx/net/sourceforge/jnlp/runtime/FakePacEvaluator.java index 98ff9d1..5d79344 100644 --- a/netx/net/sourceforge/jnlp/runtime/FakePacEvaluator.java +++ b/netx/net/sourceforge/jnlp/runtime/FakePacEvaluator.java @@ -39,6 +39,7 @@ package net.sourceforge.jnlp.runtime; import static net.sourceforge.jnlp.runtime.Translator.R; import java.net.URL; +import net.sourceforge.jnlp.util.logging.OutputController; /** * A dummy PacEvaluator that always returns "DIRECT" @@ -46,9 +47,7 @@ import java.net.URL; public class FakePacEvaluator implements PacEvaluator { @Override public String getProxies(URL url) { - if (JNLPRuntime.isDebug()) { - System.err.println(R("RPRoxyPacNotSupported")); - } + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, R("RPRoxyPacNotSupported")); return "DIRECT"; } } diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java index 4efa435..c387b35 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java @@ -92,6 +92,7 @@ import net.sourceforge.jnlp.security.PluginAppVerifier; import net.sourceforge.jnlp.security.SecurityDialogs; import net.sourceforge.jnlp.tools.JarCertVerifier; import net.sourceforge.jnlp.util.FileUtils; +import net.sourceforge.jnlp.util.logging.OutputController; import net.sourceforge.jnlp.util.StreamUtils; import sun.misc.JarIndex; @@ -223,8 +224,7 @@ public class JNLPClassLoader extends URLClassLoader { protected JNLPClassLoader(JNLPFile file, UpdatePolicy policy, String mainName) throws LaunchException { super(new URL[0], JNLPClassLoader.class.getClassLoader()); - if (JNLPRuntime.isDebug()) - System.out.println("New classloader: " + file.getFileLocation()); + OutputController.getLogger().log("New classloader: " + file.getFileLocation()); this.file = file; this.updatePolicy = policy; @@ -508,7 +508,7 @@ public class JNLPClassLoader extends URLClassLoader { JNLPClassLoader loader = getInstance(ext[i].getLocation(), uniqueKey, ext[i].getVersion(), file.getParserSettings(), updatePolicy, mainClass); loaderList.add(loader); } catch (Exception ex) { - ex.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, ex); } } //} @@ -527,11 +527,10 @@ public class JNLPClassLoader extends URLClassLoader { Permission p = CacheUtil.getReadPermission(jars[i].getLocation(), jars[i].getVersion()); - if (JNLPRuntime.isDebug()) { - if (p == null) - System.out.println("Unable to add permission for " + jars[i].getLocation()); - else - System.out.println("Permission added: " + p.toString()); + if (p == null) { + OutputController.getLogger().log("Unable to add permission for " + jars[i].getLocation()); + } else { + OutputController.getLogger().log("Permission added: " + p.toString()); } if (p != null) resourcePermissions.add(p); @@ -583,8 +582,8 @@ public class JNLPClassLoader extends URLClassLoader { try { addToCodeBaseLoader(new URL(file.getCodeBase(), codeBaseFolder)); } catch (MalformedURLException mfe) { - System.err.println("Problem trying to add folder to code base:"); - System.err.println(mfe.getMessage()); + OutputController.getLogger().log(OutputController.Level.WARNING_ALL, "Problem trying to add folder to code base:"); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, mfe); } } } @@ -663,7 +662,7 @@ public class JNLPClassLoader extends URLClassLoader { //we caught an Exception from the JarCertVerifier class. //Note: one of these exceptions could be from not being able //to read the cacerts or trusted.certs files. - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); throw new LaunchException(null, null, R("LSFatal"), R("LCInit"), R("LFatalVerification"), R("LFatalVerificationInfo") + ": " +e.getMessage()); } @@ -727,12 +726,12 @@ public class JNLPClassLoader extends URLClassLoader { cachedFile = tracker.getCacheFile(jarDesc.getLocation()); } catch (IllegalResourceDescriptorException irde){ //Caused by ignored resource being removed due to not being valid - System.err.println("JAR " + jarDesc.getLocation() + " is not a valid jar file. Continuing."); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "JAR " + jarDesc.getLocation() + " is not a valid jar file. Continuing."); continue; } if (cachedFile == null) { - System.err.println("JAR " + jarDesc.getLocation() + " not found. Continuing."); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "JAR " + jarDesc.getLocation() + " not found. Continuing."); continue; // JAR not found. Keep going. } @@ -765,7 +764,7 @@ public class JNLPClassLoader extends URLClassLoader { jarLocationSecurityMap.put(jarDesc.getLocation(), jarSecurity); } catch (MalformedURLException mfe) { - System.err.println(mfe.getMessage()); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, mfe); } } activateJars(initialJars); @@ -832,7 +831,7 @@ public class JNLPClassLoader extends URLClassLoader { .getCacheFile(jars.get(i).getLocation()); if (localFile == null) { - System.err.println("JAR " + jars.get(i).getLocation() + " not found. Continuing."); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "JAR " + jars.get(i).getLocation() + " not found. Continuing."); continue; // JAR not found. Keep going. } @@ -942,14 +941,12 @@ public class JNLPClassLoader extends URLClassLoader { if (jeName.equals(TEMPLATE) || jeName.equals(APPLICATION)) { - if (JNLPRuntime.isDebug()) - System.err.println("Creating Jar InputStream from JarEntry"); + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Creating Jar InputStream from JarEntry"); inStream = jarFile.getInputStream(je); inputReader = new InputStreamReader(inStream); - if (JNLPRuntime.isDebug()) - System.err.println("Creating File InputStream from lauching JNLP file"); + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Creating File InputStream from lauching JNLP file"); JNLPFile jnlp = this.getJNLPFile(); URL url = jnlp.getFileLocation(); @@ -968,13 +965,11 @@ public class JNLPClassLoader extends URLClassLoader { JNLPMatcher matcher; if (jeName.equals(APPLICATION)) { // If signed application was found - if (JNLPRuntime.isDebug()) - System.err.println("APPLICATION.JNLP has been located within signed JAR. Starting verfication..."); + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "APPLICATION.JNLP has been located within signed JAR. Starting verfication..."); matcher = new JNLPMatcher(inputReader, jnlpReader, false); } else { // Otherwise template was found - if (JNLPRuntime.isDebug()) - System.err.println("APPLICATION_TEMPLATE.JNLP has been located within signed JAR. Starting verfication..."); + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "APPLICATION_TEMPLATE.JNLP has been located within signed JAR. Starting verfication..."); matcher = new JNLPMatcher(inputReader, jnlpReader, true); @@ -985,8 +980,7 @@ public class JNLPClassLoader extends URLClassLoader { throw new JNLPMatcherException("Signed Application did not match launching JNLP File"); this.isSignedJNLP = true; - if (JNLPRuntime.isDebug()) - System.err.println("Signed Application Verification Successful"); + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Signed Application Verification Successful"); break; } @@ -1009,8 +1003,7 @@ public class JNLPClassLoader extends URLClassLoader { } catch (Exception e) { - if (JNLPRuntime.isDebug()) - e.printStackTrace(System.err); + OutputController.getLogger().log(e); /* * After this exception is caught, it is escaped. If an exception is @@ -1028,8 +1021,7 @@ public class JNLPClassLoader extends URLClassLoader { StreamUtils.closeSilently(jnlpReader); } - if (JNLPRuntime.isDebug()) - System.err.println("Ending check for signed JNLP file..."); + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Ending check for signed JNLP file..."); } /** @@ -1061,10 +1053,7 @@ public class JNLPClassLoader extends URLClassLoader { */ public void setApplication(ApplicationInstance app) { if (this.app != null) { - if (JNLPRuntime.isDebug()) { - Exception ex = new IllegalStateException("Application can only be set once"); - ex.printStackTrace(); - } + OutputController.getLogger().log(new IllegalStateException("Application can only be set once")); return; } @@ -1118,9 +1107,7 @@ public class JNLPClassLoader extends URLClassLoader { throw new NullPointerException("Code source security was null"); } if (getCodeSourceSecurity(cs.getLocation()).getSecurityType() == null) { - if (JNLPRuntime.isDebug()){ - new NullPointerException("Warning! Code source security type was null").printStackTrace(); - } + OutputController.getLogger().log(new NullPointerException("Warning! Code source security type was null")); } Object securityType = getCodeSourceSecurity(cs.getLocation()).getSecurityType(); if (SecurityDesc.ALL_PERMISSIONS.equals(securityType) @@ -1153,9 +1140,7 @@ public class JNLPClassLoader extends URLClassLoader { return result; } catch (RuntimeException ex) { - if (JNLPRuntime.isDebug()) { - ex.printStackTrace(); - } + OutputController.getLogger().log(ex); throw ex; } } @@ -1287,10 +1272,8 @@ public class JNLPClassLoader extends URLClassLoader { jarLocationSecurityMap.put(fakeRemote, jarSecurity); } catch (MalformedURLException mfue) { - if (JNLPRuntime.isDebug()) - System.err.println("Unable to add extracted nested jar to classpath"); - - mfue.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.WARNING_DEBUG, "Unable to add extracted nested jar to classpath"); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, mfue); } } @@ -1327,12 +1310,10 @@ public class JNLPClassLoader extends URLClassLoader { CachedJarFileCallback.getInstance().addMapping(jar.getLocation(), jar.getLocation()); } - if (JNLPRuntime.isDebug()) - System.err.println("Activate jar: " + location); + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Activate jar: " + location); } catch (Exception ex) { - if (JNLPRuntime.isDebug()) - ex.printStackTrace(); + OutputController.getLogger().log(ex); } // some programs place a native library in any jar @@ -1471,9 +1452,7 @@ public class JNLPClassLoader extends URLClassLoader { result = loadClassExt(name); return result; } catch (ClassNotFoundException cnfe1) { - if (JNLPRuntime.isDebug()) { - cnfe1.printStackTrace(); - } + OutputController.getLogger().log(cnfe1); } // As a last resort, look in any available indexes @@ -1497,9 +1476,7 @@ public class JNLPClassLoader extends URLClassLoader { try { addNewJar(desc); } catch (Exception e) { - if (JNLPRuntime.isDebug()) { - e.printStackTrace(); - } + OutputController.getLogger().log(e); } } @@ -1604,7 +1581,7 @@ public class JNLPClassLoader extends URLClassLoader { // throw additional exceptions. So instead, just ignore it. // Exception => jar will not get added to classpath, which will // result in CNFE from loadClass. - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } } @@ -1628,7 +1605,7 @@ public class JNLPClassLoader extends URLClassLoader { } } catch (ClassNotFoundException ex) { } catch (ClassFormatError cfe) { - cfe.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, cfe); } catch (PrivilegedActionException pae) { } catch (NullJnlpFileException ex) { throw new ClassNotFoundException(this.mainClass + " in main classloader ", ex); @@ -1702,9 +1679,7 @@ public class JNLPClassLoader extends URLClassLoader { result = e.nextElement(); } } catch (IOException e) { - if (JNLPRuntime.isDebug()) { - e.printStackTrace(); - } + OutputController.getLogger().log(e); } // If result is still null, look in the codebase loader @@ -1728,7 +1703,7 @@ public class JNLPClassLoader extends URLClassLoader { resources = findResourcesBySearching(name); } } catch (LaunchException le) { - le.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, le); } return resources; @@ -1889,22 +1864,18 @@ public class JNLPClassLoader extends URLClassLoader { if (sec == null && !alreadyTried.contains(source)) { alreadyTried.add(source); //try to load the jar which is requesting the permissions, but was NOT downloaded by standard way - if (JNLPRuntime.isDebug()) { - System.out.println("Application is trying to get permissions for " + source.toString() + ", which was not added by standard way. Trying to download and verify!"); - } + OutputController.getLogger().log("Application is trying to get permissions for " + source.toString() + ", which was not added by standard way. Trying to download and verify!"); try { JARDesc des = new JARDesc(source, null, null, false, false, false, false); addNewJar(des); sec = jarLocationSecurityMap.get(source); } catch (Throwable t) { - if (JNLPRuntime.isDebug()) { - t.printStackTrace(); - } + OutputController.getLogger().log(t); sec = null; } } if (sec == null){ - System.out.println(Translator.R("LNoSecInstance",source.toString())); + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, Translator.R("LNoSecInstance",source.toString())); } return sec; } @@ -2039,10 +2010,8 @@ public class JNLPClassLoader extends URLClassLoader { try { tracker.removeResource(eachJar.getLocation()); } catch (Exception e) { - if (JNLPRuntime.isDebug()) { - System.err.println(e.getMessage()); - System.err.println("Failed to remove resource from tracker, continuing.."); - } + OutputController.getLogger().log(e); + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Failed to remove resource from tracker, continuing.."); } File cachedFile = CacheUtil.getCacheFile(eachJar.getLocation(), null); @@ -2050,13 +2019,11 @@ public class JNLPClassLoader extends URLClassLoader { File directory = new File(directoryUrl); - if (JNLPRuntime.isDebug()) - System.out.println("Deleting cached file: " + cachedFile.getAbsolutePath()); + OutputController.getLogger().log("Deleting cached file: " + cachedFile.getAbsolutePath()); cachedFile.delete(); - if (JNLPRuntime.isDebug()) - System.out.println("Deleting cached directory: " + directory.getAbsolutePath()); + OutputController.getLogger().log("Deleting cached directory: " + directory.getAbsolutePath()); directory.delete(); } @@ -2074,8 +2041,7 @@ public class JNLPClassLoader extends URLClassLoader { JARDesc[] jars = ManageJnlpResources.findJars(this, ref, part, version); for (JARDesc eachJar : jars) { - if (JNLPRuntime.isDebug()) - System.out.println("Downloading and initializing jar: " + eachJar.getLocation().toString()); + OutputController.getLogger().log("Downloading and initializing jar: " + eachJar.getLocation().toString()); this.addNewJar(eachJar, UpdatePolicy.FORCE); } @@ -2107,8 +2073,7 @@ public class JNLPClassLoader extends URLClassLoader { if (action == DownloadAction.DOWNLOAD_TO_CACHE) { JARDesc jarToCache = new JARDesc(ref, resourceVersion, null, false, true, false, true); - if (JNLPRuntime.isDebug()) - System.out.println("Downloading and initializing jar: " + ref.toString()); + OutputController.getLogger().log("Downloading and initializing jar: " + ref.toString()); foundLoader.addNewJar(jarToCache, UpdatePolicy.FORCE); diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPPolicy.java b/netx/net/sourceforge/jnlp/runtime/JNLPPolicy.java index ba9b53e..59b8c87 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPPolicy.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPPolicy.java @@ -23,6 +23,7 @@ import java.security.*; import java.util.Enumeration; import net.sourceforge.jnlp.config.DeploymentConfiguration; +import net.sourceforge.jnlp.util.logging.OutputController; /** * Policy for JNLP environment. This class delegates to the @@ -167,11 +168,11 @@ public class JNLPPolicy extends Policy { URI policyUri = new URI(policyLocation); policy = getInstance("JavaPolicy", new URIParameter(policyUri)); } catch (IllegalArgumentException e) { - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } catch (URISyntaxException e) { - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } } return policy; diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPProxySelector.java b/netx/net/sourceforge/jnlp/runtime/JNLPProxySelector.java index efcf62e..e92b2c9 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPProxySelector.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPProxySelector.java @@ -33,6 +33,7 @@ import java.util.List; import java.util.StringTokenizer; import net.sourceforge.jnlp.config.DeploymentConfiguration; +import net.sourceforge.jnlp.util.logging.OutputController; /** * A ProxySelector specific to JNLPs. This proxy uses the deployment @@ -97,7 +98,7 @@ public abstract class JNLPProxySelector extends ProxySelector { try { autoConfigUrl = new URL(autoConfigString); } catch (MalformedURLException e) { - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } } @@ -159,7 +160,7 @@ public abstract class JNLPProxySelector extends ProxySelector { try { proxyPort = Integer.valueOf(port); } catch (NumberFormatException e) { - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } } return proxyPort; @@ -170,7 +171,7 @@ public abstract class JNLPProxySelector extends ProxySelector { */ @Override public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { - ioe.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, ioe); } /** @@ -178,15 +179,11 @@ public abstract class JNLPProxySelector extends ProxySelector { */ @Override public List select(URI uri) { - if (JNLPRuntime.isDebug()) { - System.out.println("Selecting proxy for: " + uri); - } - + OutputController.getLogger().log("Selecting proxy for: " + uri); + if (inBypassList(uri)) { List proxies = Arrays.asList(new Proxy[] { Proxy.NO_PROXY }); - if (JNLPRuntime.isDebug()) { - System.out.println("Selected proxies: " + Arrays.toString(proxies.toArray())); - } + OutputController.getLogger().log("Selected proxies: " + Arrays.toString(proxies.toArray())); return proxies; } @@ -211,9 +208,7 @@ public abstract class JNLPProxySelector extends ProxySelector { break; } - if (JNLPRuntime.isDebug()) { - System.out.println("Selected proxies: " + Arrays.toString(proxies.toArray())); - } + OutputController.getLogger().log("Selected proxies: " + Arrays.toString(proxies.toArray())); return proxies; } @@ -344,7 +339,7 @@ public abstract class JNLPProxySelector extends ProxySelector { String proxiesString = pacEvaluator.getProxies(uri.toURL()); proxies.addAll(getProxiesFromPacResult(proxiesString)); } catch (MalformedURLException e) { - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); proxies.add(Proxy.NO_PROXY); } @@ -403,9 +398,7 @@ public abstract class JNLPProxySelector extends ProxySelector { } else if (token.startsWith("DIRECT")) { proxies.add(Proxy.NO_PROXY); } else { - if (JNLPRuntime.isDebug()) { - System.out.println("Unrecognized proxy token: " + token); - } + OutputController.getLogger().log("Unrecognized proxy token: " + token); } } diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java index a2fcb7d..a79663b 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java @@ -67,7 +67,9 @@ import net.sourceforge.jnlp.security.SecurityDialogMessageHandler; import net.sourceforge.jnlp.security.VariableX509TrustManager; import net.sourceforge.jnlp.services.XServiceManagerStub; import net.sourceforge.jnlp.util.FileUtils; +import net.sourceforge.jnlp.util.logging.OutputController; import net.sourceforge.jnlp.util.TeeOutputStream; +import net.sourceforge.jnlp.util.logging.LogConfig; import sun.net.www.protocol.jar.URLJarFile; /** @@ -87,7 +89,7 @@ import sun.net.www.protocol.jar.URLJarFile; * @version $Revision: 1.19 $ */ public class JNLPRuntime { - + static { loadResources(); } @@ -129,11 +131,12 @@ public class JNLPRuntime { /** whether debug mode is on */ private static boolean debug = false; + /** + * whether plugin debug mode is on + */ + private static Boolean pluginDebug = null; - /** whether streams should be redirected */ - private static boolean redirectStreams = false; - - /** mutex to wait on, for initialization */ + /** mutex to wait on, for initialization */ public static Object initMutex = new Object(); /** set to true if this is a webstart application. */ @@ -196,15 +199,13 @@ public class JNLPRuntime { } catch (ConfigurationException e) { /* exit if there is a fatal exception loading the configuration */ if (isApplication) { - System.out.println(getMessage("RConfigurationError")); - System.exit(1); + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, getMessage("RConfigurationError")); + JNLPRuntime.exit(1); } } KeyStores.setConfiguration(config); - initializeStreams(); - isWebstartApplication = isApplication; //Setting the system property for javawebstart's version. @@ -220,9 +221,9 @@ public class JNLPRuntime { if (handler == null) { if (headless) { - handler = new DefaultLaunchHandler(System.err); + handler = new DefaultLaunchHandler(OutputController.getLogger()); } else { - handler = new GuiLaunchHandler(System.err); + handler = new GuiLaunchHandler(OutputController.getLogger()); } } @@ -234,7 +235,7 @@ public class JNLPRuntime { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } doMainAppContextHacks(); @@ -259,8 +260,8 @@ public class JNLPRuntime { HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory); } catch (Exception e) { - System.err.println("Unable to set SSLSocketfactory (may _prevent_ access to sites that should be trusted)! Continuing anyway..."); - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "Unable to set SSLSocketfactory (may _prevent_ access to sites that should be trusted)! Continuing anyway..."); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } // plug in a custom authenticator and proxy selector @@ -294,14 +295,14 @@ public class JNLPRuntime { try { trustManagerClass = Class.forName("net.sourceforge.jnlp.security.VariableX509TrustManagerJDK6"); } catch (ClassNotFoundException cnfe) { - System.err.println("Unable to find class net.sourceforge.jnlp.security.VariableX509TrustManagerJDK6"); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "Unable to find class net.sourceforge.jnlp.security.VariableX509TrustManagerJDK6"); return null; } } else { // Java 7 or more (technically could be <= 1.5 but <= 1.5 is unsupported) try { trustManagerClass = Class.forName("net.sourceforge.jnlp.security.VariableX509TrustManagerJDK7"); } catch (ClassNotFoundException cnfe) { - System.err.println("Unable to find class net.sourceforge.jnlp.security.VariableX509TrustManagerJDK7"); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "Unable to find class net.sourceforge.jnlp.security.VariableX509TrustManagerJDK7"); return null; } } @@ -318,7 +319,8 @@ public class JNLPRuntime { return (TrustManager) tmCtor.newInstance(); } catch (RuntimeException e) { - System.err.println("Unable to load JDK-specific TrustManager. Was this version of IcedTea-Web compiled with JDK6?"); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "Unable to load JDK-specific TrustManager. Was this version of IcedTea-Web compiled with JDK 6 or 7?"); + OutputController.getLogger().log(e); throw e; } } @@ -357,37 +359,7 @@ public class JNLPRuntime { new ParserDelegator(); } - /** - * Initializes the standard output and error streams, redirecting them or - * duplicating them as required. - */ - private static void initializeStreams() { - Boolean enableLogging = Boolean.valueOf(config - .getProperty(DeploymentConfiguration.KEY_ENABLE_LOGGING)); - if (redirectStreams || enableLogging) { - String logDir = config.getProperty(DeploymentConfiguration.KEY_USER_LOG_DIR); - - try { - File errFile = new File(logDir, JNLPRuntime.STDERR_FILE); - FileUtils.createParentDir(errFile); - FileUtils.createRestrictedFile(errFile, true); - File outFile = new File(logDir, JNLPRuntime.STDOUT_FILE); - FileUtils.createParentDir(outFile); - FileUtils.createRestrictedFile(outFile, true); - - if (redirectStreams) { - System.setErr(new PrintStream(new FileOutputStream(errFile))); - System.setOut(new PrintStream(new FileOutputStream(outFile))); - } else { - System.setErr(new TeeOutputStream(new FileOutputStream(errFile), System.err)); - System.setOut(new TeeOutputStream(new FileOutputStream(outFile), System.out)); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - + /** * Gets the Configuration associated with this runtime * @return a {@link DeploymentConfiguration} object that can be queried to @@ -513,6 +485,10 @@ public class JNLPRuntime { * should be printed. */ public static boolean isDebug() { + return isSetDebug() || isPluginDebug() || LogConfig.getLogConfig().isEnableLogging(); + } + + public static boolean isSetDebug() { return debug; } @@ -527,17 +503,7 @@ public class JNLPRuntime { debug = enabled; } - /** - * Sets whether the standard output/error streams should be redirected to - * the loggging files. - * - * @throws IllegalStateException if the runtime has already been initialized - */ - public static void setRedirectStreams(boolean redirect) { - checkInitialized(); - redirectStreams = redirect; - } - + /** * Sets the default update policy. * @@ -737,13 +703,11 @@ public class JNLPRuntime { } if (fileLock != null && fileLock.isShared()) { - if (JNLPRuntime.isDebug()) { - System.out.println("Acquired shared lock on " + + OutputController.getLogger().log("Acquired shared lock on " + netxRunningFile.toString() + " to indicate javaws is running"); - } } } catch (IOException e) { - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } Runtime.getRuntime().addShutdownHook(new Thread("JNLPRuntimeShutdownHookThread") { @@ -766,13 +730,10 @@ public class JNLPRuntime { fileLock.release(); fileLock.channel().close(); fileLock = null; - if (JNLPRuntime.isDebug()) { - String file = JNLPRuntime.getConfiguration() - .getProperty(DeploymentConfiguration.KEY_USER_NETX_RUNNING_FILE); - System.out.println("Release shared lock on " + file); - } + OutputController.getLogger().log("Release shared lock on " + JNLPRuntime.getConfiguration() + .getProperty(DeploymentConfiguration.KEY_USER_NETX_RUNNING_FILE)); } catch (IOException e) { - e.printStackTrace(); + OutputController.getLogger().log(e); } } @@ -791,7 +752,24 @@ public class JNLPRuntime { public static void setIgnoreHeaders(boolean ignoreHeaders) { JNLPRuntime.ignoreHeaders = ignoreHeaders; } - - + + public static boolean isPluginDebug() { + if (pluginDebug == null) { + try { + //there are cases when this itself is not allowed by security manager, and so + //throws exception. Under some conditions it can couse deadlock + pluginDebug = System.getenv().containsKey("ICEDTEAPLUGIN_DEBUG"); + } catch (Exception ex) { + pluginDebug = false; + OutputController.getLogger().log(ex); + } + } + return pluginDebug; + } + + public static void exit(int i) { + OutputController.getLogger().close(); + System.exit(i); + } } diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java b/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java index 6842f2c..5c69b01 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java @@ -32,6 +32,7 @@ import javax.swing.JWindow; import net.sourceforge.jnlp.JNLPFile; import net.sourceforge.jnlp.security.SecurityDialogs.AccessType; import net.sourceforge.jnlp.services.ServiceUtil; +import net.sourceforge.jnlp.util.logging.OutputController; import net.sourceforge.jnlp.util.WeakList; import sun.awt.AWTSecurityManager; import sun.awt.AppContext; @@ -263,7 +264,7 @@ class JNLPSecurityManager extends AWTSecurityManager { // Enable this manually -- it'll produce too much output for -verbose // otherwise. // if (true) - // System.out.println("Checking permission: " + perm.toString()); + // OutputController.getLogger().log("Checking permission: " + perm.toString()); if (!JNLPRuntime.isWebstartApplication() && ("setPolicy".equals(name) || "setSecurityManager".equals(name))) @@ -283,9 +284,7 @@ class JNLPSecurityManager extends AWTSecurityManager { super.checkPermission(perm); } catch (SecurityException ex) { - if (JNLPRuntime.isDebug()) { - System.out.println("Denying permission: " + perm); - } + OutputController.getLogger().log("Denying permission: " + perm); throw ex; } } @@ -318,14 +317,14 @@ class JNLPSecurityManager extends AWTSecurityManager { JNLPClassLoader cl = (JNLPClassLoader) JNLPRuntime.getApplication().getClassLoader(); cl.addPermission(perm); if (JNLPRuntime.isDebug()) { - if (cl.getPermissions(null).implies(perm)) - System.err.println("Added permission: " + perm.toString()); - else - System.err.println("Unable to add permission: " + perm.toString()); + if (cl.getPermissions(null).implies(perm)){ + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "Added permission: " + perm.toString()); + } else { + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "Unable to add permission: " + perm.toString()); + } } } else { - if (JNLPRuntime.isDebug()) - System.err.println("Unable to add permission: " + perm + ", classloader not JNLP."); + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Unable to add permission: " + perm + ", classloader not JNLP."); } } @@ -341,8 +340,7 @@ class JNLPSecurityManager extends AWTSecurityManager { if (app != null && window instanceof Window) { Window w = (Window) window; - if (JNLPRuntime.isDebug()) - System.err.println("SM: app: " + app.getTitle() + " is adding a window: " + window + " with appContext " + AppContext.getAppContext()); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "SM: app: " + app.getTitle() + " is adding a window: " + window + " with appContext " + AppContext.getAppContext()); weakWindows.add(w); // for mapping window -> app weakApplications.add(app); diff --git a/netx/net/sourceforge/jnlp/runtime/PacEvaluatorFactory.java b/netx/net/sourceforge/jnlp/runtime/PacEvaluatorFactory.java index 9ed6217..a034161 100644 --- a/netx/net/sourceforge/jnlp/runtime/PacEvaluatorFactory.java +++ b/netx/net/sourceforge/jnlp/runtime/PacEvaluatorFactory.java @@ -43,6 +43,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.util.Properties; +import net.sourceforge.jnlp.util.logging.OutputController; public class PacEvaluatorFactory { @@ -60,16 +61,12 @@ public class PacEvaluatorFactory { properties = new Properties(); properties.load(in); } catch (IOException e) { - if (JNLPRuntime.isDebug()) { - e.printStackTrace(); - } + OutputController.getLogger().log(e); } finally { try { in.close(); } catch (IOException e) { - if (JNLPRuntime.isDebug()) { - e.printStackTrace(); - } + OutputController.getLogger().log(e); } } @@ -88,16 +85,16 @@ public class PacEvaluatorFactory { } catch (ClassNotFoundException e) { // ignore } catch (InstantiationException e) { - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } catch (IllegalAccessException e) { - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } catch (NoSuchMethodException e) { - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } catch (IllegalArgumentException e) { - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); } catch (InvocationTargetException e) { if (e.getCause() != null) { - e.getCause().printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e.getCause()); } } } diff --git a/netx/net/sourceforge/jnlp/runtime/RhinoBasedPacEvaluator.java b/netx/net/sourceforge/jnlp/runtime/RhinoBasedPacEvaluator.java index b1c290a..eb4030b 100644 --- a/netx/net/sourceforge/jnlp/runtime/RhinoBasedPacEvaluator.java +++ b/netx/net/sourceforge/jnlp/runtime/RhinoBasedPacEvaluator.java @@ -49,6 +49,7 @@ import java.security.Permissions; import java.security.PrivilegedAction; import java.security.ProtectionDomain; import java.util.PropertyPermission; +import net.sourceforge.jnlp.util.logging.OutputController; import net.sourceforge.jnlp.util.TimedHashMap; @@ -75,9 +76,7 @@ public class RhinoBasedPacEvaluator implements PacEvaluator { * @param pacUrl the url of the PAC file to use */ public RhinoBasedPacEvaluator(URL pacUrl) { - if (JNLPRuntime.isDebug()) { - System.err.println("Using the Rhino based PAC evaluator for url " + pacUrl); - } + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Using the Rhino based PAC evaluator for url " + pacUrl); pacHelperFunctionContents = getHelperFunctionContents(); this.pacUrl = pacUrl; pacContents = getPacContents(pacUrl); @@ -119,7 +118,7 @@ public class RhinoBasedPacEvaluator implements PacEvaluator { */ private String getProxiesWithoutCaching(URL url) { if (pacHelperFunctionContents == null) { - System.err.println("Error loading pac functions"); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "Error loading pac functions"); return "DIRECT"; } @@ -151,7 +150,7 @@ public class RhinoBasedPacEvaluator implements PacEvaluator { BufferedReader pacReader = new BufferedReader(new InputStreamReader(pacUrl.openStream())); try { while ((line = pacReader.readLine()) != null) { - // System.out.println(line); + // OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, line); contents = contents.append(line).append("\n"); } } finally { @@ -181,14 +180,14 @@ public class RhinoBasedPacEvaluator implements PacEvaluator { try { contents = new StringBuilder(); while ((line = pacFuncsReader.readLine()) != null) { - // System.out.println(line); + // OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL,line); contents = contents.append(line).append("\n"); } } finally { pacFuncsReader.close(); } } catch (IOException e) { - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); contents = null; } @@ -249,7 +248,7 @@ public class RhinoBasedPacEvaluator implements PacEvaluator { Object functionObj = scope.get("FindProxyForURL", scope); if (!(functionObj instanceof Function)) { - System.err.println("FindProxyForURL not found"); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, "FindProxyForURL not found"); return null; } else { Function findProxyFunction = (Function) functionObj; @@ -259,7 +258,7 @@ public class RhinoBasedPacEvaluator implements PacEvaluator { return (String) result; } } catch (Exception e) { - e.printStackTrace(); + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e); return "DIRECT"; } finally { Context.exit(); -- cgit v1.2.3