Skip to content

Commit 9f61824

Browse files
committed
Logout and close connection handling.
1 parent 62c519b commit 9f61824

File tree

23 files changed

+143
-55
lines changed

23 files changed

+143
-55
lines changed

azure/src/main/java/ch/cyberduck/core/azure/AzureSession.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import ch.cyberduck.core.Credentials;
19+
import ch.cyberduck.core.DefaultIOExceptionMappingService;
1920
import ch.cyberduck.core.Host;
2021
import ch.cyberduck.core.HostKeyCallback;
2122
import ch.cyberduck.core.HostUrlProvider;
@@ -38,6 +39,7 @@
3839
import org.apache.logging.log4j.LogManager;
3940
import org.apache.logging.log4j.Logger;
4041

42+
import java.io.IOException;
4143
import java.util.Collections;
4244

4345
import com.azure.core.credential.AzureSasCredential;
@@ -142,8 +144,20 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
142144
}
143145

144146
@Override
145-
protected void logout() {
146-
//
147+
public void close() throws BackgroundException {
148+
try {
149+
if(client != null) {
150+
try {
151+
((ApacheHttpClient) client.getHttpPipeline().getHttpClient()).getHttpClient().close();
152+
}
153+
catch(IOException e) {
154+
throw new DefaultIOExceptionMappingService().map(e);
155+
}
156+
}
157+
}
158+
finally {
159+
super.close();
160+
}
147161
}
148162

149163
@Override

azure/src/main/java/ch/cyberduck/core/azure/apache/ApacheHttpClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.commons.lang3.StringUtils;
2121
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
2222
import org.apache.http.entity.ByteArrayEntity;
23+
import org.apache.http.impl.client.CloseableHttpClient;
2324
import org.apache.http.impl.client.HttpClientBuilder;
2425
import org.apache.http.protocol.HTTP;
2526
import reactor.core.publisher.Mono;
@@ -29,12 +30,16 @@
2930
import java.net.URL;
3031

3132
public class ApacheHttpClient implements HttpClient {
32-
private final org.apache.http.client.HttpClient httpClient;
33+
private final CloseableHttpClient httpClient;
3334

3435
public ApacheHttpClient(final HttpClientBuilder builder) {
3536
this.httpClient = builder.build();
3637
}
3738

39+
public CloseableHttpClient getHttpClient() {
40+
return httpClient;
41+
}
42+
3843
public Mono<HttpResponse> send(final HttpRequest azureRequest) {
3944
try {
4045
ApacheHttpRequest apacheRequest = new ApacheHttpRequest(azureRequest.getHttpMethod(), azureRequest.getUrl(),

backblaze/src/main/java/ch/cyberduck/core/b2/B2Session.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,24 @@ protected B2ApiClient connect(final ProxyFinder proxy, final HostKeyCallback key
6868
}
6969

7070
@Override
71-
public void logout() throws BackgroundException {
71+
public void close() throws BackgroundException {
7272
try {
73+
fileid.clear();
7374
client.close();
7475
}
7576
catch(IOException e) {
7677
throw new DefaultIOExceptionMappingService().map(e);
7778
}
7879
finally {
79-
fileid.clear();
80+
super.close();
8081
}
8182
}
8283

84+
@Override
85+
protected void disconnect() {
86+
super.disconnect();
87+
}
88+
8389
@Override
8490
public void login(final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
8591
try {

box/src/main/java/ch/cyberduck/core/box/BoxSession.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,16 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
8787
}
8888

8989
@Override
90-
protected void logout() throws BackgroundException {
90+
public void close() throws BackgroundException {
9191
try {
92+
fileid.clear();
9293
client.close();
9394
}
9495
catch(IOException e) {
9596
throw new DefaultIOExceptionMappingService().map(e);
9697
}
9798
finally {
98-
fileid.clear();
99+
super.close();
99100
}
100101
}
101102

brick/src/main/java/ch/cyberduck/core/brick/BrickSession.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,18 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
111111
}
112112

113113
@Override
114-
protected void logout() throws BackgroundException {
114+
public void close() throws BackgroundException {
115115
try {
116-
client.close();
116+
if(client != null) {
117+
client.close();
118+
}
117119
}
118120
catch(IOException e) {
119121
throw new DefaultIOExceptionMappingService().map(e);
120122
}
123+
finally {
124+
super.close();
125+
}
121126
}
122127

123128
public Credentials pair(final Host bookmark, final ConnectionCallback alert, final LoginCallback prompt, final CancelCallback cancel,

core/src/test/java/ch/cyberduck/core/NullSession.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
3333
throw new LoginCanceledException();
3434
}
3535

36-
@Override
37-
protected void logout() {
38-
//
39-
}
40-
4136
@Override
4237
public AttributedList<Path> list(final Path folder, final ListProgressListener listener) throws BackgroundException {
4338
listener.chunk(folder, AttributedList.emptyList());

ctera/src/main/java/ch/cyberduck/core/ctera/CteraSession.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,15 @@ protected void logout() throws BackgroundException {
228228
}
229229
finally {
230230
super.logout();
231-
versionid.clear();
232231
}
233232
}
234233

234+
@Override
235+
public void close() throws BackgroundException {
236+
versionid.clear();
237+
super.close();
238+
}
239+
235240
@Override
236241
@SuppressWarnings("unchecked")
237242
public <T> T _getFeature(final Class<T> type) {

deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxSession.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,15 @@ public DeepcloudApiClient getDeepcloudClient() {
182182
}
183183

184184
@Override
185-
protected void logout() {
186-
client.getHttpClient().close();
185+
public void close() throws BackgroundException {
186+
try {
187+
if(client != null) {
188+
client.getHttpClient().close();
189+
}
190+
}
191+
finally {
192+
super.close();
193+
}
187194
}
188195

189196
@Override

dracoon/src/main/java/ch/cyberduck/core/sds/SDSSession.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,17 @@ public int hashCode() {
580580
}
581581

582582
@Override
583-
protected void logout() {
584-
scheduler.shutdown(false);
585-
client.getHttpClient().close();
586-
nodeid.clear();
583+
public void close() throws BackgroundException {
584+
try {
585+
scheduler.shutdown(false);
586+
nodeid.clear();
587+
if(client != null) {
588+
client.getHttpClient().close();
589+
}
590+
}
591+
finally {
592+
super.close();
593+
}
587594
}
588595

589596
@Override

dropbox/src/main/java/ch/cyberduck/core/dropbox/DropboxSession.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,16 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
124124
}
125125

126126
@Override
127-
protected void logout() throws BackgroundException {
127+
public void close() throws BackgroundException {
128128
try {
129129
((DropboxCommonsHttpRequestExecutor) client.getRequestConfig().getHttpRequestor()).close();
130130
}
131131
catch(IOException e) {
132132
throw new DefaultIOExceptionMappingService().map(e);
133133
}
134+
finally {
135+
super.close();
136+
}
134137
}
135138

136139
@Override

0 commit comments

Comments
 (0)