+ appendIfNotNull(sb, "Getdown appdir: ",
+ System.getProperty("getdownappdir"), "\n", null);
+ appendIfNotNull(sb, "Java home: ", System.getProperty("java.home"),
+ "\n", "unknown");
+ }
+ return sb.toString();
+ }
+
+ /**
+ *
+ * @return build details as reported in splashscreen
+ */
+ public static String getBuildDetailsForSplash()
+ {
+ // consider returning more human friendly info
+ // eg 'built from Source' or update channel
+ return jalview.bin.Cache.getDefault("INSTALLATION", "unknown");
+ }
+
+ public static String getStackTraceString(Throwable t)
+ {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ t.printStackTrace(pw);
+ return sw.toString();
+ }
+
+ // proxy properties methods
+ public static void resetProxyProperties()
+ {
+ setProxyProperties(startupProxyProperties[0], startupProxyProperties[1],
+ startupProxyProperties[2], startupProxyProperties[3],
+ startupProxyProperties[4], startupProxyProperties[5],
+ startupProxyProperties[6], startupProxyProperties[7]);
+ StringBuilder sb = new StringBuilder();
+ sb.append("Setting proxy properties to: http.proxyHost=")
+ .append(startupProxyProperties[0]).append(", http.proxyPort=")
+ .append(startupProxyProperties[1])
+ .append(startupProxyProperties[4] != null
+ && !startupProxyProperties[4].isEmpty()
+ ? " [" + startupProxyProperties[4] + "]"
+ : "")
+ .append(", https.proxyHost=").append(startupProxyProperties[2])
+ .append(", https.proxyPort=").append(startupProxyProperties[3])
+ .append(startupProxyProperties[6] != null
+ && !startupProxyProperties[6].isEmpty()
+ ? " [" + startupProxyProperties[6] + "]"
+ : "");
+
+ Cache.debug(sb.toString());
+ }
+
+ public static void setProxyProperties(String httpHost, String httpPort,
+ String httpsHost, String httpsPort, String httpUser,
+ String httpPassword)
+ {
+ setProxyProperties(httpHost, httpPort, httpsHost, httpsPort, httpUser,
+ httpPassword, httpUser, httpPassword);
+ }
+
+ public static void setProxyProperties(String httpHost, String httpPort,
+ String httpsHost, String httpsPort, String httpUser,
+ String httpPassword, String httpsUser, String httpsPassword)
+ {
+ setOrClearSystemProperty("http.proxyHost", httpHost);
+ setOrClearSystemProperty("http.proxyPort", httpPort);
+ setOrClearSystemProperty("https.proxyHost", httpsHost);
+ setOrClearSystemProperty("https.proxyPort", httpsPort);
+ setOrClearSystemProperty("http.proxyUser", httpUser);
+ setOrClearSystemProperty("http.proxyPassword", httpPassword);
+ setOrClearSystemProperty("https.proxyUser", httpsUser);
+ setOrClearSystemProperty("https.proxyPassword", httpsPassword);
+ if (httpUser != null || httpsUser != null)
+ {
+ try
+ {
+ Authenticator.setDefault(new Authenticator()
+ {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication()
+ {
+ if (getRequestorType() == RequestorType.PROXY)
+ {
+ try
+ {
+ if (getRequestingScheme().equalsIgnoreCase("http")
+ && getRequestingHost().equalsIgnoreCase(httpHost)
+ && getRequestingPort() == Integer.valueOf(httpPort))
+ {
+ return new PasswordAuthentication(httpUser,
+ httpPassword == null ? new char[] {}
+ : httpPassword.toCharArray());
+ }
+ if (getRequestingScheme().equalsIgnoreCase("https")
+ && getRequestingHost().equalsIgnoreCase(httpsHost)
+ && getRequestingPort() == Integer
+ .valueOf(httpsPort))
+ {
+ return new PasswordAuthentication(httpsUser,
+ httpsPassword == null ? new char[] {}
+ : httpsPassword.toCharArray());
+ }
+ } catch (NumberFormatException e)
+ {
+ Cache.error("Problem with proxy port values [http:"
+ + httpPort + ", https:" + httpsPort + "]");
+ }
+ }
+ // non proxy request
+ return null;
+ }
+ });
+ // required to re-enable basic authentication (should be okay for a
+ // local proxy)
+ System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
+ } catch (SecurityException e)
+ {
+ Cache.error("Could not set default Authenticator");
+ Cache.debug(getStackTraceString(e));
+ }