forked from devonfw/IDEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into devonfw#315-bugfixDocker
- Loading branch information
Showing
26 changed files
with
919 additions
and
299 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
cli/src/main/java/com/devonfw/tools/ide/io/HttpErrorResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.devonfw.tools.ide.io; | ||
|
||
import java.net.URI; | ||
import java.net.http.HttpClient.Version; | ||
import java.net.http.HttpHeaders; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.util.Collections; | ||
import java.util.Optional; | ||
import javax.net.ssl.SSLSession; | ||
|
||
/** | ||
* Implementation of {@link HttpResponse} in case of an {@link Throwable error} to prevent sub-sequent {@link NullPointerException}s. | ||
*/ | ||
public class HttpErrorResponse implements HttpResponse<Throwable> { | ||
|
||
private final Throwable error; | ||
|
||
private final HttpRequest request; | ||
|
||
private final URI uri; | ||
private static final HttpHeaders NO_HEADERS = HttpHeaders.of(Collections.emptyMap(), (x, y) -> true); | ||
|
||
/** | ||
* @param error the {@link Throwable} that was preventing the HTTP request for {@link #body()}. | ||
* @param request the {@link HttpRequest} for {@link #request()}. | ||
* @param uri the {@link URI} for {@link #uri()}. | ||
*/ | ||
public HttpErrorResponse(Throwable error, HttpRequest request, URI uri) { | ||
super(); | ||
this.error = error; | ||
this.request = request; | ||
this.uri = uri; | ||
} | ||
|
||
@Override | ||
public int statusCode() { | ||
return -1; | ||
} | ||
|
||
@Override | ||
public HttpRequest request() { | ||
return this.request; | ||
} | ||
|
||
@Override | ||
public Optional<HttpResponse<Throwable>> previousResponse() { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public HttpHeaders headers() { | ||
return NO_HEADERS; | ||
} | ||
|
||
@Override | ||
public Throwable body() { | ||
return this.error; | ||
} | ||
|
||
@Override | ||
public Optional<SSLSession> sslSession() { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public URI uri() { | ||
return this.uri; | ||
} | ||
|
||
@Override | ||
public Version version() { | ||
return Version.HTTP_2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.