private WebXml getDefaultWebXmlFragment() {
// Host should never be null
Host host = (Host) context.getParent();
DefaultWebXmlCacheEntry entry = hostWebXmlCache.get(host);
InputSource globalWebXml = getGlobalWebXmlSource();
InputSource hostWebXml = getHostWebXmlSource();
long globalTimeStamp = 0;
long hostTimeStamp = 0;
if (globalWebXml != null) {
try {
URL url = new URL(globalWebXml.getSystemId());
globalTimeStamp = url.openConnection().getLastModified();
} catch (MalformedURLException e) {
globalTimeStamp = -1;
} catch (IOException e) {
globalTimeStamp = -1;
}
}
if (hostWebXml != null) {
try {
URL url = new URL(hostWebXml.getSystemId());
hostTimeStamp = url.openConnection().getLastModified();
} catch (MalformedURLException e) {
hostTimeStamp = -1;
} catch (IOException e) {
hostTimeStamp = -1;
}
}
if (entry != null && entry.getGlobalTimeStamp() == globalTimeStamp &&
entry.getHostTimeStamp() == hostTimeStamp) {
return entry.getWebXml();
}
// Parsing global web.xml is relatively expensive. Use a sync block to
// make sure it only happens once. Use the pipeline since a lock will
// already be held on the host by another thread
synchronized (host.getPipeline()) {
entry = hostWebXmlCache.get(host);
if (entry != null && entry.getGlobalTimeStamp() == globalTimeStamp &&
entry.getHostTimeStamp() == hostTimeStamp) {
return entry.getWebXml();
}