Home / Function/ main() — netty Function Reference

main() — netty Function Reference

Architecture documentation for the main() function in HttpUploadClient.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  9eb10f57_11e0_77d4_dfe6_470ff611d081["main()"]
  b9da3ba5_7453_22c6_2d8f_69c79b4ca314["HttpUploadClient"]
  9eb10f57_11e0_77d4_dfe6_470ff611d081 -->|defined in| b9da3ba5_7453_22c6_2d8f_69c79b4ca314
  a87d0f14_a3fe_b3ad_40f3_d0415237ca9a["formget()"]
  9eb10f57_11e0_77d4_dfe6_470ff611d081 -->|calls| a87d0f14_a3fe_b3ad_40f3_d0415237ca9a
  74523085_3ff4_6038_bdc0_b90d4585970b["formpost()"]
  9eb10f57_11e0_77d4_dfe6_470ff611d081 -->|calls| 74523085_3ff4_6038_bdc0_b90d4585970b
  d9705f9a_6272_0aa0_3cd7_4bfaf6636ab5["formpostmultipart()"]
  9eb10f57_11e0_77d4_dfe6_470ff611d081 -->|calls| d9705f9a_6272_0aa0_3cd7_4bfaf6636ab5
  style 9eb10f57_11e0_77d4_dfe6_470ff611d081 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java lines 61–143

    public static void main(String[] args) throws Exception {
        String postSimple, postFile, get;
        if (BASE_URL.endsWith("/")) {
            postSimple = BASE_URL + "formpost";
            postFile = BASE_URL + "formpostmultipart";
            get = BASE_URL + "formget";
        } else {
            postSimple = BASE_URL + "/formpost";
            postFile = BASE_URL + "/formpostmultipart";
            get = BASE_URL + "/formget";
        }

        URI uriSimple = new URI(postSimple);
        String scheme = uriSimple.getScheme() == null? "http" : uriSimple.getScheme();
        String host = uriSimple.getHost() == null? "127.0.0.1" : uriSimple.getHost();
        int port = uriSimple.getPort();
        if (port == -1) {
            if ("http".equalsIgnoreCase(scheme)) {
                port = 80;
            } else if ("https".equalsIgnoreCase(scheme)) {
                port = 443;
            }
        }

        if (!"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme)) {
            System.err.println("Only HTTP(S) is supported.");
            return;
        }

        final boolean ssl = "https".equalsIgnoreCase(scheme);
        final SslContext sslCtx;
        if (ssl) {
            sslCtx = SslContextBuilder.forClient()
                .trustManager(InsecureTrustManagerFactory.INSTANCE).build();
        } else {
            sslCtx = null;
        }

        URI uriFile = new URI(postFile);
        File file = new File(FILE);
        if (!file.canRead()) {
            throw new FileNotFoundException(FILE);
        }

        // Configure the client.
        EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());

        // setup the factory: here using a mixed memory/disk based on size threshold
        HttpDataFactory factory = new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE); // Disk if MINSIZE exceed

        DiskFileUpload.deleteOnExitTemporaryFile = true; // should delete file on exit (in normal exit)
        DiskFileUpload.baseDirectory = null; // system temp directory
        DiskAttribute.deleteOnExitTemporaryFile = true; // should delete file on exit (in normal exit)
        DiskAttribute.baseDirectory = null; // system temp directory

        try {
            Bootstrap b = new Bootstrap();
            b.group(group).channel(NioSocketChannel.class).handler(new HttpUploadClientInitializer(sslCtx));

            // Simple Get form: no factory used (not usable)
            List<Entry<String, String>> headers = formget(b, host, port, get, uriSimple);
            if (headers == null) {
                factory.cleanAllHttpData();
                return;
            }

            // Simple Post form: factory used for big attributes
            List<InterfaceHttpData> bodylist = formpost(b, host, port, uriSimple, file, factory, headers);
            if (bodylist == null) {
                factory.cleanAllHttpData();
                return;
            }

            // Multipart Post form: factory used
            formpostmultipart(b, host, port, uriFile, factory, headers, bodylist);
        } finally {
            // Shut down executor threads to exit.
            group.shutdownGracefully();

            // Really clean all temporary files if they still exist
            factory.cleanAllHttpData();

Domain

Subdomains

Frequently Asked Questions

What does main() do?
main() is a function in the netty codebase, defined in example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java.
Where is main() defined?
main() is defined in example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java at line 61.
What does main() call?
main() calls 3 function(s): formget, formpost, formpostmultipart.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free