Example usage for java.lang System getProperties

List of usage examples for java.lang System getProperties

Introduction

In this page you can find the example usage for java.lang System getProperties.

Prototype

public static Properties getProperties() 

Source Link

Document

Determines the current system properties.

Usage

From source file:com.eviware.soapui.monitor.PropertySupport.java

public static void applySystemProperties(Object target, String scope, ModelItem modelItem) {
    PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(target);
    DefaultPropertyExpansionContext context = new DefaultPropertyExpansionContext(modelItem);
    Properties properties = System.getProperties();

    for (PropertyDescriptor descriptor : descriptors) {
        String name = descriptor.getName();
        String key = scope + "." + name;
        if (PropertyUtils.isWriteable(target, name) && properties.containsKey(key)) {
            try {
                String value = context.expand(String.valueOf(properties.get(key)));
                BeanUtils.setProperty(target, name, value);
                SoapUI.log.info("Set property [" + name + "] to [" + value + "] in scope [" + scope + "]");
            } catch (Throwable e) {
                SoapUI.logError(e);/*from   w  ww .ja  v  a 2s  .c o  m*/
            }
        }
    }
}

From source file:nebula.plugin.metrics.model.Info.java

public static Info create(Tool tool, Tool scm, Tool ci) {
    return create(tool, scm, ci, System.getenv(), new HashMap(System.getProperties()));
}

From source file:com.asakusafw.cleaner.testutil.UnitTestUtil.java

public static void tearDownEnv() throws Exception {
    Properties p = System.getProperties();
    p.clear();//from   www.jav  a  2 s . c o  m
    ConfigurationLoader.setSysProp(p);
    System.setProperties(p);
}

From source file:Main.java

public static String openUrl(String url, String method, Bundle params) {
    if (method.equals("GET")) {
        url = url + "?" + encodeUrl(params);
    }/*from  www .  j  a  v a 2  s.c  o m*/
    String response = "";
    try {
        Log.d(LOG_TAG, method + " URL: " + url);
        HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        conn.setRequestProperty("User-Agent",
                System.getProperties().getProperty("http.agent") + " RenrenAndroidSDK");
        if (!method.equals("GET")) {
            conn.setRequestMethod("POST");
            conn.setDoOutput(true);
            conn.getOutputStream().write(encodeUrl(params).getBytes("UTF-8"));
        }

        response = read(conn.getInputStream());
    } catch (Exception e) {
        Log.e(LOG_TAG, e.getMessage());
        throw new RuntimeException(e.getMessage(), e);
    }
    return response;
}

From source file:edu.stanford.muse.email.VerifyEmailSetup.java

public static Pair<Boolean, String> run() {
    PrintStream savedOut = System.out;
    InputStream savedIn = System.in;

    try {/*w  w w. j a v a  2  s .c  o m*/
        // Get a Properties object
        Properties props = System.getProperties();

        // Get a Session object
        Session session = Session.getInstance(props, null);
        session.setDebug(true);
        String filename = System.getProperty("java.io.tmpdir") + File.separatorChar + "verifyEmailSetup";
        PrintStream ps = new PrintStream(new FileOutputStream(filename));
        System.setOut(ps);
        System.setErr(ps);

        // Get a Store object
        Store store = null;
        store = session.getStore("imaps");
        store.connect("imap.gmail.com", 993, "checkmuse", ""); // not the real password. unfortunately, the checkmuse a/c will get blocked by google.
        //           Folder folder = store.getFolder("[Gmail]/Sent Mail");
        //           int totalMessages = folder.getMessageCount();
        // System.err.println (totalMessages + " messages!");
        ps.close();
        String contents = Util.getFileContents(filename);
        System.out.println(contents);
        return new Pair<Boolean, String>(Boolean.TRUE, contents);
    } catch (AuthenticationFailedException e) {
        /* its ok if auth failed. we only want to check if IMAPS network route is blocked.
         when network is blocked, we'll get something like
        javax.mail.MessagingException: No route to host; 
        nested exception is: 
        java.net.NoRouteToHostException: No route to host 
        ...
        */
        log.info("Verification succeeded: " + Util.stackTrace(e));
        return new Pair<Boolean, String>(Boolean.TRUE, "");
    } catch (Exception e) {
        log.warn("Verification failed: " + Util.stackTrace(e));
        return new Pair<Boolean, String>(Boolean.FALSE, e.toString()); // stack track reveals too much about our code... Util.stackTrace(e));         
    } finally {
        System.setOut(savedOut);
        System.setIn(savedIn);
    }
}

From source file:io.cloudslang.lang.runtime.configuration.SlangRuntimeSpringConfig.java

private static void setPythonIoEncoding() {
    String encodingValue = System.getProperty(SlangSystemPropertyConstant.CSLANG_ENCODING.getValue());
    if (StringUtils.isEmpty(encodingValue)) {
        encodingValue = StandardCharsets.UTF_8.name();
    }/* w ww.j a va  2  s.  co  m*/
    System.getProperties().setProperty(PySystemState.PYTHON_IO_ENCODING, encodingValue);
}

From source file:com.partnet.automation.util.SystemPropsUtil.java

/**
 * Load properties from the given configuration file name.
 * <p>// w  ww .ja v  a  2s.com
 * Given error message is displayed if file not found.
 * <p>
 * 
 * @param configFileName
 *          - File name of properties file.
 * @throws RuntimeException
 *           - If the file has a error while reading the properties file
 */
public static void loadProperties(String configFileName) {
    Properties cmdlineProps = System.getProperties();
    Properties fileProps = new Properties();

    // load property file
    InputStream inputStream = SystemPropsUtil.class.getResourceAsStream(configFileName);
    if (inputStream == null) {
        // force use of classloader to look for properties file
        inputStream = SystemPropsUtil.class.getClassLoader().getResourceAsStream(configFileName);
        if (inputStream == null) {
            log.warn(String.format("Failed to locate and load properties file: %s", configFileName));
            return;
        }
    } else {
        log.info("Properties file ({}) exists", configFileName);
    }

    // load fileProps with config.properties
    try {
        fileProps.load(inputStream);
    } catch (IOException e) {
        throw new RuntimeException(
                String.format("Failure occurred while reading properties file: %s", configFileName), e);
    }

    // Override any fileProp with cmdlineProps
    fileProps.putAll(cmdlineProps);
    System.setProperties(fileProps);
}

From source file:net.orpiske.ssps.common.db.derby.DerbyManagerFactory.java

/**
 * Creates a new database manager instance
 * @return a new database manager instance
 * @throws DatabaseInitializationException
 *///from   w  w w . ja  v  a 2 s.  com
public static DerbyDatabaseManager newInstance() throws DatabaseInitializationException {
    Properties props = System.getProperties();
    props.setProperty("derby.system.home", Utils.getSdmDirectoryPath());

    boolean volatileStorage = config.getBoolean("registry.volatile.storage", false);

    return new DerbyDatabaseManager("registry", props, volatileStorage);
}

From source file:bad.robot.http.configuration.SystemPropertyProxy.java

private static URL getUrlFromSystemProperties() {
    String url = (String) System.getProperties().get(SystemPropertyProxy.proxyUrl);
    String port = (String) System.getProperties().get(SystemPropertyProxy.port);
    if (isEmpty(url) || isEmpty(port))
        throw new IllegalArgumentException(format(
                "'%s' and/or '%s' were not specified as system properties, use -D or set programatically",
                SystemPropertyProxy.proxyUrl, SystemPropertyProxy.port));
    if (url.toLowerCase().contains("://"))
        throw new IllegalArgumentException(format(
                "no need to set a protocol on the proxy URL specified by the system property '%s'", proxyUrl));
    String username = (String) System.getProperties().get(SystemPropertyProxy.user);
    String password = (String) System.getProperties().get(SystemPropertyProxy.password);
    if (isEmpty(username) || isEmpty(password))
        return url(format("http://%s:%s", url, port));
    return url(format("http://%s:%s@%s:%s", username, password, url, port));
}

From source file:SendMailBean.java

public void emailPassword(String email, String memberName, String password) {
    String host = "mail";
    String from = "w@j.com";

    Properties props = System.getProperties();

    props.put("mail.smtp.host", host);
    Session session = Session.getDefaultInstance(props, null);
    MimeMessage message = new MimeMessage(session);

    try {//from w  w w  .  j av a 2 s . c  o m
        message.setFrom(new InternetAddress(from));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(email));

        message.setSubject("Password Reminder");

        message.setText("Hi " + memberName + ",\nYour password is: " + password + "\nregards - " + from);
        Transport.send(message);
    } catch (AddressException ae) {
    } catch (MessagingException me) {
    }
}