Beispiel #1
0
  public static boolean writeConfigToDisk(ProxyConfig pc) {
    Resource.Lock lock = null;
    try {
      GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class);
      Resource configFile = loader.get("proxy/proxy.xml");

      XStream xs = new XStream();
      String xml = xs.toXML(pc);
      FileWriter fw = new FileWriter(configFile.file(), false); // false means overwrite old file
      // Take the write lock on the file & lock it
      lock = configFile.lock();
      fw.write(xml);
      fw.close();
      return true;
    } catch (Exception e) {
      LOG.warning("Failed to save configuration for Proxy module. Exception:" + e.toString());
      return false;
    } finally {
      if (lock != null) lock.release();
    }
  }
Beispiel #2
0
  /* this is pretty unappealingly hackish */
  public static ProxyConfig loadConfFromDisk() {
    ProxyConfig retval;
    Resource.Lock lock = null;
    try {
      GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class);
      Resource configFile = loader.get("proxy/proxy.xml");
      lock = configFile.lock();

      InputStream proxyConfStream = configFile.in();
      XStream xs = new XStream();
      // Take the read lock, then read the file
      retval = (ProxyConfig) (xs.fromXML(proxyConfStream));
    } catch (Exception e) {
      LOG.warning(
          "Failed to open configuration for Proxy module. Using default. Exception:"
              + e.toString());
      // writeConfigToDisk(DEFAULT);
      retval = DEFAULT;
    } finally {
      if (lock != null) lock.release();
    }
    return retval;
  }