2016-07-16 16 views
0

Ich habe responseTimeout und soTimeout auf 15000ms gesetzt, aber ich bekomme immer noch ein Timeout nach 90000ms.Timeout mit jcifs definiert funktioniert nicht

Ich habe dies auf v1.3.18 und v1.3.17 getestet.

Als ich registrieren nicht die Standard-Timeout jCIFS für HttpURLConnection nach 15000ms korrekt auftritt:

connection.setReadTimeout(15000); 
connection.setConnectTimeout(15000); 

Aber wenn ich jCIFS registrieren dann die timout tritt nach 90000ms:

System.setProperty("jcifs.smb.client.responseTimeout", "15000"); 
System.setProperty("jcifs.smb.client.soTimeout", "15000"); 
jcifs.Config.registerSmbURLHandler(); 
[...] 
connection.setReadTimeout(15000); 
connection.setConnectTimeout(15000); 

Es scheint, Das JCIFs-Timeout und mein Standard-Timeout werden beide für einen anderen Wert ignoriert.

Ich habe auch versucht setProperty direkt auf Config, aber es ändert sich nicht:

jcifs.Config.setProperty("jcifs.smb.client.responseTimeout", "15000"); 
jcifs.Config.setProperty("jcifs.smb.client.soTimeout", "15000"); 

Antwort

2

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(); 
} 
Verwandte Themen