Java Code Examples for io.netty.util.internal.SystemPropertyUtil#get()

The following examples show how to use io.netty.util.internal.SystemPropertyUtil#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NettySocketSslContext.java    From wind-im with Apache License 2.0 6 votes vote down vote up
private NettySocketSslContext() {
	String algorithm = SystemPropertyUtil.get("ssl.KeyManagerFactory.algorithm");
	if (algorithm == null) {
		algorithm = "SunX509";
	}

	try {
		//
		KeyStore keystore = KeyStore.getInstance("JKS");
		keystore.load(SslKeyStore.asInputStream(), SslKeyStore.getKeyStorePassword());

		// Set up key manager factory to use our key store
		KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
		kmf.init(keystore, SslKeyStore.getCertificatePassword());

		// Initialize the SSLContext to work with our key managers.
		serverContext = SSLContext.getInstance(PROTOCOL);
		serverContext.init(kmf.getKeyManagers(), null, null);
	} catch (Exception e) {
		throw new Error("Failed to initialize the server-side SSLContext", e);
	}

}
 
Example 2
Source File: NettyRuntimeTests.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressForbidden(reason = "testing fallback to Runtime#availableProcessors")
public void testGet() {
    final String availableProcessorsSystemProperty = SystemPropertyUtil.get("io.netty.availableProcessors");
    try {
        System.clearProperty("io.netty.availableProcessors");
        final NettyRuntime.AvailableProcessorsHolder holder = new NettyRuntime.AvailableProcessorsHolder();
        assertThat(holder.availableProcessors(), equalTo(Runtime.getRuntime().availableProcessors()));
    } finally {
        if (availableProcessorsSystemProperty != null) {
            System.setProperty("io.netty.availableProcessors", availableProcessorsSystemProperty);
        } else {
            System.clearProperty("io.netty.availableProcessors");
        }
    }
}
 
Example 3
Source File: NettySocketSslContext.java    From openzaly with Apache License 2.0 6 votes vote down vote up
private NettySocketSslContext() {
	String algorithm = SystemPropertyUtil.get("ssl.KeyManagerFactory.algorithm");
	if (algorithm == null) {
		algorithm = "SunX509";
	}

	try {
		//
		KeyStore keystore = KeyStore.getInstance("JKS");
		keystore.load(SslKeyStore.asInputStream(), SslKeyStore.getKeyStorePassword());

		// Set up key manager factory to use our key store
		KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
		kmf.init(keystore, SslKeyStore.getCertificatePassword());

		// Initialize the SSLContext to work with our key managers.
		serverContext = SSLContext.getInstance(PROTOCOL);
		serverContext.init(kmf.getKeyManagers(), null, null);
	} catch (Exception e) {
		throw new Error("Failed to initialize the server-side SSLContext", e);
	}

}
 
Example 4
Source File: NettySocketSslContext.java    From openzaly with Apache License 2.0 6 votes vote down vote up
private NettySocketSslContext() {
	String algorithm = SystemPropertyUtil.get("ssl.KeyManagerFactory.algorithm");
	if (algorithm == null) {
		algorithm = "SunX509";
	}

	try {
		//
		KeyStore keystore = KeyStore.getInstance("JKS");
		keystore.load(SslKeyStore.asInputStream(), SslKeyStore.getKeyStorePassword());

		// Set up key manager factory to use our key store
		KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
		kmf.init(keystore, SslKeyStore.getCertificatePassword());

		// Initialize the SSLContext to work with our key managers.
		serverContext = SSLContext.getInstance(PROTOCOL);
		serverContext.init(kmf.getKeyManagers(), null, null);
	} catch (Exception e) {
		throw new Error("Failed to initialize the server-side SSLContext", e);
	}

}
 
Example 5
Source File: AbstractBootstrapServer.java    From InChat with Apache License 2.0 6 votes vote down vote up
private void initSsl(InitNetty serverBean){
    ExecutorService executorService = Executors.newCachedThreadPool();
    executorService.submit(() -> {});
    String algorithm = SystemPropertyUtil.get("ssl.KeyManagerFactory.algorithm");
    if (algorithm == null) {
        algorithm = "SunX509";
    }
    SSLContext serverContext;
    try {
        //
        KeyStore ks = KeyStore.getInstance("JKS");
        ks.load( SecureSocketSslContextFactory.class.getResourceAsStream(serverBean.getJksFile()),
                serverBean.getJksStorePassword().toCharArray());
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
        kmf.init(ks,serverBean.getJksCertificatePassword().toCharArray());
        serverContext = SSLContext.getInstance(PROTOCOL);
        serverContext.init(kmf.getKeyManagers(), null, null);
    } catch (Exception e) {
        throw new Error(
                "Failed to initialize the server-side SSLContext", e);
    }
    SERVER_CONTEXT = serverContext;
}
 
Example 6
Source File: HttpStaticFileServerHandler.java    From timely with Apache License 2.0 6 votes vote down vote up
private static String sanitizeUri(String uri) {
    // Decode the path.
    try {
        uri = URLDecoder.decode(uri, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new Error(e);
    }

    if (uri.isEmpty() || uri.charAt(0) != '/') {
        return null;
    }

    // Convert file separators.
    uri = uri.replace('/', File.separatorChar);

    // Simplistic dumb security check.
    // You will have to do something serious in the production environment.
    if (uri.contains(File.separator + '.') || uri.contains('.' + File.separator) || uri.charAt(0) == '.'
            || uri.charAt(uri.length() - 1) == '.' || INSECURE_URI.matcher(uri).matches()) {
        return null;
    }

    // Convert to absolute path.
    return SystemPropertyUtil.get("user.dir") + File.separator + uri;
}
 
Example 7
Source File: HttpStaticFileServerHandler.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private static String sanitizeUri(String uri) {
    // Decode the path.
    try {
        uri = URLDecoder.decode(uri, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new Error(e);
    }

    if (uri.isEmpty() || uri.charAt(0) != '/') {
        return null;
    }

    // Convert file separators.
    uri = uri.replace('/', File.separatorChar);

    // Simplistic dumb security check.
    // You will have to do something serious in the production environment.
    if (uri.contains(File.separator + '.') ||
        uri.contains('.' + File.separator) ||
        uri.charAt(0) == '.' || uri.charAt(uri.length() - 1) == '.' ||
        INSECURE_URI.matcher(uri).matches()) {
        return null;
    }

    // Convert to absolute path.
    return SystemPropertyUtil.get("user.dir") + File.separator + uri;
}
 
Example 8
Source File: NettyRuntimeTests.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetWithSystemProperty() {
    final String availableProcessorsSystemProperty = SystemPropertyUtil.get("io.netty.availableProcessors");
    try {
        System.setProperty("io.netty.availableProcessors", "2048");
        final NettyRuntime.AvailableProcessorsHolder holder = new NettyRuntime.AvailableProcessorsHolder();
        assertThat(holder.availableProcessors(), equalTo(2048));
    } finally {
        if (availableProcessorsSystemProperty != null) {
            System.setProperty("io.netty.availableProcessors", availableProcessorsSystemProperty);
        } else {
            System.clearProperty("io.netty.availableProcessors");
        }
    }
}
 
Example 9
Source File: HttpStaticFileServerHandler.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
private static String sanitizeUri(String uri) {
    // Decode the path.
    try {
        uri = URLDecoder.decode(uri, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new Error(e);
    }

    if (uri.isEmpty() || uri.charAt(0) != '/') {
        return null;
    }

    // Convert file separators.
    uri = uri.replace('/', File.separatorChar);

    // Simplistic dumb security check.
    // You will have to do something serious in the production environment.
    if (uri.contains(File.separator + '.') ||
        uri.contains('.' + File.separator) ||
        uri.charAt(0) == '.' || uri.charAt(uri.length() - 1) == '.' ||
        INSECURE_URI.matcher(uri).matches()) {
        return null;
    }

    // Convert to absolute path.
    return SystemPropertyUtil.get("user.dir") + File.separator + uri;
}
 
Example 10
Source File: Holder.java    From blynk-server with GNU General Public License v3.0 5 votes vote down vote up
private static void disableNettyLeakDetector() {
    String leakProperty = SystemPropertyUtil.get("io.netty.leakDetection.level");
    //we do not pass any with JVM option
    if (leakProperty == null) {
        System.setProperty("io.netty.leakDetection.level", "disabled");
    }
}
 
Example 11
Source File: HttpStaticFileServerHandler.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
private static String sanitizeUri(String uri) {
    // Decode the path.
    try {
        uri = URLDecoder.decode(uri, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new Error(e);
    }

    if (uri.isEmpty() || uri.charAt(0) != '/') {
        return null;
    }

    // Convert file separators.
    uri = uri.replace('/', File.separatorChar);

    // Simplistic dumb security check.
    // You will have to do something serious in the production environment.
    if (uri.contains(File.separator + '.') ||
        uri.contains('.' + File.separator) ||
        uri.charAt(0) == '.' || uri.charAt(uri.length() - 1) == '.' ||
        INSECURE_URI.matcher(uri).matches()) {
        return null;
    }

    // Convert to absolute path.
    return SystemPropertyUtil.get("user.dir") + File.separator + uri;
}
 
Example 12
Source File: AbstractMicrobenchmarkBase.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
protected String getReportDir() {
    return SystemPropertyUtil.get("perfReportDir");
}
 
Example 13
Source File: ReferenceCountedOpenSslContext.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
public String run() {
    return SystemPropertyUtil.get("jdk.tls.ephemeralDHKeySize");
}
 
Example 14
Source File: AbstractMicrobenchmark.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
protected String getReportDir() {
    return SystemPropertyUtil.get("perfReportDir");
}