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:ch.cyberduck.core.shared.DefaultCopyFeatureTest.java

@Test
public void testCopy() throws Exception {
    final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch",
            new Credentials(System.getProperties().getProperty("sftp.user"),
                    System.getProperties().getProperty("sftp.password")));
    final SFTPSession session = new SFTPSession(host);
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());

    final Path source = new Path(new SFTPHomeDirectoryService(session).find(),
            new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Path target = new Path(new SFTPHomeDirectoryService(session).find(),
            new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    new DefaultTouchFeature<Void>(new DefaultUploadFeature<Void>(new SFTPWriteFeature(session))).touch(source,
            new TransferStatus());
    final byte[] content = RandomUtils.nextBytes(524);
    final TransferStatus status = new TransferStatus().length(content.length);
    final OutputStream out = new SFTPWriteFeature(session).write(source, status,
            new DisabledConnectionCallback());
    assertNotNull(out);//w w  w .  j  av a 2 s  .  co m
    new StreamCopier(status, status).withLimit(new Long(content.length))
            .transfer(new ByteArrayInputStream(content), out);
    out.close();
    new DefaultCopyFeature(session).copy(source, target, new TransferStatus(),
            new DisabledConnectionCallback());
    assertTrue(new DefaultFindFeature(session).find(source));
    assertTrue(new DefaultFindFeature(session).find(target));
    assertEquals(content.length, new DefaultAttributesFinderFeature(session).find(target).getSize());
    new SFTPDeleteFeature(session).delete(Arrays.asList(source, target), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:se.inera.axel.shs.camel.ShsMessageDataFormatTest.java

@DirtiesContext
@Test//from  w w w.  ja  v a2 s.c  o  m
public void testMarshal() throws Exception {
    Assert.assertNotNull(testShsMessage);

    resultEndpoint.expectedMessageCount(1);
    template.sendBody("direct:marshal", testShsMessage);

    resultEndpoint.assertIsSatisfied();
    List<Exchange> exchanges = resultEndpoint.getReceivedExchanges();
    Exchange exchange = exchanges.get(0);

    InputStream mimeStream = exchange.getIn().getBody(InputStream.class);

    MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(System.getProperties()), mimeStream);
    String[] mimeSubject = mimeMessage.getHeader("Subject");
    Assert.assertTrue("SHS Message".equalsIgnoreCase(mimeSubject[0]),
            "Subject is expected to be 'SHS Message' but was " + mimeSubject[0]);

    Assert.assertNull(mimeMessage.getMessageID());

    MimeMultipart multipart = (MimeMultipart) mimeMessage.getContent();
    Assert.assertEquals(multipart.getCount(), 2);

    BodyPart bodyPart = multipart.getBodyPart(1);
    String content = (String) bodyPart.getContent();
    Assert.assertEquals(content, ShsMessageTestObjectMother.DEFAULT_TEST_BODY);

    String contentType = bodyPart.getContentType();
    Assert.assertTrue(
            StringUtils.contains(contentType, ShsMessageTestObjectMother.DEFAULT_TEST_DATAPART_CONTENTTYPE),
            "Content type error");

    String encodings[] = bodyPart.getHeader("Content-Transfer-Encoding");
    Assert.assertNotNull(encodings);
    Assert.assertEquals(encodings.length, 1);
    Assert.assertEquals(encodings[0].toUpperCase(),
            ShsMessageTestObjectMother.DEFAULT_TEST_DATAPART_TRANSFERENCODING.toString().toUpperCase());

    mimeMessage.writeTo(System.out);
}

From source file:ch.cyberduck.core.sftp.SFTPReadFeatureTest.java

@Test
public void testRead() throws Exception {
    final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch",
            new Credentials(System.getProperties().getProperty("sftp.user"),
                    System.getProperties().getProperty("sftp.password")));
    final SFTPSession session = new SFTPSession(host);
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new SFTPHomeDirectoryService(session).find();
    final Path test = new Path(home, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    new SFTPTouchFeature(session).touch(test, new TransferStatus());
    final int length = 39865;
    final byte[] content = RandomUtils.nextBytes(length);
    {/*  w  w  w  . j a v  a  2s  . c  om*/
        final TransferStatus status = new TransferStatus().length(content.length);
        final OutputStream out = new SFTPWriteFeature(session).write(test, status,
                new DisabledConnectionCallback());
        assertNotNull(out);
        new StreamCopier(status, status).withLimit(new Long(content.length))
                .transfer(new ByteArrayInputStream(content), out);
        out.close();
    }
    {
        final TransferStatus status = new TransferStatus();
        status.setLength(content.length);
        final InputStream in = new SFTPReadFeature(session).read(test, status,
                new DisabledConnectionCallback());
        assertNotNull(in);
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
        new StreamCopier(status, status).withLimit(new Long(content.length)).transfer(in, buffer);
        in.close();
        assertArrayEquals(content, buffer.toByteArray());
    }
    new SFTPDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:ch.cyberduck.core.cryptomator.S3MultipartWriteFeatureTest.java

@Test
public void testWrite() throws Exception {
    final S3Session session = new S3Session(new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
            new Credentials(System.getProperties().getProperty("s3.key"),
                    System.getProperties().getProperty("s3.secret"))));
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new Path("test-eu-central-1-cyberduck",
            EnumSet.of(Path.Type.volume, Path.Type.directory));
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.directory));
    final Path test = new Path(vault, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    session.withRegistry(//from  w w  w.  j a v a 2  s.  c om
            new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final CryptoWriteFeature feature = new CryptoWriteFeature<List<MultipartPart>>(session,
            new S3MultipartWriteFeature(session), cryptomator);
    final byte[] content = RandomUtils.nextBytes(6 * 1024 * 1024);
    final TransferStatus writeStatus = new TransferStatus();
    final Cryptor cryptor = cryptomator.getCryptor();
    final FileHeader header = cryptor.fileHeaderCryptor().create();
    writeStatus.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header));
    writeStatus.setNonces(new RandomNonceGenerator());
    writeStatus.setLength(-1L);
    final StatusOutputStream out = feature.write(test, writeStatus, new DisabledConnectionCallback());
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    final TransferStatus progress = new TransferStatus();
    new StreamCopier(new TransferStatus(), progress).transfer(in, out);
    assertEquals(content.length, progress.getOffset());
    assertNotNull(out.getStatus());
    assertTrue(new CryptoFindFeature(session, new S3FindFeature(session), cryptomator).find(test));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new CryptoReadFeature(session, new S3ReadFeature(session), cryptomator)
            .read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new CryptoDeleteFeature(session, new S3DefaultDeleteFeature(session), cryptomator)
            .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}

From source file:org.alfresco.bm.web.WebApp.java

@Override
public void onStartup(ServletContext container) {
    // Grab the server capabilities, otherwise just use the java version
    String javaVersion = System.getProperty("java.version");
    String systemCapabilities = System.getProperty(PROP_SYSTEM_CAPABILITIES, javaVersion);

    String appDir = new File(".").getAbsolutePath();
    String appContext = container.getContextPath();
    String appName = container.getContextPath().replace(SEPARATOR, "");

    // Create an application context (don't start, yet)
    XmlWebApplicationContext ctx = new XmlWebApplicationContext();
    ctx.setConfigLocations(new String[] { "classpath:config/spring/app-context.xml" });

    // Pass our properties to the new context
    Properties ctxProperties = new Properties();
    {/*from   w  w w  .ja va 2  s  .  co m*/
        ctxProperties.put(PROP_SYSTEM_CAPABILITIES, systemCapabilities);
        ctxProperties.put(PROP_APP_CONTEXT_PATH, appContext);
        ctxProperties.put(PROP_APP_DIR, appDir);
    }
    ConfigurableEnvironment ctxEnv = ctx.getEnvironment();
    ctxEnv.getPropertySources().addFirst(new PropertiesPropertySource(appName, ctxProperties));
    // Override all properties with system properties
    ctxEnv.getPropertySources().addFirst(new PropertiesPropertySource("system", System.getProperties()));
    // Bind to shutdown
    ctx.registerShutdownHook();

    ContextLoaderListener ctxLoaderListener = new ContextLoaderListener(ctx);
    container.addListener(ctxLoaderListener);

    ServletRegistration.Dynamic jerseyServlet = container.addServlet("jersey-serlvet", SpringServlet.class);
    jerseyServlet.setInitParameter("com.sun.jersey.config.property.packages", "org.alfresco.bm.rest");
    jerseyServlet.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
    jerseyServlet.addMapping("/api/*");
}

From source file:mitm.common.properties.PropertyUtils.java

/**
 * Returns the property as a boolean. If propery is not found, or the property is not something that can
 * be represented a boolean, defaultValue will be returned.
 *//*  w w  w. ja  v a  2 s .c o m*/
public static boolean getBooleanSystemProperty(String name, boolean defaultValue) {
    return getBooleanProperty(System.getProperties(), name, defaultValue);
}

From source file:org.smigo.config.WebAppInitializer.java

@Override
protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
    super.beforeSpringSecurityFilterChain(servletContext);
    log.info("Starting servlet context");
    log.info("contextName: " + servletContext.getServletContextName());
    log.info("contextPath:" + servletContext.getContextPath());
    log.info("effectiveMajorVersion:" + servletContext.getEffectiveMajorVersion());
    log.info("effectiveMinorVersion:" + servletContext.getEffectiveMinorVersion());
    log.info("majorVersion:" + servletContext.getMajorVersion());
    log.info("minorVersion:" + servletContext.getMinorVersion());
    log.info("serverInfo:" + servletContext.getServerInfo());
    //               ", virtualServerName:" + servletContext.getVirtualServerName() +
    log.info("toString:" + servletContext.toString());

    for (Enumeration<String> e = servletContext.getAttributeNames(); e.hasMoreElements();) {
        log.info("Attribute:" + e.nextElement());
    }//  w  ww .  ja v a 2  s .  c  o  m
    for (Map.Entry<String, String> env : System.getenv().entrySet()) {
        log.info("System env:" + env.toString());
    }
    for (Map.Entry<Object, Object> prop : System.getProperties().entrySet()) {
        log.info("System prop:" + prop.toString());
    }

    final String profile = System.getProperty("smigoProfile", EnvironmentProfile.PRODUCTION);
    log.info("Starting with profile " + profile);

    WebApplicationContext context = new AnnotationConfigWebApplicationContext() {
        {
            register(WebConfiguration.class);
            setDisplayName("SomeRandomName");
            getEnvironment().setActiveProfiles(profile);
        }
    };

    FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("CharacterEncodingFilter",
            new CharacterEncodingFilter());
    characterEncodingFilter.setInitParameter("encoding", "UTF-8");
    characterEncodingFilter.setInitParameter("forceEncoding", "true");
    characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*");

    servletContext.addListener(new RequestContextListener());
    servletContext.addListener(new ContextLoaderListener(context));

    //http://stackoverflow.com/questions/4811877/share-session-data-between-2-subdomains
    //        servletContext.getSessionCookieConfig().setDomain(getDomain());

    DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
    dispatcherServlet.setThrowExceptionIfNoHandlerFound(false);
    servletContext.addServlet("dispatcher", dispatcherServlet).addMapping("/");
}

From source file:ch.cyberduck.core.SingleTransferWorkerTest.java

@Test
public void testTransferredSizeRepeat() throws Exception {
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    final byte[] content = new byte[62768];
    new Random().nextBytes(content);
    final OutputStream out = local.getOutputStream(false);
    IOUtils.write(content, out);//from  w ww  .  j av  a 2s  . c  o m
    out.close();
    final Host host = new Host(new DAVProtocol(), "test.cyberduck.ch",
            new Credentials(System.getProperties().getProperty("webdav.user"),
                    System.getProperties().getProperty("webdav.password")));
    host.setDefaultPath("/dav/basic");
    final AtomicBoolean failed = new AtomicBoolean();
    final DAVSession session = new DAVSession(host) {
        final DAVUploadFeature upload = new DAVUploadFeature(this) {
            @Override
            protected InputStream decorate(final InputStream in, final MessageDigest digest)
                    throws IOException {
                if (failed.get()) {
                    // Second attempt successful
                    return in;
                }
                return new CountingInputStream(in) {
                    @Override
                    protected void beforeRead(final int n) throws IOException {
                        super.beforeRead(n);
                        if (this.getByteCount() >= 32768L) {
                            failed.set(true);
                            throw new SocketTimeoutException();
                        }
                    }
                };
            }
        };

        @Override
        @SuppressWarnings("unchecked")
        public <T> T getFeature(final Class<T> type) {
            if (type == Upload.class) {
                return (T) upload;
            }
            return super.getFeature(type);
        }
    };
    session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path test = new Path(new DefaultHomeFinderService(session).find(), UUID.randomUUID().toString(),
            EnumSet.of(Path.Type.file));
    final Transfer t = new UploadTransfer(new Host(new TestProtocol()), test, local);
    final BytecountStreamListener counter = new BytecountStreamListener(new DisabledStreamListener());
    assertTrue(new SingleTransferWorker(session, t, new TransferOptions(), new TransferSpeedometer(t),
            new DisabledTransferPrompt() {
                @Override
                public TransferAction prompt(final TransferItem file) {
                    return TransferAction.overwrite;
                }
            }, new DisabledTransferErrorCallback(), new DisabledTransferItemCallback(),
            new DisabledProgressListener(), counter, new DisabledLoginCallback(), TransferItemCache.empty()) {

    }.run(session));
    local.delete();
    assertEquals(62768L, counter.getSent(), 0L);
    assertEquals(62768L, new DAVAttributesFeature(session).find(test).getSize());
    assertTrue(failed.get());
    new DAVDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
}

From source file:com.symbian.driver.remoting.master.TestMaster.java

/**
 * Start master.//from   w ww  .j av  a 2s  .  c o  m
 */
public void start() {

    String bindingName = null;
    String jobsFolder = null;
    String lHostName = null;
    String lServiceName = null;

    // start rmi registry
    /*
     * The user can specify the ip@ or the host name at config --server
     */
    try {

        TDConfig CONFIG = TDConfig.getInstance();
        lHostName = CONFIG.getPreference(TDConfig.SERVER_NAME);
        lServiceName = CONFIG.getPreference(TDConfig.SERVICE);

        LOGGER.fine("Host: " + lHostName + " RMI Service: " + lServiceName);

        jobsFolder = CONFIG.getPreferenceFile(TDConfig.JOBS_FOLDER).getAbsolutePath();
        if (lHostName.matches("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$")) {
            LOGGER.fine("Using host ip address for RMI from the config : " + lHostName);
            lHostName = InetAddress.getByName(lHostName).getHostName();
        }

        if (lHostName == null) {
            LOGGER.log(Level.SEVERE, "Could not determine the Host Name. Please check your config.");
            System.exit(-1);
        }

        System.getProperties().setProperty("java.rmi.server.hostname", lHostName);
        Registry lRegistry = LocateRegistry.createRegistry(1099);
        LOGGER.fine("Master: RMI registry ready. " + lRegistry);

    } catch (ParseException lE) {
        LOGGER.log(Level.SEVERE, "Master: Can not parse configuration.", lE);
        System.exit(-1);
    } catch (UnknownHostException lUHE) {
        LOGGER.log(Level.SEVERE, "Invalid host name " + lHostName, lUHE);
        System.exit(-1);
    } catch (RemoteException lRemoteException) {
        LOGGER.log(Level.SEVERE, "Master: RMI registry failed to start " + lRemoteException.getMessage(),
                lRemoteException);
        System.exit(-1);
    }

    File storeFolder = new File(SERIALIZE_FOLDER);
    if (!(storeFolder.isDirectory())) {
        if (!(storeFolder.mkdirs())) {
            LOGGER.log(Level.SEVERE,
                    "Master: Unable to create the store folder." + "Please ensure that the " + SERIALIZE_FOLDER
                            + " folder exists. It is needed by Master for placing system restore files.");
            System.exit(-1);
        }
    }

    try {
        if (ClientRegister.getInstance().needRestore()) {
            LOGGER.info("Restoring Client register.");
            ClientRegister.getInstance().restoreSnapshot();
        }
        if (JobTracker.getInstance().needRestore()) {
            LOGGER.info("Restoring Job tracker.");
            JobTracker.getInstance().restoreSnapshot();
        }
        JobCounter jobCounter = new JobCounter();
        if (jobCounter.needRestore()) {
            LOGGER.info("Restoring Job counter.");
            jobCounter.restoreSnapshot();
        }
        QueuedExecutor queuedExecutor = new QueuedExecutor();
        if (queuedExecutor.needRestore()) {
            LOGGER.info("Restoring execution queue.");
            queuedExecutor.restoreSnapshot();
        }
        bindingName = "//" + lHostName + "/" + lServiceName;
        MasterRemote master = new MasterRemoteImpl(jobsFolder, jobCounter, queuedExecutor);
        Naming.rebind(bindingName, master);
        LOGGER.info("Remote Service Name : " + bindingName);
    } catch (RemoteException lRE) {
        LOGGER.log(Level.SEVERE, "Master: Problem with contacting the RMI Registry: ", lRE);
        System.exit(-1);
    } catch (IOException lE) {
        LOGGER.log(Level.SEVERE, "Master: Problem with starting up TestMaster: ", lE);
        System.exit(-1);
    }
}

From source file:cc.kave.commons.pointsto.evaluation.DefaultModule.java

@Override
protected void configure() {
    configCrossValidation();//from   w w w . j a v  a 2s  .c o m
    configOptions();

    configMeasure();

    bind(new TypeLiteral<Predicate<Usage>>() {
    }).annotatedWith(UsageFilter.class).to(PointsToUsageFilter.class);
    bind(ResultExporter.class).to(CSVExporter.class);

    // Executor for CVEvaluator
    int numThreads;
    if (System.getProperties().containsKey("evaluation.numthreads")) {
        numThreads = Integer.parseInt(System.getProperty("evaluation.numthreads"));
    } else {
        numThreads = Math.min(6, Runtime.getRuntime().availableProcessors());
    }
    ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
    // ExecutorService executorService = Executors.newSingleThreadExecutor();
    bind(ExecutorService.class).toInstance(executorService);
}