Example usage for io.netty.util.internal SystemPropertyUtil get

List of usage examples for io.netty.util.internal SystemPropertyUtil get

Introduction

In this page you can find the example usage for io.netty.util.internal SystemPropertyUtil get.

Prototype

public static String get(String key) 

Source Link

Document

Returns the value of the Java system property with the specified key , while falling back to null if the property access fails.

Usage

From source file:adalightserver.http.HttpServer.java

License:Apache License

private static String sanitizeUri(String uri) {
    // Decode the path.
    try {/*from w w w .j av a  2 s.c o m*/
        uri = URLDecoder.decode(uri, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new Error(e);
    }

    if (!uri.startsWith("/")) {
        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.startsWith(".")
            || uri.endsWith(".") || INSECURE_URI.matcher(uri).matches()) {
        return null;
    }

    // Convert to absolute path.
    return SystemPropertyUtil.get("user.dir") + File.separator + "static" + File.separator + uri;
}

From source file:com.alibaba.rocketmq.remoting.netty.NettyRemotingClient.java

License:Apache License

public NettyRemotingClient(final NettyClientConfig nettyClientConfig, //
        final ChannelEventListener channelEventListener) {
    super(nettyClientConfig.getClientOnewaySemaphoreValue(), nettyClientConfig.getClientAsyncSemaphoreValue());
    String name = SystemPropertyUtil.get("os.name").toLowerCase(Locale.UK).trim();
    isLinux = name.startsWith("linux");
    isLinux = false;/*from   w ww .  j av  a  2s  .  c  o  m*/
    this.nettyClientConfig = nettyClientConfig;
    this.channelEventListener = channelEventListener;

    int publicThreadNums = nettyClientConfig.getClientCallbackExecutorThreads();
    if (publicThreadNums <= 0) {
        publicThreadNums = 4;
    }

    this.publicExecutor = Executors.newFixedThreadPool(publicThreadNums, new ThreadFactory() {
        private AtomicInteger threadIndex = new AtomicInteger(0);

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "NettyClientPublicExecutor_" + this.threadIndex.incrementAndGet());
        }
    });

    ThreadFactory workerThreadFactory = new ThreadFactory() {
        private AtomicInteger threadIndex = new AtomicInteger(0);

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, String.format("NettyClientSelector_%d", this.threadIndex.incrementAndGet()));
        }
    };

    if (isLinux) {
        this.eventLoopGroupWorker = new EpollEventLoopGroup(1, workerThreadFactory);
    } else {
        this.eventLoopGroupWorker = new NioEventLoopGroup(1, workerThreadFactory);
    }
}

From source file:com.alibaba.rocketmq.remoting.netty.NettyRemotingServer.java

License:Apache License

public NettyRemotingServer(final NettyServerConfig nettyServerConfig,
        final ChannelEventListener channelEventListener) {
    super(nettyServerConfig.getServerOnewaySemaphoreValue(), nettyServerConfig.getServerAsyncSemaphoreValue());
    String name = SystemPropertyUtil.get("os.name").toLowerCase(Locale.UK).trim();
    isLinux = name.startsWith("linux");
    isLinux = false; //TODO: java.lang.UnsupportedOperationException: unsupported message type: OneMessageTransfer (expected: ByteBuf, DefaultFileRegion)
    this.serverBootstrap = new ServerBootstrap();
    this.nettyServerConfig = nettyServerConfig;
    this.channelEventListener = channelEventListener;

    int publicThreadNums = nettyServerConfig.getServerCallbackExecutorThreads();
    if (publicThreadNums <= 0) {
        publicThreadNums = 4;/*from  w  w  w  . jav  a  2  s  . c  o m*/
    }

    this.publicExecutor = Executors.newFixedThreadPool(publicThreadNums, new ThreadFactory() {
        private AtomicInteger threadIndex = new AtomicInteger(0);

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "NettyServerPublicExecutor_" + this.threadIndex.incrementAndGet());
        }
    });

    ThreadFactory bossThreadFactory = new ThreadFactory() {
        private AtomicInteger threadIndex = new AtomicInteger(0);

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, String.format("NettyBossSelector_%d", this.threadIndex.incrementAndGet()));
        }
    };

    ThreadFactory workerThreadFactory = new ThreadFactory() {
        private AtomicInteger threadIndex = new AtomicInteger(0);
        private int threadTotal = nettyServerConfig.getServerSelectorThreads();

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, String.format("NettyServerSelector_%d_%d", threadTotal,
                    this.threadIndex.incrementAndGet()));
        }
    };

    if (isLinux) {
        this.eventLoopGroupBoss = new EpollEventLoopGroup(1, bossThreadFactory);
        this.eventLoopGroupWorker = new EpollEventLoopGroup(nettyServerConfig.getServerSelectorThreads(),
                workerThreadFactory);
    } else {
        this.eventLoopGroupBoss = new NioEventLoopGroup(1, bossThreadFactory);
        this.eventLoopGroupWorker = new NioEventLoopGroup(nettyServerConfig.getServerSelectorThreads(),
                workerThreadFactory);
    }
}

From source file:com.cats.version.httpserver.HttpStaticFileServerHandler.java

License:Apache License

private static String sanitizeUri(String uri) {
    // Decode the path.
    try {//from ww w . j a v a 2s .  com
        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;
}

From source file:com.creamsugardonut.HttpStaticFileServerHandler2.java

License:Apache License

private static String sanitizeUri(String uri) {
    // Decode the path.
    try {/*from w  ww  .  j av a  2 s .  c o m*/
        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()) {
        System.out.println("insecure");
        return null;
    }

    // Convert to absolute path.
    return SystemPropertyUtil.get("user.dir") + File.separator + uri;
}

From source file:com.e2e.management.HttpSocketHandler.java

License:Apache License

private static String sanitizeUri(String uri) {
    // Decode the path.
    try {//from  w  ww .  j  a va  2  s .  c om
        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 + "src" + File.separator + "test"
            + File.separator + "resources" + File.separator + "www" + uri;
}

From source file:com.earasoft.framework.http.WebSocketServerHandler.java

License:Apache License

private static String sanitizeUri(String rootPath, String uri) {
    // Decode the path.
    try {//ww  w . j  ava  2 s  .  co  m
        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 + rootPath + File.separator + uri;
}

From source file:com.just.server.http.file.HttpStaticFileServerHandler.java

License:Apache License

private static String sanitizeUri(String uri) {
    // Decode the path.
    try {//  w  ww . ja  v a 2s  . c om
        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);
    System.out.println(uri);
    // 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 + "website" + File.separator + uri;
}

From source file:com.lambdaworks.redis.UnixDomainSocketTest.java

License:Apache License

private void linuxOnly() {
    String osName = SystemPropertyUtil.get("os.name").toLowerCase(Locale.UK).trim();
    assumeTrue("Only supported on Linux, your os is " + osName, osName.startsWith("linux"));
}

From source file:com.ociweb.pronghorn.adapter.netty.impl.HttpStaticFileServerHandler.java

License:Apache License

@Override
public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
    if (!request.decoderResult().isSuccess()) {
        sendError(ctx, BAD_REQUEST);/*  w  w w. j  a  va  2 s . c  o m*/
        return;
    }

    if (request.method() != GET) {
        sendError(ctx, METHOD_NOT_ALLOWED);
        return;
    }

    final String uri = request.uri();

    final String path = sanitizeUri(uri, SystemPropertyUtil.get("user.dir"));

    if (path == null) {
        sendError(ctx, FORBIDDEN);
        return;
    }

    File file = new File(path);

    if (file.isHidden() || !file.exists()) {
        return;
    }

    if (file.isDirectory()) {
        if (uri.endsWith("/")) {
            sendListing(ctx, file);
        } else {
            sendRedirect(ctx, uri + '/');
        }
        return;
    }

    sendFile(ctx, request, file);
}