wms-bootstrap

16:53:59.386 INFO  jd.cli.Main - Decompiling wms-bootstrap.jar
package com.wowza.wms.bootstrap;

import java.net.URL;
import java.net.URLClassLoader;

public class Bootstrap$BootstrapURLClassLoader
  extends URLClassLoader
{
  public Bootstrap$BootstrapURLClassLoader(URL[] paramArrayOfURL, ClassLoader paramClassLoader)
  {
    super(paramArrayOfURL, paramClassLoader);
  }
  
  public void addURL(URL paramURL)
  {
    super.addURL(paramURL);
  }
}

/* Location:
 * Qualified Name:     com.wowza.wms.bootstrap.Bootstrap.BootstrapURLClassLoader
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.wowza.wms.bootstrap;

public class Bootstrap$ReplaceItem
{
  public int start = 0;
  public int end = 0;
  public String newValue = null;
  
  public Bootstrap$ReplaceItem(int paramInt1, int paramInt2, String paramString)
  {
    start = paramInt1;
    end = paramInt2;
    newValue = paramString;
  }
}

/* Location:
 * Qualified Name:     com.wowza.wms.bootstrap.Bootstrap.ReplaceItem
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.wowza.wms.bootstrap;

import com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import org.apache.commons.lang.SystemUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Bootstrap
{
  public static final int APPHOME = 1;
  public static final int CONFIGHOME = 2;
  public static final String NATIVELIBFOLDER = "lib-native";
  
  public static class ReplaceItem
  {
    public int start = 0;
    public int end = 0;
    public String newValue = null;
    
    public ReplaceItem(int paramInt1, int paramInt2, String paramString)
    {
      start = paramInt1;
      end = paramInt2;
      newValue = paramString;
    }
  }
  
  public static ClassLoader loader = null;
  private static final String CRLF = "\r\n";
  private static final String HTTP_PROTOCOL = "HTTP/1.1";
  private static final String[] hexadecimal = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
  public static final String DATEFORMAT = "EEE, dd MMM yyyy HH:mm:ss";
  
  public static class BootstrapURLClassLoader
    extends URLClassLoader
  {
    public BootstrapURLClassLoader(URL[] paramArrayOfURL, ClassLoader paramClassLoader)
    {
      super(paramClassLoader);
    }
    
    public void addURL(URL paramURL)
    {
      super.addURL(paramURL);
    }
  }
  
  public static void main(String[] paramArrayOfString)
  {
    
    if (paramArrayOfString.length > 0) {
      if (paramArrayOfString[0].equals("start")) {
        startServer();
      } else if (paramArrayOfString[0].equals("stop")) {
        stopServer();
      } else if (paramArrayOfString[0].equals("runTest")) {
        runTest(paramArrayOfString[1]);
      } else if (paramArrayOfString[0].equals("runTestCL")) {
        runTestCL(paramArrayOfString);
      } else if (paramArrayOfString[0].equals("runJUnit")) {
        runJUnit(paramArrayOfString);
      } else if (paramArrayOfString[0].equals("startDebugger")) {
        startDebugger();
      } else if (paramArrayOfString[0].equals("stopDebugger")) {
        stopDebugger();
      } else if (paramArrayOfString[0].equals("outputTuningCommandLine")) {
        BootstrapTuningHandler.outputTuningCommandLine();
      } else if (paramArrayOfString[0].equals("tailLogFile")) {
        tailLogFile();
      }
    }
  }
  
  public static void tailLogFile()
  {
    BootstrapConsoleLogger localBootstrapConsoleLogger = new BootstrapConsoleLogger();
    
    String str1 = getServerHome(1);
    String str2 = str1 + "/conf/log4j.properties";
    
    localBootstrapConsoleLogger.setPropertiesPath(str2);
    localBootstrapConsoleLogger.init();
    for (;;)
    {
      try
      {
        localBootstrapConsoleLogger.run();
      }
      catch (Exception localException1)
      {
        System.out.println("*** ERROR: Bootstrap.tailLogFile[" + str2 + "]: " + localException1.toString());
        break;
      }
      try
      {
        Thread.currentThread();Thread.sleep(750L);
      }
      catch (Exception localException2) {}
    }
  }
  
  private static void doWait()
  {
    try
    {
      Thread.sleep(5000L);
    }
    catch (Exception localException) {}
  }
  
  public static boolean isRunModeService()
  {
    boolean bool = false;
    String str = System.getProperty("com.wowza.wms.runmode");
    if (str != null) {
      if (str.equals("service")) {
        bool = true;
      }
    }
    return bool;
  }
  
  public static boolean isNativeWindows()
  {
    boolean bool = false;
    
    String str = getNativeOS();
    if (str != null) {
      if ("win".equals(str)) {
        bool = true;
      }
    }
    return bool;
  }
  
  public static boolean isNativeLinux()
  {
    boolean bool = false;
    
    String str = getNativeOS();
    if (str != null) {
      if ("linux".equals(str)) {
        bool = true;
      }
    }
    return bool;
  }
  
  public static boolean isNativeOSX()
  {
    boolean bool = false;
    
    String str = getNativeOS();
    if (str != null) {
      if ("osx".equals(str)) {
        bool = true;
      }
    }
    return bool;
  }
  
  private static String expandEnvironmentVariables(String paramString)
  {
    Pattern localPattern = Pattern.compile("\\$\\{[^}]*\\}");
    Matcher localMatcher = localPattern.matcher(paramString);
    while (localMatcher.find())
    {
      String str = localMatcher.group().substring(2, localMatcher.group().length() - 1);
      paramString = paramString.substring(0, localMatcher.start()) + System.getProperty(str) + paramString.substring(localMatcher.end());
    }
    return paramString;
  }
  
  private static ClassLoader createClassLoader(Map paramMap)
  {
    Object localObject1 = null;
    ArrayList localArrayList = new ArrayList();
    try
    {
      String str1 = getServerHome(1);
      String str2 = (str1 == null ? "" : str1) + File.separatorChar + "lib" + File.separatorChar;
      String str3 = (str1 == null ? "" : str1) + File.separatorChar + "lib-license" + File.separatorChar;
      
      boolean bool = new File(str2).exists();
      Object localObject8;
      Object localObject4;
      Object localObject9;
      Object localObject10;
      String str4;
      Object localObject11;
      Object localObject13;
      if (bool)
      {
        localObject2 = new File(str2);
        if (((File)localObject2).exists())
        {
          localObject3 = ((File)localObject2).listFiles();
          for (int i = 0; i < localObject3.length; i++)
          {
            Object localObject6 = localObject3[i];
            localObject8 = ((File)localObject6).toString();
            if ((!((File)localObject6).isDirectory()) && ((((String)localObject8).toLowerCase().endsWith(".jar")) || (((String)localObject8).toLowerCase().endsWith(".xml")) || (((String)localObject8).toLowerCase().endsWith(".properties")) || (((String)localObject8).toLowerCase().endsWith(".class")))) {
              localArrayList.add(((File)localObject6).toURL());
            }
          }
        }
        localObject3 = new File(str3);
        if (((File)localObject3).exists())
        {
          localObject4 = ((File)localObject3).listFiles();
          for (int j = 0; j < localObject4.length; j++)
          {
            localObject8 = localObject4[j];
            localObject9 = ((File)localObject8).toString();
            if ((!((File)localObject8).isDirectory()) && ((((String)localObject9).toLowerCase().endsWith(".jar")) || (((String)localObject9).toLowerCase().endsWith(".xml")) || (((String)localObject9).toLowerCase().endsWith(".properties")) || (((String)localObject9).toLowerCase().endsWith(".class")))) {
              localArrayList.add(((File)localObject8).toURL());
            }
          }
        }
      }
      else
      {
        localObject2 = getConfigURL();
        localObject3 = localObject2;
        if (((String)localObject3).indexOf("?") >= 0) {
          localObject3 = (String)localObject3 + "&";
        } else {
          localObject3 = (String)localObject3 + "?";
        }
        localObject3 = (String)localObject3 + "context=server&filename=" + encodeValue("conf/LibFolder.xml");
        try
        {
          localObject4 = DocumentBuilderFactory.newInstance();
          localObject7 = ((DocumentBuilderFactory)localObject4).newDocumentBuilder();
          
          localObject8 = ((DocumentBuilder)localObject7).parse((String)localObject3);
          
          localObject9 = newXPathFactory();
          localObject10 = ((XPathFactory)localObject9).newXPath();
          if (localObject8 != null)
          {
            Element localElement = ((Document)localObject8).getDocumentElement();
            str4 = "/Root/LibFolder/Lib";
            localObject11 = ((XPath)localObject10).compile(str4);
            
            NodeList localNodeList = (NodeList)((XPathExpression)localObject11).evaluate(localElement, XPathConstants.NODESET);
            if (localNodeList != null) {
              for (int n = 0; n < localNodeList.getLength(); n++)
              {
                localObject13 = localNodeList.item(n);
                String str5 = getNodeValue((Node)localObject13);
                
                localArrayList.add(new URL(str5));
              }
            }
          }
        }
        catch (Exception localException2)
        {
          System.out.println("Error parsing LibFolder.xml: " + localException2.toString());
          localException2.printStackTrace();
          doWait();
        }
      }
      Object localObject2 = (Map)paramMap.get("VHosts");
      if (localObject2 != null)
      {
        localObject3 = ((Map)localObject2).keySet().iterator();
        while (((Iterator)localObject3).hasNext())
        {
          localObject5 = (Map)((Map)localObject2).get(((Iterator)localObject3).next());
          localObject7 = expandEnvironmentVariables((String)((Map)localObject5).get("ConfigDir"));
          
          localObject8 = (String)localObject7 + File.separatorChar + "applications";
          localObject9 = new File((String)localObject8);
          if ((((File)localObject9).exists()) && (((File)localObject9).isDirectory()))
          {
            localObject10 = ((File)localObject9).listFiles();
            for (int k = 0; k < localObject10.length; k++)
            {
              str4 = localObject10[k];
              if (str4.isDirectory())
              {
                localObject11 = str4.listFiles();
                for (int m = 0; m < localObject11.length; m++)
                {
                  Object localObject12 = localObject11[m];
                  localObject13 = ((File)localObject12).toString();
                  if ((!((File)localObject12).isDirectory()) && ((((String)localObject13).toLowerCase().endsWith(".jar")) || (((String)localObject13).toLowerCase().endsWith(".xml")) || (((String)localObject13).toLowerCase().endsWith(".properties")) || (((String)localObject13).toLowerCase().endsWith(".class")))) {
                    localArrayList.add(((File)localObject12).toURL());
                  }
                }
              }
            }
          }
          else
          {
            System.out.println("Error: applications folder missing: " + localObject9);
          }
        }
      }
      Object localObject3 = (URL[])localArrayList.toArray(new URL[localArrayList.size()]);
      
      Object localObject5 = Thread.currentThread().getContextClassLoader();
      Object localObject7 = new BootstrapURLClassLoader((URL[])localObject3, (ClassLoader)localObject5);
      
      Thread.currentThread().setContextClassLoader((ClassLoader)localObject7);
      
      localObject1 = localObject7;
    }
    catch (Exception localException1)
    {
      System.out.println("Error creating class loader: " + localException1);
      localException1.printStackTrace();
      doWait();
    }
    return (ClassLoader)localObject1;
  }
  
  public static boolean loadJar(File paramFile)
  {
    boolean bool = false;
    if (paramFile.exists()) {
      if ((loader instanceof BootstrapURLClassLoader))
      {
        BootstrapURLClassLoader localBootstrapURLClassLoader = (BootstrapURLClassLoader)loader;
        
        URL localURL = null;
        try
        {
          localURL = paramFile.toURL();
        }
        catch (Exception localException1) {}
        if (localURL != null)
        {
          URL[] arrayOfURL = localBootstrapURLClassLoader.getURLs();
          
          int i = 0;
          if (arrayOfURL != null) {
            for (int j = 0; j < arrayOfURL.length; j++) {
              if (arrayOfURL[j].toString().equals(localURL.toString()))
              {
                i = 0;
                break;
              }
            }
          }
          if (i == 0) {
            try
            {
              localBootstrapURLClassLoader.addURL(localURL);
            }
            catch (Exception localException2)
            {
              return bool;
            }
          }
          bool = true;
        }
      }
    }
    return bool;
  }
  
  public static Class findClass(String paramString)
  {
    Class localClass = null;
    try
    {
      if (loader != null) {
        localClass = loader.loadClass(paramString);
      } else {
        System.out.println("Bootstrap.findClass (" + paramString + "): Class loader is null");
      }
    }
    catch (Exception localException)
    {
      System.out.println("Bootstrap.findClass (" + paramString + "): " + localException);
      localException.printStackTrace();
    }
    return localClass;
  }
  
  private static void startServer()
  {
    try
    {
      Map localMap = getServerInfo();
      if (localMap != null)
      {
        loader = createClassLoader(localMap);
        
        String str = "com.wowza.wms.server.Server";
        Class localClass = loader.loadClass(str);
        Method localMethod = localClass.getMethod("start", new Class[0]);
        localMethod.invoke(null, (Object[])null);
      }
    }
    catch (Exception localException)
    {
      System.out.println("Error starting: " + localException);
      localException.printStackTrace();
      doWait();
    }
  }
  
  private static void startDebugger()
  {
    try
    {
      Map localMap = getServerInfo();
      if (localMap != null)
      {
        ClassLoader localClassLoader = createClassLoader(localMap);
        
        String str = "com.wowza.wms.debugger.DebugServer";
        Class localClass = localClassLoader.loadClass(str);
        Method localMethod = localClass.getMethod("startServer", new Class[0]);
        localMethod.invoke(null, (Object[])null);
      }
    }
    catch (Exception localException)
    {
      System.out.println("Error starting: " + localException);
      localException.printStackTrace();
      doWait();
    }
  }
  
  private static void stopDebugger() {}
  
  private static String getServerGUID()
  {
    Object localObject = null;
    
    BufferedReader localBufferedReader = null;
    if (localObject == null)
    {
      String str1 = getServerHome(2);
      str1 = str1 + File.separatorChar + "conf" + File.separatorChar + "Server.guid";
      try
      {
        File localFile = new File(str1);
        if (localFile.exists())
        {
          localBufferedReader = new BufferedReader(new FileReader(localFile));
          String str2;
          while ((str2 = localBufferedReader.readLine()) != null)
          {
            str2 = str2.trim();
            if ((!str2.startsWith("#")) && 
            
              (str2.length() != 0)) {
              localObject = str2;
            }
          }
        }
      }
      catch (Exception localException2)
      {
        System.out.println("Server.getServerGUID: File error[" + str1 + "]: " + localException2.toString());
      }
    }
    try
    {
      if (localBufferedReader != null) {
        localBufferedReader.close();
      }
      localBufferedReader = null;
    }
    catch (Exception localException1)
    {
      System.out.println("Server.getServerGUID: Close error: " + localException1.toString());
    }
    return (String)localObject;
  }
  
  private static String getAdminGUID()
  {
    Object localObject = null;
    
    BufferedReader localBufferedReader = null;
    if (localObject == null)
    {
      String str1 = getServerHome(2);
      str1 = str1 + File.separatorChar + "conf" + File.separatorChar + "Admin.guid";
      try
      {
        File localFile = new File(str1);
        if (localFile.exists())
        {
          localBufferedReader = new BufferedReader(new FileReader(localFile));
          String str2;
          while ((str2 = localBufferedReader.readLine()) != null)
          {
            str2 = str2.trim();
            if ((!str2.startsWith("#")) && 
            
              (str2.length() != 0)) {
              localObject = str2;
            }
          }
        }
      }
      catch (Exception localException2)
      {
        System.out.println("Server.getAdminGUID: File error[" + str1 + "]: " + localException2.toString());
      }
    }
    try
    {
      if (localBufferedReader != null) {
        localBufferedReader.close();
      }
      localBufferedReader = null;
    }
    catch (Exception localException1)
    {
      System.out.println("Server.getAdminGUID: Close error: " + localException1.toString());
    }
    return (String)localObject;
  }
  
  private static byte[] getServerCommandEncryptionKey(String paramString1, String paramString2)
  {
    byte[] arrayOfByte1 = null;
    try
    {
      MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
      byte[] arrayOfByte2 = localMessageDigest.digest((paramString1 + ":" + paramString2).getBytes("UTF-8"));
      if (arrayOfByte2 != null)
      {
        arrayOfByte1 = new byte[16];
        System.arraycopy(arrayOfByte2, 0, arrayOfByte1, 0, arrayOfByte1.length);
      }
    }
    catch (Exception localException) {}
    return arrayOfByte1;
  }
  
  private static String signServerCommand(String paramString)
  {
    String str = null;
    
    byte[] arrayOfByte = null;
    try
    {
      MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
      arrayOfByte = localMessageDigest.digest(paramString.getBytes("UTF-8"));
    }
    catch (Exception localException) {}
    if (arrayOfByte != null) {
      str = encodeHexString(arrayOfByte);
    }
    return str;
  }
  
  public static String encodeHexString(byte[] paramArrayOfByte)
  {
    String str = "";
    for (int i = 0; i < paramArrayOfByte.length; i++)
    {
      int j = paramArrayOfByte[i] & 0xF;
      int k = (paramArrayOfByte[i] & 0xF0) >> 4;
      str = str + hexadecimal[k];
      str = str + hexadecimal[j];
    }
    return str;
  }
  
  public static String httpDate()
  {
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss", Locale.US);
    localSimpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    return localSimpleDateFormat.format(new Date()) + "GMT";
  }
  
  private static byte[] encryptMessageServerCommand(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
  {
    byte[] arrayOfByte = null;
    try
    {
      SecretKeySpec localSecretKeySpec = new SecretKeySpec(paramArrayOfByte1, "AES");
      Cipher localCipher = Cipher.getInstance("AES");
      localCipher.init(1, localSecretKeySpec);
      arrayOfByte = localCipher.doFinal(paramArrayOfByte2);
    }
    catch (Exception localException) {}
    return arrayOfByte;
  }
  
  private static boolean sendServerCommand(String paramString, byte[] paramArrayOfByte)
  {
    boolean bool = true;
    try
    {
      Map localMap = getServerInfo();
      String str1 = getAdminGUID();
      if ((str1 != null) && (localMap != null))
      {
        String str2 = "GET";
        String str3 = "/ws-admin/current/server?action=" + paramString;
        String str4 = "HTTP/1.1";
        String str5 = httpDate();
        long l = paramArrayOfByte == null ? 0 : paramArrayOfByte.length;
        
        String str6 = str2 + "\n" + str3 + "\n" + str4 + "\n" + str5 + "\n" + l + "\n" + str1;
        String str7 = signServerCommand(str6);
        byte[] arrayOfByte1 = getServerCommandEncryptionKey(str1, str7);
        
        InetAddress localInetAddress = (InetAddress)localMap.get("HostPort.address");
        int i = ((Integer)localMap.get("HostPort.port")).intValue();
        
        Socket localSocket = localInetAddress == null ? new Socket("127.0.0.1", i) : new Socket(localInetAddress, i);
        OutputStream localOutputStream = localSocket.getOutputStream();
        
        StringBuffer localStringBuffer = new StringBuffer();
        
        localStringBuffer.append(str2 + " " + str3 + " " + str4 + "\r\n");
        localStringBuffer.append("Date: " + str5 + "\r\n");
        localStringBuffer.append("Content-Length: " + l + "\r\n");
        localStringBuffer.append("Authorization: WOWZA " + str7 + "\r\n");
        localStringBuffer.append("\r\n");
        
        byte[] arrayOfByte2 = localStringBuffer.toString().getBytes();
        
        localOutputStream.write(arrayOfByte2);
        if (paramArrayOfByte != null)
        {
          byte[] arrayOfByte3 = encryptMessageServerCommand(arrayOfByte1, paramArrayOfByte);
          if (arrayOfByte3 != null) {
            localOutputStream.write(arrayOfByte3);
          }
        }
        localOutputStream.flush();
        localOutputStream.close();
        localSocket.close();
      }
    }
    catch (Exception localException)
    {
      bool = false;
    }
    return bool;
  }
  
  public static void stopServer()
  {
    sendServerCommand("serverstop", null);
  }
  
  public static void restartServer() {}
  
  public static XPathFactory newXPathFactory()
  {
    XPathFactory localXPathFactory = null;
    if (localXPathFactory == null) {
      try
      {
        localXPathFactory = XPathFactory.newInstance();
      }
      catch (Exception localException1) {}
    }
    if (localXPathFactory == null) {
      try
      {
        new XPathFactoryImpl();
      }
      catch (Exception localException2) {}
    }
    if (localXPathFactory == null) {
      System.out.println("Error: Can't find XPathFactory");
    }
    return localXPathFactory;
  }
  
  public static String encodeValue(String paramString)
  {
    String str = paramString;
    try
    {
      str = URLEncoder.encode(str, "UTF-8");
    }
    catch (Exception localException)
    {
      System.out.println("encodeValue (" + paramString + "): " + localException.toString());
      str = paramString;
    }
    return str;
  }
  
  public static String expandEnvironmentVariables(String paramString, Map paramMap)
  {
    if (paramString == null) {
      return null;
    }
    Pattern localPattern = Pattern.compile("\\$\\{[^}]*\\}");
    Matcher localMatcher = localPattern.matcher(paramString);
    ArrayList localArrayList = new ArrayList();
    Object localObject2;
    while (localMatcher.find())
    {
      localObject1 = localMatcher.group().substring(2, localMatcher.group().length() - 1);
      
      localObject2 = null;
      if (paramMap == null) {
        localObject2 = System.getProperty((String)localObject1);
      } else if (paramMap.containsKey(localObject1)) {
        localObject2 = (String)paramMap.get(localObject1);
      } else {
        localObject2 = System.getProperty((String)localObject1);
      }
      if (localObject2 == null) {
        localObject2 = "${" + (String)localObject1 + "}";
      }
      localArrayList.add(0, new ReplaceItem(localMatcher.start(), localMatcher.end(), (String)localObject2));
    }
    Object localObject1 = localArrayList.iterator();
    while (((Iterator)localObject1).hasNext())
    {
      localObject2 = (ReplaceItem)((Iterator)localObject1).next();
      paramString = paramString.substring(0, start) + newValue + paramString.substring(end);
    }
    return paramString;
  }
  
  public static BootstrapTuningConfig getTuningConfig()
  {
    BootstrapTuningConfig localBootstrapTuningConfig = new BootstrapTuningConfig();
    
    String str1 = getTuneXMLURL();
    if (str1 != null) {
      try
      {
        DocumentBuilderFactory localDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder localDocumentBuilder = localDocumentBuilderFactory.newDocumentBuilder();
        Document localDocument = localDocumentBuilder.parse(str1);
        
        XPathFactory localXPathFactory = newXPathFactory();
        XPath localXPath = localXPathFactory.newXPath();
        if (localDocument != null)
        {
          Element localElement1 = localDocument.getDocumentElement();
          
          heapSize = getNodeValue(localXPath, "/Root/Tune/HeapSize", localElement1, null);
          garbageCollector = getNodeValue(localXPath, "/Root/Tune/GarbageCollector", localElement1, null);
          if (heapSize != null)
          {
            heapSize = heapSize.trim();
            if (heapSize.length() <= 0) {
              heapSize = null;
            }
          }
          if (garbageCollector != null)
          {
            garbageCollector = garbageCollector.trim();
            if (garbageCollector.length() <= 0) {
              garbageCollector = null;
            }
          }
          XPathExpression localXPathExpression = localXPath.compile("/Root/Tune/VMOptions/VMOption");
          
          NodeList localNodeList = (NodeList)localXPathExpression.evaluate(localElement1, XPathConstants.NODESET);
          if (localNodeList != null) {
            for (int i = 0; i < localNodeList.getLength(); i++)
            {
              Node localNode = localNodeList.item(i);
              Element localElement2 = (Element)localNode;
              
              String str2 = getNodeValue(localElement2);
              if (str2 != null)
              {
                str2 = str2.trim();
                if (str2.length() > 0) {
                  vmOptions.add(str2);
                }
              }
            }
          }
        }
      }
      catch (Exception localException)
      {
        System.out.println("Error parsing Tune.xml[" + str1 + "]: " + localException.toString());
      }
    }
    return localBootstrapTuningConfig;
  }
  
  private static Map getServerInfo()
  {
    HashMap localHashMap1 = null;
    
    String str1 = getServerXMLURL();
    if (str1 == null)
    {
      System.out.println("ERROR: Server.xml not found: exiting.");
      System.exit(1);
    }
    String str2 = getVHostsXMLURL();
    if (str2 == null)
    {
      System.out.println("ERROR: VHosts.xml not found: exiting.");
      System.exit(1);
    }
    localHashMap1 = new HashMap();
    
    HashMap localHashMap2 = new HashMap();
    localHashMap1.put("VHosts", localHashMap2);
    DocumentBuilder localDocumentBuilder;
    Document localDocument;
    XPathFactory localXPathFactory;
    XPath localXPath;
    Element localElement;
    String str3;
    XPathExpression localXPathExpression;
    Object localObject1;
    Node localNode2;
    Object localObject2;
    Object localObject3;
    Object localObject4;
    Object localObject5;
    Object localObject6;
    String str4;
    Object localObject7;
    Object localObject8;
    try
    {
      DocumentBuilderFactory localDocumentBuilderFactory1 = DocumentBuilderFactory.newInstance();
      localDocumentBuilder = localDocumentBuilderFactory1.newDocumentBuilder();
      localDocument = localDocumentBuilder.parse(str1);
      
      localXPathFactory = newXPathFactory();
      localXPath = localXPathFactory.newXPath();
      if (localDocument != null)
      {
        localElement = localDocument.getDocumentElement();
        str3 = "/Root/Server/CommandInterface/HostPort";
        localXPathExpression = localXPath.compile(str3);
        
        localObject1 = (Node)localXPathExpression.evaluate(localElement, XPathConstants.NODE);
        if (localObject1 != null)
        {
          Node localNode1 = getNodeByTagName((Element)localObject1, "DomainName");
          localNode2 = getNodeByTagName((Element)localObject1, "IpAddress");
          localObject2 = getNodeByTagName((Element)localObject1, "Port");
          if (((localNode1 != null) || (localNode2 != null)) && (localObject2 != null))
          {
            localObject3 = getNodeValue(localNode1);
            localObject4 = getNodeValue(localNode2);
            localObject5 = getNodeValue((Node)localObject2);
            
            localObject6 = null;
            str4 = null;
            if (localNode2 != null)
            {
              if (((String)localObject4).equals("*"))
              {
                localObject6 = null;
              }
              else
              {
                localObject7 = ((String)localObject4).split("[.]");
                if (localObject7.length == 4)
                {
                  localObject8 = new byte[localObject7.length];
                  for (int j = 0; j < localObject7.length; j++) {
                    localObject8[j] = ((byte)Integer.parseInt(localObject7[j]));
                  }
                  localObject6 = InetAddress.getByAddress((byte[])localObject8);
                }
                else
                {
                  System.out.println("setIpAddress: invalid ipAddress: " + (String)localObject4);
                }
              }
            }
            else if (localNode1 != null) {
              if (((String)localObject3).equals("*")) {
                localObject6 = null;
              } else {
                localObject6 = InetAddress.getByName((String)localObject3);
              }
            }
            localHashMap1.put("HostPort.address", localObject6);
            localHashMap1.put("HostPort.port", new Integer(Integer.parseInt((String)localObject5)));
          }
          else
          {
            System.out.println("Error parsing Server.xml: <DomainName> or <IpAddress> and <Port> required");
          }
        }
      }
    }
    catch (Exception localException1)
    {
      System.out.println("Error parsing Server.xml: <DomainName> or <IpAddress> and <Port> required: " + localException1.toString());
      localException1.printStackTrace();
      doWait();
    }
    try
    {
      DocumentBuilderFactory localDocumentBuilderFactory2 = DocumentBuilderFactory.newInstance();
      localDocumentBuilder = localDocumentBuilderFactory2.newDocumentBuilder();
      localDocument = localDocumentBuilder.parse(str2);
      
      localXPathFactory = newXPathFactory();
      localXPath = localXPathFactory.newXPath();
      if (localDocument != null)
      {
        localElement = localDocument.getDocumentElement();
        str3 = "/Root/VHosts/VHost";
        localXPathExpression = localXPath.compile(str3);
        
        localObject1 = (NodeList)localXPathExpression.evaluate(localElement, XPathConstants.NODESET);
        if (localObject1 != null) {
          for (int i = 0; i < ((NodeList)localObject1).getLength(); i++)
          {
            localNode2 = ((NodeList)localObject1).item(i);
            localObject2 = (Element)localNode2;
            
            localObject3 = getNodeByTagName((Element)localObject2, "Name");
            localObject4 = getNodeByTagName((Element)localObject2, "ConfigDir");
            localObject5 = getNodeByTagName((Element)localObject2, "ConnectionLimit");
            if ((localObject3 != null) && (localObject4 != null))
            {
              localObject6 = getNodeValue((Node)localObject3);
              str4 = getNodeValue((Node)localObject4);
              localObject7 = null;
              if (localObject5 != null) {
                localObject7 = getNodeValue((Node)localObject5);
              }
              localObject8 = new HashMap();
              ((Map)localObject8).put("Name", localObject6);
              ((Map)localObject8).put("ConfigDir", str4);
              ((Map)localObject8).put("ConnectionLimit", localObject7);
              
              localHashMap2.put(localObject6, localObject8);
            }
            else
            {
              System.out.println("loadConfigFile: error parsing vhosts config file: (" + str2 + ") : error <Name> and <ConfigDir> required.");
            }
          }
        }
      }
    }
    catch (Exception localException2)
    {
      System.out.println("Error parsing VHosts.xml (" + str2 + "): " + localException2.toString());
      localException2.printStackTrace();
      doWait();
    }
    return localHashMap1;
  }
  
  private static Node getNodeByTagName(Element paramElement, String paramString)
  {
    NodeList localNodeList = paramElement.getElementsByTagName(paramString);
    if ((localNodeList != null) && 
      (localNodeList.getLength() > 0)) {
      return localNodeList.item(0);
    }
    return null;
  }
  
  private static String getNodeValue(Node paramNode)
  {
    String str = "";
    if (paramNode != null)
    {
      Node localNode = paramNode.getFirstChild();
      while (localNode != null)
      {
        str = str + localNode.getNodeValue();
        localNode = localNode.getNextSibling();
      }
    }
    return str;
  }
  
  public static String getNodeValue(XPath paramXPath, String paramString1, Element paramElement, String paramString2)
  {
    Object localObject = paramString2;
    try
    {
      String str = paramXPath.evaluate(paramString1, paramElement);
      if (str.length() > 0) {
        localObject = str;
      }
    }
    catch (Exception localException)
    {
      System.out.println("getNodeValue: " + localException.toString());
    }
    return (String)localObject;
  }
  
  public static String getServerLog4jPropertiesURL()
  {
    Object localObject = null;
    String str1 = getConfigURL();
    String str2 = getServerHome(2);
    
    String str3 = (str2 == null ? "" : str2) + File.separatorChar + "conf" + File.separatorChar + "log4j.properties";
    if (new File(str3).exists())
    {
      localObject = str3.replace("\\", "/");
      if (((String)localObject).charAt(1) == ':') {
        localObject = "/" + (String)localObject;
      }
      localObject = "file://" + (String)localObject;
    }
    else if (str1 != null)
    {
      localObject = str1;
      if (((String)localObject).indexOf("?") >= 0) {
        localObject = (String)localObject + "&";
      } else {
        localObject = (String)localObject + "?";
      }
      localObject = (String)localObject + "context=server&filename=" + encodeValue("conf/log4j.properties");
    }
    return (String)localObject;
  }
  
  public static String getServerLicenseURL()
  {
    String str1 = null;
    
    String str2 = getServerHome(2);
    
    String str3 = (str2 == null ? "" : str2) + File.separatorChar + "conf" + File.separatorChar + "Server.license";
    if (new File(str3).exists())
    {
      str1 = str3.replace("\\", "/");
      if (str1.charAt(1) == ':') {
        str1 = "/" + str1;
      }
      str1 = "file://" + str1;
    }
    return str1;
  }
  
  public static String getTuneXMLURL()
  {
    Object localObject = null;
    String str1 = getConfigURL();
    String str2 = getServerHome(2);
    
    String str3 = (str2 == null ? "" : str2) + File.separatorChar + "conf" + File.separatorChar + "Tune.xml";
    if (new File(str3).exists())
    {
      localObject = str3.replace("\\", "/");
      if (((String)localObject).charAt(1) == ':') {
        localObject = "/" + (String)localObject;
      }
      localObject = "file://" + (String)localObject;
    }
    else if (str1 != null)
    {
      localObject = str1;
      if (((String)localObject).indexOf("?") >= 0) {
        localObject = (String)localObject + "&";
      } else {
        localObject = (String)localObject + "?";
      }
      localObject = (String)localObject + "context=server&filename=" + encodeValue("conf/Tune.xml");
    }
    return (String)localObject;
  }
  
  public static String getServerXMLURL()
  {
    Object localObject = null;
    String str1 = getConfigURL();
    String str2 = getServerHome(2);
    
    String str3 = (str2 == null ? "" : str2) + File.separatorChar + "conf" + File.separatorChar + "Server.xml";
    if (new File(str3).exists())
    {
      localObject = str3.replace("\\", "/");
      if (((String)localObject).charAt(1) == ':') {
        localObject = "/" + (String)localObject;
      }
      localObject = "file://" + (String)localObject;
    }
    else if (str1 != null)
    {
      localObject = str1;
      if (((String)localObject).indexOf("?") >= 0) {
        localObject = (String)localObject + "&";
      } else {
        localObject = (String)localObject + "?";
      }
      localObject = (String)localObject + "context=server&filename=" + encodeValue("conf/Server.xml");
    }
    return (String)localObject;
  }
  
  public static String getVHostsXMLURL()
  {
    Object localObject = null;
    String str1 = getConfigURL();
    String str2 = getServerHome(2);
    
    String str3 = (str2 == null ? "" : str2) + File.separatorChar + "conf" + File.separatorChar + "VHosts.xml";
    if (new File(str3).exists())
    {
      localObject = str3.replace("\\", "/");
      if (((String)localObject).charAt(1) == ':') {
        localObject = "/" + (String)localObject;
      }
      localObject = "file://" + (String)localObject;
    }
    else if (str1 != null)
    {
      localObject = str1;
      if (((String)localObject).indexOf("?") >= 0) {
        localObject = (String)localObject + "&";
      } else {
        localObject = (String)localObject + "?";
      }
      localObject = (String)localObject + "context=server&filename=" + encodeValue("conf/VHosts.xml");
    }
    return (String)localObject;
  }
  
  public static String getConfigURL()
  {
    String str = System.getProperty("com.wowza.wms.ConfigURL");
    if (str == null) {
      return null;
    }
    if (str.trim().length() == 0) {
      return null;
    }
    return str.trim();
  }
  
  public static boolean isServerURLConfig()
  {
    return getConfigURL() != null;
  }
  
  public static void resolveServerHome()
  {
    String str1 = System.getProperty("com.wowza.wms.AppHome");
    if (str1 == null) {
      str1 = System.getenv("WMSAPP_HOME");
    }
    if (str1 != null)
    {
      str1 = str1.trim();
      str1 = str1.replace("\\", "/");
      str1 = str1.replace("//", "/");
      if (str1.endsWith("/")) {
        str1 = str1.substring(0, str1.length() - 1);
      }
      if (str1.length() == 0) {
        str1 = null;
      }
    }
    System.setProperty("com.wowza.wms.AppHome", str1);
    
    String str2 = System.getProperty("com.wowza.wms.ConfigHome");
    if (str2 == null) {
      str2 = System.getenv("WMSCONFIG_HOME");
    }
    if (str2 != null)
    {
      str2 = str2.trim();
      str2 = str2.replace("\\", "/");
      str2 = str2.replace("//", "/");
      if (str2.endsWith("/")) {
        str2 = str2.substring(0, str2.length() - 1);
      }
      if (str2.length() == 0) {
        str2 = null;
      }
    }
    System.setProp
1 2

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd