Skip to content

Commit

Permalink
Fix #124 by adding info to timeout exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
FroMage committed Sep 2, 2015
1 parent 15ce455 commit 93ec966
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
Expand Up @@ -21,6 +21,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -127,7 +128,13 @@ public ContentHandle putContent(Node node, InputStream stream, ContentOptions op
file = new File(path + node.getLabel()); // just concat paths
}

IOUtils.writeToFile(file, stream);
try{
IOUtils.writeToFile(file, stream);
}catch(SocketTimeoutException ex){
SocketTimeoutException newEx = new SocketTimeoutException("Timed out reading "+node.getDisplayString()+" from "+node.getStoreDisplayString());
newEx.initCause(ex);
throw newEx;
}
return new FileContentHandle(node, file);
}

Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.io.Serializable;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Collections;
Expand Down Expand Up @@ -58,14 +59,20 @@ protected InputStream openStream(final URL url) throws IOException {
huc.setConnectTimeout(timeout);
huc.setReadTimeout(timeout * Constants.READ_TIMEOUT_MULTIPLIER);
addCredentials(huc);
InputStream stream = conn.getInputStream();
int code = huc.getResponseCode();
if (code != -1 && code != 200) {
log.info("Got " + code + " for url: " + url);
return null;
try{
InputStream stream = conn.getInputStream();
int code = huc.getResponseCode();
if (code != -1 && code != 200) {
log.info("Got " + code + " for url: " + url);
return null;
}
log.debug("Got " + code + " for url: " + url);
return stream;
}catch(SocketTimeoutException timeoutException){
SocketTimeoutException newException = new SocketTimeoutException("Timed out during connection to "+url);
newException.initCause(timeoutException);
throw newException;
}
log.debug("Got " + code + " for url: " + url);
return stream;
}
}
return null;
Expand Down
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.Proxy;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -147,10 +148,14 @@ public ContentHandle putContent(Node node, InputStream stream, ContentOptions op
String token = null;
if (!isHerd())
token = s.lock(pUrl); // local parent
final String url = getUrlAsString(node);
try {
final String url = getUrlAsString(node);
s.put(url, stream);
return new WebDAVContentHandle(url);
} catch (SocketTimeoutException x) {
SocketTimeoutException ret = new SocketTimeoutException("Timed out writing to "+url);
ret.initCause(x);
throw ret;
} finally {
if (!isHerd())
s.unlock(pUrl, token);
Expand Down

0 comments on commit 93ec966

Please sign in to comment.