List of usage examples for java.lang System getProperties
public static Properties getProperties()
From source file:org.hawkular.apm.api.services.ConfigurationLoader.java
/** * This method loads the configuration from the supplied URI. * * @param uri The URI//from www . j a va2 s . c om * @param type The type, or null if default (jvm) * @return The configuration */ protected static CollectorConfiguration loadConfig(String uri, String type) { final CollectorConfiguration config = new CollectorConfiguration(); if (type == null) { type = DEFAULT_TYPE; } uri += java.io.File.separator + type; File f = new File(uri); if (!f.isAbsolute()) { if (f.exists()) { uri = f.getAbsolutePath(); } else if (System.getProperties().containsKey("jboss.server.config.dir")) { uri = System.getProperty("jboss.server.config.dir") + java.io.File.separatorChar + uri; } else { try { URL url = Thread.currentThread().getContextClassLoader().getResource(uri); if (url != null) { uri = url.getPath(); } else { log.severe("Failed to get absolute path for uri '" + uri + "'"); } } catch (Exception e) { log.log(Level.SEVERE, "Failed to get absolute path for uri '" + uri + "'", e); uri = null; } } } if (uri != null) { String[] uriParts = uri.split(Matcher.quoteReplacement(File.separator)); int startIndex = 0; // Remove any file prefix if (uriParts[0].equals("file:")) { startIndex++; } try { Path path = getPath(startIndex, uriParts); Files.walkFileTree(path, new FileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(Path path, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { if (path.toString().endsWith(".json")) { String json = new String(Files.readAllBytes(path)); CollectorConfiguration childConfig = mapper.readValue(json, CollectorConfiguration.class); if (childConfig != null) { config.merge(childConfig, false); } } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path path, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); } catch (Throwable e) { log.log(Level.SEVERE, "Failed to load configuration", e); } } return config; }
From source file:com.kylinolap.rest.service.AdminService.java
/** * Get Java Env info as string/*from w w w . jav a 2 s . c om*/ * * @return */ @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN) public String getEnv() { logger.debug("Get Kylin Runtime environment"); PropertiesConfiguration tempConfig = new PropertiesConfiguration(); // Add Java Env try { String content = ""; ByteArrayOutputStream baos = new ByteArrayOutputStream(); // env Map<String, String> env = System.getenv(); for (String envName : env.keySet()) { tempConfig.addProperty(envName, env.get(envName)); } // properties Properties properteis = System.getProperties(); for (Object propName : properteis.keySet()) { tempConfig.setProperty((String) propName, properteis.get(propName)); } // do save tempConfig.save(baos); content = baos.toString(); return content; } catch (ConfigurationException e) { logger.debug("Failed to get Kylin Runtime env", e); throw new InternalErrorException("Failed to get Kylin env Config", e); } }
From source file:ch.cyberduck.core.sds.SDSNodeIdProviderTest.java
@Test public void withCache() throws Exception { final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials( System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key"))); final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); assertNotNull(new SDSNodeIdProvider(session).withCache(PathCache.empty())); }
From source file:ch.cyberduck.core.ftp.FTPStatListServiceTest.java
@Test public void testList() throws Exception { final Host host = new Host(new FTPTLSProtocol(), "test.cyberduck.ch", new Credentials(System.getProperties().getProperty("ftp.user"), System.getProperties().getProperty("ftp.password"))); final FTPSession session = new FTPSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final ListService service = new FTPStatListService(session, new CompositeFileEntryParser(Collections.singletonList(new UnixFTPEntryParser()))); final Path directory = new FTPWorkdirService(session).find(); final Path file = new Path(directory, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new DefaultTouchFeature<Integer>(new DefaultUploadFeature<Integer>(new FTPWriteFeature(session))) .touch(file, new TransferStatus()); final Permission permission = new Permission(Permission.Action.read_write, Permission.Action.read_write, Permission.Action.read_write); new FTPUnixPermissionFeature(session).setUnixPermission(file, permission); final AttributedList<Path> list = service.list(directory, new DisabledListProgressListener()); assertTrue(list.contains(file));/* w ww . j a v a2s . co m*/ assertEquals(permission, list.get(file).attributes().getPermission()); session.close(); }
From source file:de.cosmocode.palava.core.Main.java
private Main(String[] args) { final CmdLineParser parser = new CmdLineParser(options); try {/*from w w w .ja v a 2 s. c om*/ parser.parseArgument(args); } catch (CmdLineException e) { System.err.println("Usage: java [options] configuration-files..."); parser.printUsage(System.err); throw new IllegalArgumentException(e); } if (options.isInterceptStreams()) { SystemStreamWrapper.redirectSystemStreams(); LOG.info("SYSOUT and SYSERR will be logged through the logging system"); } LOG.info("Options: {}", options); LOG.info("Environment: {}", System.getenv()); LOG.info("System: {}", System.getProperties()); final Properties properties; try { properties = MultiProperties.load(options.getConfigs()); } catch (IOException e) { throw new IllegalArgumentException(e); } framework = Palava.newFramework(properties); }
From source file:ch.cyberduck.core.spectra.SpectraUploadFeatureTest.java
@Test public void testUpload() throws Exception { final Host host = new Host(new SpectraProtocol() { @Override//from w w w . j a v a2s . co m public Scheme getScheme() { return Scheme.http; } }, System.getProperties().getProperty("spectra.hostname"), Integer.valueOf(System.getProperties().getProperty("spectra.port")), new Credentials(System.getProperties().getProperty("spectra.user"), System.getProperties().getProperty("spectra.key"))); final SpectraSession session = new SpectraSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); final int length = 32770; final byte[] content = RandomUtils.nextBytes(length); final OutputStream out = local.getOutputStream(false); IOUtils.write(content, out); out.close(); final Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final TransferStatus writeStatus = new TransferStatus().length(content.length); final SpectraBulkService bulk = new SpectraBulkService(session); bulk.pre(Transfer.Type.upload, Collections.singletonMap(test, writeStatus), new DisabledConnectionCallback()); final SpectraUploadFeature upload = new SpectraUploadFeature(new SpectraWriteFeature(session), new SpectraBulkService(session)); upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), writeStatus, new DisabledConnectionCallback()); final byte[] buffer = new byte[content.length]; final TransferStatus readStatus = new TransferStatus().length(content.length); bulk.pre(Transfer.Type.download, Collections.singletonMap(test, readStatus), new DisabledConnectionCallback()); final InputStream in = new SpectraReadFeature(session).read(test, readStatus, new DisabledConnectionCallback()); IOUtils.readFully(in, buffer); in.close(); assertArrayEquals(content, buffer); new SpectraDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); local.delete(); session.close(); }
From source file:org.up4j.APITest.java
@Before public void setUp() throws IOException { Properties properties = System.getProperties(); if (properties.contains("test.email")) { email = properties.getProperty("test.email"); }//from ww w. j a v a2s.c o m if (properties.contains("test.password")) { password = properties.getProperty("test.password"); } api = DefaultAPIImpl.newInstance(); jsonResponseHolder = new JsonResponseHolder(); ((DefaultAPIImpl) api).addJsonResponseListener(jsonResponseHolder); authenticationResponse = api.login(email, password); }
From source file:ch.cyberduck.core.ftp.FTPReadFeatureTest.java
@Test(expected = NotfoundException.class) public void testReadNotFound() throws Exception { final Host host = new Host(new FTPTLSProtocol(), "test.cyberduck.ch", new Credentials(System.getProperties().getProperty("ftp.user"), System.getProperties().getProperty("ftp.password"))); final FTPSession session = new FTPSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final TransferStatus status = new TransferStatus(); new FTPReadFeature(session).read( new Path(new FTPWorkdirService(session).find(), "nosuchname", EnumSet.of(Path.Type.file)), status, new DisabledConnectionCallback()); }
From source file:com.github.born2snipe.maven.log.LogFilterApplier.java
public boolean showDebugInfo() { return System.getProperties().containsKey(DEBUG_SWITCH); }
From source file:com.github.sleroy.junit.mail.server.test.MailSender.java
/** * Send mail.//w ww .ja va2 s . c o m * * @param from * Sender's email ID needs to be mentioned * @param to * Recipient's email ID needs to be mentioned. * @param subject * the subject * @throws MessagingException */ public void sendMail(String from, String to, String subject, String body) throws MessagingException { // Get system properties Properties properties = System.getProperties(); // Setup mail server properties.setProperty("mail.smtp.host", host); properties.setProperty("mail.smtp.port", Integer.toString(port)); // Get the default Session object. Session session = Session.getDefaultInstance(properties); Transport transport = null; try { transport = session.getTransport(); // Create a default MimeMessage object. MimeMessage message = new MimeMessage(session); // Set From: header field of the header. message.setFrom(new InternetAddress(from)); // Set To: header field of the header. message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); // Set Subject: header field message.setSubject(subject); // Now set the actual message message.setText(body); // Send message transport.send(message); System.out.println("Sent message successfully...."); } finally { if (transport != null) { transport.close(); } } }