Für mich (Diese Meldung Forum bei http://thread.gmane.org/gmane.network.samba.java/9554 geschrieben wurde jCIFS)
das Problem ist, dass jCIFS eine neue hüllt HttpURLConnection, so dass es alle für die ursprüngliche Verbindung definierten Einstellungen wie die Timeout-Einstellungen verliert. Um dies zu beweisen, benutze ich entweder Reflektion oder ich modifiziere die Bibliothek und ändere die interne jcif-Verbindung, dann funktioniert das Timeout gut.
(Informationen Einstellung jcifs.smb.client.responseTimeout und jcifs.smb.client.soTimeout nicht funktioniert)
Zuerst habe ich bestätigen, dass jCIFS ist das Problem: mein Timeout von 15000ms funktioniert nicht bei allen Wenn ich jcifs.Config.registerSmbURLHandler() verwende, bricht die Verbindung nach 30000ms ab. Meine 15000ms Timeout funktioniert nur, wenn ich den Aufruf von RegisterSmbURLHandler() entfernen.
In Bezug auf das Problem, öffne ich eine Verbindung (mit jCIFS registriert vorher):
URLConnection myConnection = new URL(url).openConnection();
Dann wird die URLStreamHandler eine NtlmHttpURLConnection Verpackung erzeugt und versteckt die reale HttpURLConnection:
protected URLConnection openConnection(URL url) throws IOException {
url = new URL(url, url.toExternalForm(),
getDefaultStreamHandler(url.getProtocol()));
return new NtlmHttpURLConnection((HttpURLConnection)
url.openConnection());
}
meine Timeout-Einstellungen So Werden sie auf den Wrapper NtlmHttpURLConnection angewendet, wird sie nicht auf die tatsächlich geöffnete URLConnection angewendet. Also meine Timeout sind nutzlos:
myConnection.setReadTimeout(15000); // applied to the new NtlmHttpURLConnection(wrapped), not the real wrapped one
myConnection.setConnectTimeout(15000); // applied to the new NtlmHttpURLConnection(wrapped), not the real wrapped one
Es gibt zwei Lösungen, die ich verwenden können, das Timeout auf der umwickelte Verbindung zu ändern: mit Reflexion oder mit einer festen Bibliothek.
Mit Reflexion, greife ich auf die private gewickelte Verbindung und ändern Sie die privaten Felder und connectReadTimeout:
Class<?> classConnection = myConnection.getClass();
Field privateFieldURLConnection = classConnection.getDeclaredField("connection");
privateFieldURLConnection.setAccessible(true);
URLConnection privateURLConnection = (URLConnection) privateFieldURLConnection.get(myConnection);
Class<?> classURLConnectionPrivate = privateURLConnection.getClass();
Field privateFieldConnectTimeout = classURLConnectionPrivate.getDeclaredField("connectTimeout");
privateFieldConnectTimeout.setAccessible(true);
privateFieldConnectTimeout.setInt(privateURLConnection, 15000);
Field privateFieldReadTimeout = classURLConnectionPrivate.getDeclaredField("readTimeout");
privateFieldReadTimeout.setAccessible(true);
privateFieldReadTimeout.setInt(privateURLConnection, 15000);
Oder ich die jCIFS Bibliothek ändern und den Konstruktor NtlmHttpURLConnection():
public NtlmHttpURLConnection(HttpURLConnection connection) {
super(connection.getURL());
this.connection = connection;
this.connection.setReadTimeout(15000);
this.connection.setConnectTimeout(15000);
requestProperties = new HashMap();
}