tomcat-鏈接器

1 org.apache.catalina.util.StringManagerjava

        tomcat將錯誤信息存儲在properties文件中,這些properties文件分別位於不一樣的包中,包含該包中任何類可能拋出的全部異常信息。每一個properties文件由stringManager的一個實例處理。錯誤信息的文件名爲LocalStrings_language.properties。經過指定包名,獲取stringManager。apache

org.apache.catalina.tribes.util.StringManager

private static final Map<String, Map<Locale,StringManager>> managers =
            new Hashtable<>();


public static final StringManager getManager(String packageName) {
        return getManager(packageName, Locale.getDefault());
    }

public static final synchronized StringManager getManager(
            String packageName, Locale locale) {

        Map<Locale,StringManager> map = managers.get(packageName);
        if (map == null) {
            /*
             * Don't want the HashMap to be expanded beyond LOCALE_CACHE_SIZE.
             * Expansion occurs when size() exceeds capacity. Therefore keep
             * size at or below capacity.
             * removeEldestEntry() executes after insertion therefore the test
             * for removal needs to use one less than the maximum desired size
             *
             */
            map = new LinkedHashMap<Locale,StringManager>(LOCALE_CACHE_SIZE, 1, true) {
                private static final long serialVersionUID = 1L;
                @Override
                protected boolean removeEldestEntry(
                        Map.Entry<Locale,StringManager> eldest) {
                    if (size() > (LOCALE_CACHE_SIZE - 1)) {
                        return true;
                    }
                    return false;
                }
            };
            managers.put(packageName, map);
        }

        StringManager mgr = map.get(locale);
        if (mgr == null) {
            mgr = new StringManager(packageName, locale);
            map.put(locale, mgr);
        }
        return mgr;
    }

        想獲取錯誤信息,能夠使用getString(String key)方法tomcat

private final ResourceBundle bundle;

    private StringManager(String packageName, Locale locale) {
        String bundleName = packageName + ".LocalStrings";
        ResourceBundle bnd = null;
        try {
            bnd = ResourceBundle.getBundle(bundleName, locale);
        } catch (MissingResourceException ex) {
            // Try from the current loader (that's the case for trusted apps)
            // Should only be required if using a TC5 style classloader structure
            // where common != shared != server
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            if (cl != null) {
                try {
                    bnd = ResourceBundle.getBundle(bundleName, locale, cl);
                } catch (MissingResourceException ex2) {
                    // Ignore
                }
            }
        }
        bundle = bnd;
        // Get the actual locale, which may be different from the requested one
        if (bundle != null) {
            Locale bundleLocale = bundle.getLocale();
            if (bundleLocale.equals(Locale.ROOT)) {
                this.locale = Locale.ENGLISH;
            } else {
                this.locale = bundleLocale;
            }
        } else {
            this.locale = null;
        }
    }


    public String getString(String key) {
        if (key == null){
            String msg = "key may not have a null value";
            throw new IllegalArgumentException(msg);
        }

        String str = null;

        try {
            // Avoid NPE if bundle is null and treat it like an MRE
            if (bundle != null) {
                str = bundle.getString(key);
            }
        } catch (MissingResourceException mre) {
            //bad: shouldn't mask an exception the following way:
            //   str = "[cannot find message associated with key '" + key +
            //         "' due to " + mre + "]";
            //     because it hides the fact that the String was missing
            //     from the calling code.
            //good: could just throw the exception (or wrap it in another)
            //      but that would probably cause much havoc on existing
            //      code.
            //better: consistent with container pattern to
            //      simply return null.  Calling code can then do
            //      a null check.
            str = null;
        }

        return str;
    }

org.apache.catalina.connector.Connector     Implementation of a Coyote connectorapp

http 1.1 特性less

1 長鏈接ide

顯示啓用長久鏈接, 請求頭設置 connection:keep-aliveui

2 塊編碼this

資源分屢次返回時,需告知content-length,客戶端才知如何解析。但不少時候,不知content-length,可以使用transfer-encoding的特殊請求頭,指明字節流將會分塊發送,每一塊由16進制塊長度+\r\n,換行,+具體數據。0\r\n代表事務已經完成。編碼

3 狀態碼100code

客戶端準備發送較長請求體,不肯定服務端是否接收時,發送 Expect: 100-continue請求頭,等待服務端確認。若服務端能夠接受並處理該請求,發送 Http/1.1 100 Continue響應頭+crlf字符,而後繼續讀取輸入流的內容 

requestFacde

相關文章
相關標籤/搜索