Example usage for java.lang System setProperty

List of usage examples for java.lang System setProperty

Introduction

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

Prototype

public static String setProperty(String key, String value) 

Source Link

Document

Sets the system property indicated by the specified key.

Usage

From source file:Main.java

/**
 * @return a new XSLT transformer/*from   w  w  w.ja  v a2  s. co m*/
 * @throws TransformerConfigurationException if no TransformerFactory can be located in the
 * runtime environment.
 */
public static Transformer getTransformer() throws TransformerConfigurationException {
    TransformerFactory tf;
    try {
        tf = TransformerFactory.newInstance();
    } catch (TransformerFactoryConfigurationError e) {
        System.setProperty("javax.xml.transform.TransformerFactory", TRANSFORMER_FACTORY_JDK5);
        tf = TransformerFactory.newInstance();
    }
    if (tf != null) {
        return tf.newTransformer();
    } else {
        throw new TransformerConfigurationException("Unable to instantiate a TransformerFactory");
    }
}

From source file:Main.java

@SuppressLint("NewApi")
@SuppressWarnings("all")
private static boolean setProxyKK(WebView webView, String host, int port, String applicationClassName) {
    Context appContext = webView.getContext().getApplicationContext();
    if (null == host) {
        System.clearProperty("http.proxyHost");
        System.clearProperty("http.proxyPort");
        System.clearProperty("https.proxyHost");
        System.clearProperty("https.proxyPort");
    } else {/*from  ww w .  ja va  2 s .  c  om*/
        System.setProperty("http.proxyHost", host);
        System.setProperty("http.proxyPort", port + "");
        System.setProperty("https.proxyHost", host);
        System.setProperty("https.proxyPort", port + "");
    }
    try {
        Class applictionCls = Class.forName(applicationClassName);
        Field loadedApkField = applictionCls.getField("mLoadedApk");
        loadedApkField.setAccessible(true);
        Object loadedApk = loadedApkField.get(appContext);
        Class loadedApkCls = Class.forName("android.app.LoadedApk");
        Field receiversField = loadedApkCls.getDeclaredField("mReceivers");
        receiversField.setAccessible(true);
        Map receivers = (Map) receiversField.get(loadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object rec : ((Map) receiverMap).keySet()) {
                Class clazz = rec.getClass();
                if (clazz.getName().contains("ProxyChangeListener")) {
                    Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
                    Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);

                    /*********** optional, may be need in future *************/
                    final String CLASS_NAME = "android.net.ProxyProperties";
                    Class cls = Class.forName(CLASS_NAME);
                    Constructor constructor = cls.getConstructor(String.class, Integer.TYPE, String.class);
                    constructor.setAccessible(true);
                    Object proxyProperties = constructor.newInstance(host, port, null);
                    intent.putExtra("proxy", (Parcelable) proxyProperties);
                    /*********** optional, may be need in future *************/

                    onReceiveMethod.invoke(rec, appContext, intent);
                }
            }
        }
        Log.d(LOG_TAG, "Setting proxy with >= 4.4 API successful!");
        return true;
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:org.apache.cxf.fediz.integrationtests.JettyTest.java

@BeforeClass
public static void init() {
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
    System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
    System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.webflow", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.security.web", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.security", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.cxf.fediz", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.cxf", "info");

    idpHttpsPort = System.getProperty("idp.https.port");
    Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
    rpHttpsPort = System.getProperty("rp.https.port");
    Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);

    JettyUtils.initIdpServer();//w  w  w.j  av  a 2s  . c o m
    JettyUtils.startIdpServer();
    JettyUtils.initRpServer();
    JettyUtils.startRpServer();
}

From source file:net.sheehantech.cherry.ProtocolTest.java

@BeforeClass
public static void init() {
    System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "DEBUG");
}

From source file:org.apache.cxf.fediz.integrationtests.JettyPreAuthSpringTest.java

@BeforeClass
public static void init() {
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
    System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
    System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.webflow", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.security.web", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.cxf.fediz", "info");

    idpHttpsPort = System.getProperty("idp.https.port");
    Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
    rpHttpsPort = System.getProperty("rp.https.port");
    Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);

    JettyUtils.initIdpServer();//  w w  w .  ja v  a 2  s . co m
    JettyUtils.startIdpServer();
    JettyUtils.initRpServer();
    JettyUtils.startRpServer();
}

From source file:org.constretto.spring.namespacehandler.ImportWithDefaultResolverTest.java

@BeforeClass
public static void setEnvironment() {
    System.setProperty(DefaultAssemblyContextResolver.ASSEMBLY_KEY, "junit");
    ctx = new ClassPathXmlApplicationContext(
            "org/constretto/spring/namespacehandler/ImportWithDefaultResolverTest-context.xml");
}

From source file:Main.java

public static void validateDTD(String xmlFile, String dtdPath)
        throws ParserConfigurationException, SAXException, IOException {

    String userDir = System.getProperty(USER_DIR_KEY);

    try {//ww  w  . j  a v a2s. c om
        File dtdPathFile = new File(dtdPath);
        if (dtdPathFile.isDirectory()) {
            System.setProperty(USER_DIR_KEY, dtdPath);
            validateDTD0(xmlFile, null);
        } else {
            validateDTD0(xmlFile, dtdPath);
        }
    } finally {
        System.setProperty(USER_DIR_KEY, userDir);
    }
}

From source file:com.netflix.config.DynamicURLConfigurationTestWithFileURL.java

@BeforeClass
public static void init() {
    System.setProperty("archaius.configurationSource.defaultFileName", "test.properties");
}

From source file:org.craftercms.cstudio.publishing.PublishingReceiverMain.java

private static Server initializeContext() throws IOException {
    System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true");
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(
            "classpath:spring/application-context.xml");
    Server server = (Server) context.getBean("Server");
    context.close();/*from   w w w.  j av  a2  s. c  o  m*/
    return server;
}

From source file:iqq.app.IMLauncher.java

/**
 * ???//from  w  w w  . j a v a  2 s .co m
 */
private static void init() {
    // APP
    String path = System.getProperty("user.dir");
    if (new File(path + File.separator + "resources").exists()) {
        System.setProperty("app.dir", new File(path).getAbsolutePath());
    } else {
        // ?main
        path = path.substring(0, path.lastIndexOf(File.separator));
        System.setProperty("app.dir", new File(path).getAbsolutePath());
    }
    LOG.info("app.dir = " + System.getProperty("app.dir"));

    // ?
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            shutdown();
        }
    }));
    LOG.info("init...");
}