Esempio n. 1
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();
     }
   }
 }
Esempio n. 2
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;
    }
  }
Esempio n. 3
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;
  }