[jcifs] Timeout still failing on v1.3.18

ron190 ron190 at ymail.com
Sat Jul 16 21:31:45 UTC 2016

For me the problem is that jcifs wraps a new HttpURLConnection so it loses
every settings defined on the original connection, like the timeout
settings. To prove this either I use reflection or I modify the library and
change jcifs internal connection, then the timeout works fine.

(For information setting jcifs.smb.client.responseTimeout and
jcifs.smb.client.soTimeout does not work)

First, I validate that jcifs is the problem : my timeout of 15000ms does not
work at all when I use jcifs.Config.registerSmbURLHandler(), connection
breaks after 30000ms. My 15000ms timeout works only if I remove the call to

Regarding the problem, I open a connection (with jcifs previously registered) :

    URLConnection myConnection = new URL(url).openConnection();

Then the URLStreamHandler creates a wrapping NtlmHttpURLConnection and hides
the real HttpURLConnection :

    protected URLConnection openConnection(URL url) throws IOException {
        url = new URL(url, url.toExternalForm(),
        return new NtlmHttpURLConnection((HttpURLConnection)

So my timeout settings are applied to the wrapper NtlmHttpURLConnection,
it's not applied to the true opened URLConnection. So my timeout are useless :

    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

There are two solutions I can use to change the timeout on the wrapped
connection : with reflection or with a fixed library.

With reflection, I access the private wrapped connection and change the
private fields connectTimeout and readTimeout :

    Class<?> classConnection = myConnection.getClass();

    Field privateFieldURLConnection =
    URLConnection privateURLConnection = (URLConnection)
    Class<?> classURLConnectionPrivate = privateURLConnection.getClass();
    Field privateFieldConnectTimeout =
    privateFieldConnectTimeout.setInt(privateURLConnection, 15000);
    Field privateFieldReadTimeout =
    privateFieldReadTimeout.setInt(privateURLConnection, 15000);

Or I modify the jcifs library and the constructor NtlmHttpURLConnection() :

    public NtlmHttpURLConnection(HttpURLConnection connection) {
        this.connection = connection;
        requestProperties = new HashMap();

These solutions are working but it's only a workaround, please can someone
take this problem into account ?

More information about the jCIFS mailing list