1 org.apache.catalina.util.StringManager
tomcat将错误信息存储在properties文件中,这些properties文件分别位于不同的包中,包含该包中任何类可能抛出的所有异常信息。每个properties文件由stringManager的一个实例处理。错误信息的文件名为LocalStrings_language.properties。通过指定包名,获取stringManager。
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)方法
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 connector
http 1.1 特性
1 长连接
显示启用长久连接, 请求头设置 connection:keep-alive
2 块编码
资源分多次返回时,需告知content-length,客户端才知如何解析。但很多时候,不知content-length,可使用transfer-encoding的特殊请求头,指明字节流将会分块发送,每一块由16进制块长度+\r\n,换行,+具体数据。0\r\n表明事务已经完成。
3 状态码100
客户端准备发送较长请求体,不确定服务端是否接收时,发送 Expect: 100-continue请求头,等待服务端确认。若服务端可以接受并处理该请求,发送 Http/1.1 100 Continue响应头+crlf字符,然后继续读取输入流的内容
requestFacde