Esempio n. 1
1
  protected void initExtensions(ClassLoader extensionClassLoader) {
    /* We break the general rule that you shouldn't catch Throwable, because we don't want extensions to crash SoapUI. */
    try {
      String extDir = System.getProperty("soapui.ext.listeners");
      addExternalListeners(
          FilenameUtils.normalize(
              extDir != null
                  ? extDir
                  : root == null ? "listeners" : root + File.separatorChar + "listeners"),
          extensionClassLoader);
    } catch (Throwable e) {
      SoapUI.logError(e, "Couldn't load external listeners");
    }

    try {
      String factoriesDir = System.getProperty("soapui.ext.factories");
      addExternalFactories(
          FilenameUtils.normalize(
              factoriesDir != null
                  ? factoriesDir
                  : root == null ? "factories" : root + File.separatorChar + "factories"),
          extensionClassLoader);
    } catch (Throwable e) {
      SoapUI.logError(e, "Couldn't load external factories");
    }
  }
Esempio n. 2
0
 public static boolean settingsFileExists() {
   DefaultSoapUICore soapUICore = new DefaultSoapUICore();
   return new File(DEFAULT_SETTINGS_FILE).exists()
       || new File(new File(soapUICore.getRoot()), DEFAULT_SETTINGS_FILE).exists()
       || new File(System.getProperty("user.home", ".") + File.separator + DEFAULT_SETTINGS_FILE)
           .exists();
 }
Esempio n. 3
0
 protected void loadPlugins() {
   File pluginDirectory = new File(System.getProperty("soapui.home"), "plugins");
   File[] pluginFiles = pluginDirectory.listFiles();
   if (pluginFiles != null) {
     for (File pluginFile : pluginFiles) {
       log.info("Adding plugin from [" + pluginFile.getAbsolutePath() + "]");
       try {
         loadOldStylePluginFrom(pluginFile);
       } catch (Throwable e) {
         log.warn("Could not load plugin from file [" + pluginFile + "]");
       }
     }
   }
 }
Esempio n. 4
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. 5
0
  protected void initLog() {
    if (!logIsInitialized) {
      String logFileName =
          System.getProperty(SoapUISystemProperties.SOAPUI_LOG4j_CONFIG_FILE, "soapui-log4j.xml");
      File log4jconfig =
          root == null ? new File(logFileName) : new File(new File(getRoot()), logFileName);
      if (log4jconfig.exists()) {
        System.out.println("Configuring log4j from [" + log4jconfig.getAbsolutePath() + "]");
        DOMConfigurator.configureAndWatch(log4jconfig.getAbsolutePath(), 5000);
      } else {
        URL url = SoapUI.class.getResource("/com/eviware/soapui/resources/conf/soapui-log4j.xml");
        if (url != null) {
          DOMConfigurator.configure(url);
        } else {
          System.err.println("Missing soapui-log4j.xml configuration");
        }
      }

      logIsInitialized = true;

      log = Logger.getLogger(DefaultSoapUICore.class);
    }
  }
Esempio n. 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;
  }
Esempio n. 7
0
 public String getRoot() {
   if (root == null || root.length() == 0) {
     root = System.getProperty("soapui.home", new File(".").getAbsolutePath());
   }
   return FilenameUtils.normalize(root);
 }