Skip to content

Commit fa13d49

Browse files
authored
Merge pull request #93 from laeubi/unwind_execpetion_java_http
Unwind the exception causes with Java11Http#performConnect
2 parents efe7c06 + b2e12ce commit fa13d49

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/src/org/eclipse/ecf/provider/filetransfer/httpclientjava/HttpClientRetrieveFileTransfer.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
import java.util.Collections;
3737
import java.util.List;
3838
import java.util.Map;
39+
import java.util.concurrent.CancellationException;
3940
import java.util.concurrent.CompletableFuture;
41+
import java.util.concurrent.ExecutionException;
4042
import java.util.concurrent.TimeUnit;
4143
import java.util.zip.GZIPInputStream;
4244

@@ -1006,11 +1008,26 @@ private IStatus performConnect(IProgressMonitor monitor) {
10061008
int ticks = 1;
10071009
monitor.beginTask(getRemoteFileURL().toString() + Messages.HttpClientRetrieveFileTransfer_CONNECTING_TASK_NAME, ticks);
10081010
try {
1009-
if (monitor.isCanceled())
1010-
throw newUserCancelledException();
1011+
if (monitor.isCanceled()) {
1012+
setDoneCanceled();
1013+
return Status.CANCEL_STATUS;
1014+
}
10111015
httpResponse = httpClient.sendAsync(httpRequest, BodyHandlers.ofInputStream());
10121016
responseCode = httpResponse.get(getConnectTimeout(),TimeUnit.MILLISECONDS).statusCode();
1013-
} catch (final Exception e) {
1017+
} catch (InterruptedException e) {
1018+
Thread.currentThread().interrupt();
1019+
setDoneCanceled();
1020+
return Status.CANCEL_STATUS;
1021+
} catch (CancellationException e) {
1022+
setDoneCanceled();
1023+
return Status.CANCEL_STATUS;
1024+
} catch (Exception e) {
1025+
if (e instanceof ExecutionException) {
1026+
Throwable cause = ((ExecutionException) e).getCause();
1027+
if (cause instanceof Exception) {
1028+
e = (Exception) cause;
1029+
}
1030+
}
10141031
Trace.catching(Activator.PLUGIN_ID, DebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "performConnect", e); //$NON-NLS-1$
10151032
if (!isDone()) {
10161033
setDoneException(e);

0 commit comments

Comments
 (0)