Home / Class/ HttpUploadClient Class — netty Architecture

HttpUploadClient Class — netty Architecture

Architecture documentation for the HttpUploadClient class in HttpUploadClient.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  b9da3ba5_7453_22c6_2d8f_69c79b4ca314["HttpUploadClient"]
  2d52e0ec_7b8c_a248_ab8f_a4dc28a44ba4["HttpUploadClient.java"]
  b9da3ba5_7453_22c6_2d8f_69c79b4ca314 -->|defined in| 2d52e0ec_7b8c_a248_ab8f_a4dc28a44ba4
  9eb10f57_11e0_77d4_dfe6_470ff611d081["main()"]
  b9da3ba5_7453_22c6_2d8f_69c79b4ca314 -->|method| 9eb10f57_11e0_77d4_dfe6_470ff611d081
  a87d0f14_a3fe_b3ad_40f3_d0415237ca9a["formget()"]
  b9da3ba5_7453_22c6_2d8f_69c79b4ca314 -->|method| a87d0f14_a3fe_b3ad_40f3_d0415237ca9a
  74523085_3ff4_6038_bdc0_b90d4585970b["formpost()"]
  b9da3ba5_7453_22c6_2d8f_69c79b4ca314 -->|method| 74523085_3ff4_6038_bdc0_b90d4585970b
  d9705f9a_6272_0aa0_3cd7_4bfaf6636ab5["formpostmultipart()"]
  b9da3ba5_7453_22c6_2d8f_69c79b4ca314 -->|method| d9705f9a_6272_0aa0_3cd7_4bfaf6636ab5

Relationship Graph

Source Code

example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java lines 56–901

public final class HttpUploadClient {

    static final String BASE_URL = System.getProperty("baseUrl", "http://127.0.0.1:8080/");
    static final String FILE = System.getProperty("file", "upload.txt");

    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 {

Frequently Asked Questions

What is the HttpUploadClient class?
HttpUploadClient is a class in the netty codebase, defined in example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java.
Where is HttpUploadClient defined?
HttpUploadClient is defined in example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java at line 56.

Analyze Your Own Codebase

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

Try Supermodel Free