jemand mit dem gleichen Problem konfrontiert ist hier, wie ich es gelöst habe. Da ich die * .css-Dateien in meinem CustomUserAgent nicht zwischenspeichern konnte, musste ich einen anderen Weg finden. Meine Lösung verwendet Squid als http-Proxy, um alle häufig verwendeten Ressourcen zwischenzuspeichern.
In meinem CustomUserAgent muss ich nur auf diesen Proxy zugreifen, indem ich das Proxy-Objekt übergebe.
public class ResourceLoaderUserAgent extends ITextUserAgent {
public ResourceLoaderUserAgent(ITextOutputDevice outputDevice) {
super(outputDevice);
}
protected InputStream resolveAndOpenStream(String uri) {
HttpURLConnection connection = null;
URL proxyUrl = null;
try {
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 3128));
proxyUrl = new URL(uri);
connection = (HttpURLConnection) proxyUrl.openConnection(proxy);
connection.connect();
} catch (Exception e) {
throw new RuntimeException(e);
}
java.io.InputStream is = null;
try {
is = connection.getInputStream();
} catch (java.net.MalformedURLException e) {
XRLog.exception("bad URL given: " + uri, e);
} catch (java.io.FileNotFoundException e) {
XRLog.exception("item at URI " + uri + " not found");
} catch (java.io.IOException e) {
XRLog.exception("IO problem for " + uri, e);
}
return is;
}
}
gecached:
resolving css took 74 ms
resolving images took 225 ms
uncached:
resolving css took 15466 ms
resolving images took 11236 ms
, wie Sie die differents zwischen zwischengespeichert und uncached Ressourcen sehen können, von Bedeutung sind