public WFile readFile(String strPath) {
        File objFile = new File(strPath);
        HashMap hmConts = new HashMap();
        setHM(strPath, hmConts);

        return new WFile(objFile.lastModified(), hmConts);
      }
示例#2
0
 @Override
 public void run() {
   if (settingsFile != null && !isSavingSettings) {
     File file = new File(settingsFile);
     if (file.exists() && file.lastModified() > lastSettingsLoad) {
       log.info("Reloading updated settings file");
       initSettings(settingsFile);
       SoapUI.updateProxyFromSettings();
     }
   }
 }
示例#3
0
  /*
   * (non-Javadoc)
   *
   * @see com.eviware.soapui.SoapUICore#saveSettings()
   */
  public String saveSettings() throws Exception {
    PropertyExpansionUtils.saveGlobalProperties();
    SecurityScanUtil.saveGlobalSecuritySettings();
    isSavingSettings = true;
    try {
      if (settingsFile == null) {
        settingsFile = getRoot() + File.separatorChar + DEFAULT_SETTINGS_FILE;
      }

      // Save settings to root or user.home
      File file = new File(settingsFile);
      if (!file.canWrite()) {
        file = new File(new File(System.getProperty("user.home", ".")), DEFAULT_SETTINGS_FILE);
      }

      SoapuiSettingsDocumentConfig settingsDocument =
          (SoapuiSettingsDocumentConfig) this.settingsDocument.copy();
      String password = settings.getString(SecuritySettings.SHADOW_PASSWORD, null);

      if (password != null && password.length() > 0) {
        try {
          byte[] data = settingsDocument.xmlText().getBytes();
          String encryptionAlgorithm = "des3";
          byte[] encryptedData = OpenSSL.encrypt(encryptionAlgorithm, password.toCharArray(), data);
          settingsDocument.setSoapuiSettings(null);
          settingsDocument.getSoapuiSettings().setEncryptedContent(encryptedData);
          settingsDocument.getSoapuiSettings().setEncryptedContentAlgorithm(encryptionAlgorithm);
        } catch (UnsupportedEncodingException e) {
          log.error("Encryption error", e);
        } catch (IOException e) {
          log.error("Encryption error", e);
        } catch (GeneralSecurityException e) {
          log.error("Encryption error", e);
        }
      }

      FileOutputStream out = new FileOutputStream(file);
      settingsDocument.save(out);
      out.flush();
      out.close();
      log.info("Settings saved to [" + file.getAbsolutePath() + "]");
      lastSettingsLoad = file.lastModified();
      return file.getAbsolutePath();
    } finally {
      isSavingSettings = false;
    }
  }
  @Nullable
  private static File findOldConfigDir(
      @NotNull File configDir, @Nullable String customPathSelector) {
    final File selectorDir = CONFIG_RELATED_PATH.isEmpty() ? configDir : configDir.getParentFile();
    final File parent = selectorDir.getParentFile();
    if (parent == null || !parent.exists()) {
      return null;
    }
    File maxFile = null;
    long lastModified = 0;
    final String selector =
        PathManager.getPathsSelector() != null
            ? PathManager.getPathsSelector()
            : selectorDir.getName();

    final String prefix = getPrefixFromSelector(selector);
    final String customPrefix =
        customPathSelector != null ? getPrefixFromSelector(customPathSelector) : null;
    for (File file :
        parent.listFiles(
            new FilenameFilter() {
              @Override
              public boolean accept(@NotNull File file, @NotNull String name) {
                return StringUtil.startsWithIgnoreCase(name, prefix)
                    || customPrefix != null && StringUtil.startsWithIgnoreCase(name, customPrefix);
              }
            })) {
      File options = new File(file, CONFIG_RELATED_PATH + OPTIONS_XML);
      if (!options.exists()) {
        continue;
      }

      long modified = options.lastModified();
      if (modified > lastModified) {
        lastModified = modified;
        maxFile = file;
      }
    }
    return maxFile != null ? new File(maxFile, CONFIG_RELATED_PATH) : null;
  }
  public static void main(String[] arg) {
    if (arg.length != 2) {
      System.err.println("usage: java ScpTo file1 user@remotehost:file2");
      System.exit(-1);
    }

    FileInputStream fis = null;
    try {

      String lfile = arg[0];
      String user = arg[1].substring(0, arg[1].indexOf('@'));
      arg[1] = arg[1].substring(arg[1].indexOf('@') + 1);
      String host = arg[1].substring(0, arg[1].indexOf(':'));
      String rfile = arg[1].substring(arg[1].indexOf(':') + 1);

      JSch jsch = new JSch();
      Session session = jsch.getSession(user, host, 22);

      // username and password will be given via UserInfo interface.
      UserInfo ui = new MyUserInfo();
      session.setUserInfo(ui);
      session.connect();

      boolean ptimestamp = true;

      // exec 'scp -t rfile' remotely
      String command = "scp " + (ptimestamp ? "-p" : "") + " -t " + rfile;
      Channel channel = session.openChannel("exec");
      ((ChannelExec) channel).setCommand(command);

      // get I/O streams for remote scp
      OutputStream out = channel.getOutputStream();
      InputStream in = channel.getInputStream();

      channel.connect();

      if (checkAck(in) != 0) {
        System.exit(0);
      }

      File _lfile = new File(lfile);

      if (ptimestamp) {
        command = "T " + (_lfile.lastModified() / 1000) + " 0";
        // The access time should be sent here,
        // but it is not accessible with JavaAPI ;-<
        command += (" " + (_lfile.lastModified() / 1000) + " 0\n");
        out.write(command.getBytes());
        out.flush();
        if (checkAck(in) != 0) {
          System.exit(0);
        }
      }

      // send "C0644 filesize filename", where filename should not include '/'
      long filesize = _lfile.length();
      command = "C0644 " + filesize + " ";
      if (lfile.lastIndexOf('/') > 0) {
        command += lfile.substring(lfile.lastIndexOf('/') + 1);
      } else {
        command += lfile;
      }
      command += "\n";
      out.write(command.getBytes());
      out.flush();
      if (checkAck(in) != 0) {
        System.exit(0);
      }

      // send a content of lfile
      fis = new FileInputStream(lfile);
      byte[] buf = new byte[1024];
      while (true) {
        int len = fis.read(buf, 0, buf.length);
        if (len <= 0) break;
        out.write(buf, 0, len); // out.flush();
      }
      fis.close();
      fis = null;
      // send '\0'
      buf[0] = 0;
      out.write(buf, 0, 1);
      out.flush();
      if (checkAck(in) != 0) {
        System.exit(0);
      }
      out.close();

      channel.disconnect();
      session.disconnect();

      System.exit(0);
    } catch (Exception e) {
      System.out.println(e);
      try {
        if (fis != null) fis.close();
      } catch (Exception ee) {
      }
    }
  }
示例#6
0
  protected Settings initSettings(String fileName) {
    // TODO Why try to load settings from current directory before using root?
    // This caused a bug in Eclipse:
    // https://sourceforge.net/tracker/?func=detail&atid=737763&aid=2620284&group_id=136013
    File settingsFile = new File(fileName).exists() ? new File(fileName) : null;

    try {
      if (settingsFile == null) {
        settingsFile = new File(new File(getRoot()), DEFAULT_SETTINGS_FILE);
        if (!settingsFile.exists()) {
          settingsFile =
              new File(new File(System.getProperty("user.home", ".")), DEFAULT_SETTINGS_FILE);
          lastSettingsLoad = 0;
        }
      } else {
        settingsFile = new File(fileName);
        if (!settingsFile.getAbsolutePath().equals(this.settingsFile)) {
          lastSettingsLoad = 0;
        }
      }

      if (!settingsFile.exists()) {
        if (settingsDocument == null) {
          log.info("Creating new settings at [" + settingsFile.getAbsolutePath() + "]");
          settingsDocument = SoapuiSettingsDocumentConfig.Factory.newInstance();
          setInitialImport(true);
        }

        lastSettingsLoad = System.currentTimeMillis();
      } else if (settingsFile.lastModified() > lastSettingsLoad) {
        settingsDocument = SoapuiSettingsDocumentConfig.Factory.parse(settingsFile);

        byte[] encryptedContent = settingsDocument.getSoapuiSettings().getEncryptedContent();
        if (encryptedContent != null) {
          char[] password = null;
          if (this.password == null) {
            // swing element -!! uh!
            JPasswordField passwordField = new JPasswordField();
            JLabel qLabel = new JLabel("Password");
            JOptionPane.showConfirmDialog(
                null,
                new Object[] {qLabel, passwordField},
                "Global Settings",
                JOptionPane.OK_CANCEL_OPTION);
            password = passwordField.getPassword();
          } else {
            password = this.password.toCharArray();
          }

          String encryptionAlgorithm =
              settingsDocument.getSoapuiSettings().getEncryptedContentAlgorithm();
          byte[] data =
              OpenSSL.decrypt(
                  StringUtils.isNullOrEmpty(encryptionAlgorithm) ? "des3" : encryptionAlgorithm,
                  password,
                  encryptedContent);
          try {
            settingsDocument =
                SoapuiSettingsDocumentConfig.Factory.parse(new String(data, "UTF-8"));
          } catch (Exception e) {
            log.warn("Wrong password.");
            JOptionPane.showMessageDialog(
                null,
                "Wrong password, creating backup settings file [ "
                    + settingsFile.getAbsolutePath()
                    + ".bak.xml. ]\nSwitch to default settings.",
                "Error - Wrong Password",
                JOptionPane.ERROR_MESSAGE);
            settingsDocument.save(new File(settingsFile.getAbsolutePath() + ".bak.xml"));
            throw e;
          }
        }

        log.info("initialized soapui-settings from [" + settingsFile.getAbsolutePath() + "]");
        lastSettingsLoad = settingsFile.lastModified();

        if (settingsWatcher == null) {
          settingsWatcher = new SettingsWatcher();
          SoapUI.getSoapUITimer().scheduleAtFixedRate(settingsWatcher, 10000, 10000);
        }
      }
    } catch (Exception e) {
      log.warn("Failed to load settings from [" + e.getMessage() + "], creating new");
      settingsDocument = SoapuiSettingsDocumentConfig.Factory.newInstance();
      lastSettingsLoad = 0;
    }

    if (settingsDocument.getSoapuiSettings() == null) {
      settingsDocument.addNewSoapuiSettings();
      settings = new XmlBeansSettingsImpl(null, null, settingsDocument.getSoapuiSettings());

      initDefaultSettings(settings);
    } else {
      settings = new XmlBeansSettingsImpl(null, null, settingsDocument.getSoapuiSettings());
    }

    this.settingsFile = settingsFile.getAbsolutePath();

    if (!settings.isSet(WsdlSettings.EXCLUDED_TYPES)) {
      StringList list = new StringList();
      list.add("schema@http://www.w3.org/2001/XMLSchema");
      settings.setString(WsdlSettings.EXCLUDED_TYPES, list.toXml());
    }

    if (settings
        .getString(HttpSettings.HTTP_VERSION, HttpSettings.HTTP_VERSION_1_1)
        .equals(HttpSettings.HTTP_VERSION_0_9)) {
      settings.setString(HttpSettings.HTTP_VERSION, HttpSettings.HTTP_VERSION_1_1);
    }

    setIfNotSet(WsdlSettings.NAME_WITH_BINDING, true);
    setIfNotSet(WsdlSettings.NAME_WITH_BINDING, 500);
    setIfNotSet(HttpSettings.HTTP_VERSION, HttpSettings.HTTP_VERSION_1_1);
    setIfNotSet(HttpSettings.MAX_TOTAL_CONNECTIONS, 2000);
    setIfNotSet(HttpSettings.RESPONSE_COMPRESSION, true);
    setIfNotSet(HttpSettings.LEAVE_MOCKENGINE, true);
    setIfNotSet(UISettings.AUTO_SAVE_PROJECTS_ON_EXIT, true);
    setIfNotSet(UISettings.SHOW_DESCRIPTIONS, true);
    setIfNotSet(WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS, true);
    setIfNotSet(WsaSettings.USE_DEFAULT_RELATES_TO, true);
    setIfNotSet(WsaSettings.USE_DEFAULT_RELATIONSHIP_TYPE, true);
    setIfNotSet(UISettings.SHOW_STARTUP_PAGE, true);
    setIfNotSet(UISettings.GC_INTERVAL, "60");
    setIfNotSet(WsdlSettings.CACHE_WSDLS, true);
    setIfNotSet(WsdlSettings.PRETTY_PRINT_RESPONSE_MESSAGES, true);
    setIfNotSet(HttpSettings.RESPONSE_COMPRESSION, true);
    setIfNotSet(HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN, true);
    setIfNotSet(HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN, true);
    setIfNotSet(HttpSettings.LEAVE_MOCKENGINE, true);
    setIfNotSet(HttpSettings.START_MOCK_SERVICE, true);
    setIfNotSet(UISettings.AUTO_SAVE_INTERVAL, "0");
    setIfNotSet(UISettings.GC_INTERVAL, "60");
    setIfNotSet(UISettings.SHOW_STARTUP_PAGE, true);
    setIfNotSet(WsaSettings.SOAP_ACTION_OVERRIDES_WSA_ACTION, false);
    setIfNotSet(WsaSettings.USE_DEFAULT_RELATIONSHIP_TYPE, true);
    setIfNotSet(WsaSettings.USE_DEFAULT_RELATES_TO, true);
    setIfNotSet(WsaSettings.OVERRIDE_EXISTING_HEADERS, false);
    setIfNotSet(WsaSettings.ENABLE_FOR_OPTIONAL, false);
    setIfNotSet(VersionUpdateSettings.AUTO_CHECK_VERSION_UPDATE, true);
    if (!settings.isSet(ProxySettings.AUTO_PROXY) && !settings.isSet(ProxySettings.ENABLE_PROXY)) {
      settings.setBoolean(ProxySettings.AUTO_PROXY, true);
      settings.setBoolean(ProxySettings.ENABLE_PROXY, true);
    }

    boolean setWsiDir = false;
    String wsiLocationString = settings.getString(WSISettings.WSI_LOCATION, null);
    if (StringUtils.isNullOrEmpty(wsiLocationString)) {
      setWsiDir = true;
    } else {
      File wsiFile = new File(wsiLocationString);
      if (!wsiFile.exists()) {
        setWsiDir = true;
      }
    }
    if (setWsiDir) {
      String wsiDir = System.getProperty("wsi.dir", new File(".").getAbsolutePath());
      settings.setString(WSISettings.WSI_LOCATION, wsiDir);
    }
    HttpClientSupport.addSSLListener(settings);

    return settings;
  }