Example usage for java.lang System clearProperty

List of usage examples for java.lang System clearProperty

Introduction

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

Prototype

public static String clearProperty(String key) 

Source Link

Document

Removes the system property indicated by the specified key.

Usage

From source file:org.apache.maven.wagon.providers.webdav.WebDavWagonTest.java

public void testWagonFailsOnPutFailureByDefault() throws Exception {
    setupRepositories();/*from  ww w .  j a  v  a2s. co m*/

    setupWagonTestingFixtures();

    File testFile = getTempFile();

    System.clearProperty(WebDavWagon.CONTINUE_ON_FAILURE_PROPERTY);

    WebDavWagon wagon = new TimeoutSimulatingWagon();
    wagon.connect(testRepository, getAuthInfo());

    try {
        String filename = TimeoutSimulatingWagon.TIMEOUT_TRIGGER + ".txt";

        try {
            wagon.put(testFile, filename);
            fail("Exception expected");
        } catch (TransferFailedException e) {

        }
    } finally {
        wagon.disconnect();

        tearDownWagonTestingFixtures();
    }
}

From source file:nl.b3p.viewer.admin.stripes.ServiceUsageMatrixActionBean.java

public static XSSFWorkbook createWorkBook(String theXml) throws ParserConfigurationException, SAXException,
        IOException, XPathExpressionException, XPathFactoryConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(new InputSource(new StringReader(theXml)));

    XSSFWorkbook workbook = new XSSFWorkbook();
    String tempProperty = null;/*from  w  w w  .j a va2 s. co  m*/
    try {
        Element root = doc.getDocumentElement();
        /* JSTL XML is setting the system property to use the jstl xpath facotry.
         * Remove the setting temporary:
         * see: https://java.net/jira/browse/JSTL-1
         */
        tempProperty = System
                .getProperty(XPathFactory.DEFAULT_PROPERTY_NAME + ":" + XPathFactory.DEFAULT_OBJECT_MODEL_URI);
        if (tempProperty != null) {
            System.clearProperty(
                    XPathFactory.DEFAULT_PROPERTY_NAME + ":" + XPathFactory.DEFAULT_OBJECT_MODEL_URI);
        }

        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPath xpath = xpathFactory.newXPath();
        XPathExpression exprFeatureSource = xpath.compile("//featureSource");
        XPathExpression exprFeatureType = xpath.compile("featureType");
        XPathExpression exprApplication = xpath.compile("applications/application");
        XPathExpression exprLayer = xpath.compile("layers/layer");
        XPathExpression exprAppLayer = xpath.compile("applayers/applayer");
        XPathExpression exprId = xpath.compile("id/text()");
        XPathExpression exprAlias = xpath.compile("alias/text()");
        XPathExpression exprName = xpath.compile("name/text()");
        XPathExpression exprVersion = xpath.compile("version/text()");
        XPathExpression exprProtocol = xpath.compile("protocol/text()");
        XPathExpression exprUrl = xpath.compile("url/text()");

        XSSFSheet sheet = workbook.createSheet("Sheet 1");
        int rowNum = 0;

        Row head = sheet.createRow(rowNum++);
        String[] headValues = { "Bron", "Featuretype", "Applicatie", "Layernaam van service",
                "Application layer (kaart)" };
        for (int c = 0; c < headValues.length; c++) {
            Cell cell = head.createCell(c);
            cell.setCellValue(headValues[c]);
        }
        List<String> columns = new ArrayList<String>();
        for (int i = 0; i < headValues.length; i++) {
            columns.add("");
        }
        NodeList featureSources = (NodeList) exprFeatureSource.evaluate(root, XPathConstants.NODESET);

        for (int fs = 0; fs < featureSources.getLength(); fs++) {
            Node featureSource = featureSources.item(fs);

            String fsString = (String) exprName.evaluate(featureSource, XPathConstants.STRING);
            fsString += " (" + (String) exprProtocol.evaluate(featureSource, XPathConstants.STRING);
            fsString += ":: " + (String) exprUrl.evaluate(featureSource, XPathConstants.STRING);
            fsString += " id: " + (String) exprId.evaluate(featureSource, XPathConstants.STRING);
            fsString += ")";
            columns.set(0, fsString);
            NodeList featureTypes = (NodeList) exprFeatureType.evaluate(featureSource, XPathConstants.NODESET);
            for (int ft = 0; ft < featureTypes.getLength(); ft++) {
                Node featureType = featureTypes.item(ft);
                //String ftId = (String) exprId.evaluate(featureType,XPathConstants.STRING);
                String ftName = (String) exprName.evaluate(featureType, XPathConstants.STRING);
                //String ftString = ""+ftName;
                columns.set(1, ftName);
                NodeList applications = (NodeList) exprApplication.evaluate(featureType,
                        XPathConstants.NODESET);
                for (int app = 0; app < applications.getLength(); app++) {
                    Node application = applications.item(app);
                    String appVersion = (String) exprVersion.evaluate(application, XPathConstants.STRING);

                    String appString = (String) exprName.evaluate(application, XPathConstants.STRING);
                    if (appVersion != null) {
                        appString += ", version: " + appVersion;
                    }
                    appString += " (" + (String) exprId.evaluate(application, XPathConstants.STRING) + ")";
                    columns.set(2, appString);
                    NodeList layers = (NodeList) exprLayer.evaluate(application, XPathConstants.NODESET);
                    for (int lay = 0; lay < layers.getLength(); lay++) {
                        Node layer = layers.item(lay);
                        String layerString = "";
                        layerString += (String) exprName.evaluate(layer, XPathConstants.STRING);
                        columns.set(3, layerString);
                        NodeList appLayers = (NodeList) exprAppLayer.evaluate(layer, XPathConstants.NODESET);
                        for (int al = 0; al < appLayers.getLength(); al++) {
                            Node appLayer = appLayers.item(al);
                            String alString = (String) exprAlias.evaluate(appLayer, XPathConstants.STRING);
                            alString += " (" + (String) exprId.evaluate(appLayer, XPathConstants.STRING) + ")";
                            columns.set(4, alString);
                            Row row = sheet.createRow(rowNum++);
                            for (int c = 0; c < columns.size(); c++) {
                                Cell cell = row.createCell(c);
                                cell.setCellValue(columns.get(c));
                            }
                        }
                    }
                }
            }
        }
    } finally {
        if (tempProperty != null) {
            System.setProperty(XPathFactory.DEFAULT_PROPERTY_NAME + ":" + XPathFactory.DEFAULT_OBJECT_MODEL_URI,
                    tempProperty);
        }
    }
    return workbook;
}

From source file:com.yahoo.athenz.common.server.db.DataSourceFactoryTest.java

@Test
public void testRetrieveConfigSettingIntInvalid() {
    System.setProperty(ATHENZ_DBPOOL_PROP1, "abc");
    assertEquals(DataSourceFactory.retrieveConfigSetting(ATHENZ_DBPOOL_PROP1, 20), 20);
    System.clearProperty(ATHENZ_DBPOOL_PROP1);
}

From source file:org.codice.ddf.migration.util.MigratableUtilTest.java

@Test(expected = IllegalArgumentException.class)
public void copyFileFromSystemPropertyWithNullValue() {
    System.clearProperty(SOURCE_PATH_PROPERTY_NAME);
    MigratableUtil migratableUtil = new MigratableUtil();
    migratableUtil.copyFileFromSystemPropertyValue(SOURCE_PATH_PROPERTY_NAME, VALID_DESTINATION_PATH, warnings);
}

From source file:org.red5.server.tomcat.TomcatVHostLoader.java

/**
 * Un-initialization./*from   w  w  w  . j a v  a2  s  . co  m*/
 */
public void uninit() {
    log.debug("TomcatVHostLoader un-init");
    Container[] children = host.findChildren();
    for (Container c : children) {
        if (c instanceof StandardContext) {
            try {
                ((StandardContext) c).stop();
                host.removeChild(c);
            } catch (Exception e) {
                log.error("Could not stop context: {}", c.getName(), e);
            }
        }
    }
    //remove system prop
    String propertyPrefix = name;
    if (domain != null) {
        propertyPrefix += '_' + domain.replace('.', '_');
    }
    System.clearProperty(propertyPrefix + ".webapp.root");
    //stop the host
    try {
        ((StandardHost) host).stop();
    } catch (LifecycleException e) {
        log.error("Could not stop host: {}", host.getName(), e);
    }
    //remove host
    engine.removeChild(host);
    //unregister jmx
    unregisterJMX();
}

From source file:org.elasticsearch.common.cli.CliToolTests.java

@Test
public void testThatThrowExceptionCanBeLogged() throws Exception {
    CaptureOutputTerminal terminal = new CaptureOutputTerminal();
    NamedCommand cmd = new NamedCommand("cmd", terminal) {
        @Override/* w  w w .j  a  v a  2 s. c  o  m*/
        public CliTool.ExitStatus execute(Settings settings, Environment env) throws Exception {
            throw new ElasticsearchException("error message");
        }
    };
    SingleCmdTool tool = new SingleCmdTool("tool", terminal, cmd);
    assertStatus(tool.execute(), CliTool.ExitStatus.CODE_ERROR);
    assertThat(terminal.getTerminalOutput(), hasSize(1));
    assertThat(terminal.getTerminalOutput(), hasItem(containsString("error message")));

    // set env... and log stack trace
    try {
        System.setProperty(Terminal.DEBUG_SYSTEM_PROPERTY, "true");
        terminal = new CaptureOutputTerminal();
        assertStatus(new SingleCmdTool("tool", terminal, cmd).execute(), CliTool.ExitStatus.CODE_ERROR);
        assertThat(terminal.getTerminalOutput(), hasSize(2));
        assertThat(terminal.getTerminalOutput(), hasItem(containsString("error message")));
        // This class must be part of the stack strace
        assertThat(terminal.getTerminalOutput(), hasItem(containsString(getClass().getName())));
    } finally {
        System.clearProperty(Terminal.DEBUG_SYSTEM_PROPERTY);
    }
}

From source file:org.apache.bookkeeper.meta.MetadataDriversTest.java

@Test
public void testLoadClientDriverFromSystemProperty() throws Exception {
    String saveDriversStr = System.getProperty(BK_METADATA_CLIENT_DRIVERS_PROPERTY);
    try {//from  w ww.j  a v a 2s. c  o m
        System.setProperty(BK_METADATA_CLIENT_DRIVERS_PROPERTY, StringUtils
                .join(new String[] { ClientDriver1.class.getName(), ClientDriver2.class.getName() }, ':'));

        MetadataDrivers.loadInitialDrivers();

        MetadataClientDriver loadedDriver1 = MetadataDrivers.getClientDriver("driver1");
        assertEquals(ClientDriver1.class, loadedDriver1.getClass());
        MetadataClientDriver loadedDriver2 = MetadataDrivers.getClientDriver("driver2");
        assertEquals(ClientDriver2.class, loadedDriver2.getClass());
    } finally {
        if (null != saveDriversStr) {
            System.setProperty(BK_METADATA_CLIENT_DRIVERS_PROPERTY, saveDriversStr);
        } else {
            System.clearProperty(BK_METADATA_CLIENT_DRIVERS_PROPERTY);
        }
    }
}

From source file:org.digidoc4j.main.DigiDoc4JTest.java

@Test
public void nonExistingDigidoc4jModeResultsInTest() throws Exception {
    String[] params = new String[] { "" };
    System.clearProperty("digidoc4j.mode");

    callMainWithoutSystemExit(params);/* w  w  w . ja v  a  2 s.  com*/
    assertEquals(Mode.PROD.toString(), System.getProperty("digidoc4j.mode"));
}

From source file:org.nuxeo.runtime.test.runner.RandomBugTest.java

@After
public void clearSystemProperties() {
    if (oldProperty != null) {
        System.setProperty(RandomBug.MODE_PROPERTY, oldProperty);
    } else {// ww w .j a v  a2 s  . c  o m
        System.clearProperty(RandomBug.MODE_PROPERTY);
    }
}

From source file:ch.bfh.abcvote.util.controllers.CommunicationController.java

/**
 * Helper method which posts the given json-string json to the given url 
 * @param url// ww  w. j  a v  a 2s . com
 * Exact url where the jsonData should get posted to
 * @param json
 * String of the JsonData which should be posted to the bulletin board
 * @param useTor
 * Boolean indicating if Json should be posted over Tor network
 * @return
 * retruns whether or not the data was sucessfully posted
 * @throws IOException IOException is thrown from the CloseableHttpClient
 */
public boolean postJsonStringToURL(String url, String json, Boolean useTor) throws IOException {
    boolean responseOK = true;
    boolean usingTor = useTor;

    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    CloseableHttpClient httpClient = httpClientBuilder.create().build();

    if (usingTor == true) {
        try {
            // Set Proxy
            System.setProperty("socksProxyHost", "127.0.0.1");
            System.setProperty("socksProxyPort", "9050");

            //prepare the post request
            HttpPost request = new HttpPost(url);
            StringEntity params = new StringEntity(json);
            request.addHeader("content-type", "application/json");
            request.setEntity(params);

            //sending post request and checking response
            CloseableHttpResponse response = httpClient.execute(request);
            //System.out.println(response);
            if (response.getStatusLine().getStatusCode() != 200) {
                responseOK = false;
            }
            response.close();
            request.completed();

        } catch (Exception ex) {
            responseOK = false;
        } finally {
            httpClient.close();

            // 'Unset' the proxy.
            System.clearProperty("socksProxyHost");
        }
    } else {
        try {
            //prepare the post request
            HttpPost request = new HttpPost(url);
            StringEntity params = new StringEntity(json);
            request.addHeader("content-type", "application/json");
            request.setEntity(params);

            //sending post request and checking response
            HttpResponse response = httpClient.execute(request);
            //System.out.println(response);
            if (response.getStatusLine().getStatusCode() != 200) {
                responseOK = false;
            }

        } catch (Exception ex) {
            responseOK = false;
        } finally {
            httpClient.close();
        }
    }
    return responseOK;
}