|
44 | 44 | import org.slf4j.Logger; |
45 | 45 | import org.slf4j.LoggerFactory; |
46 | 46 |
|
47 | | -import java.io.ByteArrayInputStream; |
48 | 47 | import java.io.IOException; |
49 | 48 | import java.io.InputStream; |
50 | 49 | import java.io.InterruptedIOException; |
@@ -488,11 +487,7 @@ protected <T> T handleGet(URL resourceUrl, Class<T> type) throws InterruptedExce |
488 | 487 | * Send a raw get - where the type should be one of String, Reader, InputStream |
489 | 488 | */ |
490 | 489 | protected <T> T handleRawGet(URL resourceUrl, Class<T> type) throws IOException { |
491 | | - HttpRequest.Builder requestBuilder = httpClient.newHttpRequestBuilder().url(resourceUrl); |
492 | | - HttpRequest request = requestBuilder.build(); |
493 | | - HttpResponse<T> response = waitForResult(httpClient.sendAsync(request, type)); |
494 | | - assertResponseCode(request, response); |
495 | | - return response.body(); |
| 490 | + return handleRaw(type, resourceUrl.toString(), "GET", null); |
496 | 491 | } |
497 | 492 |
|
498 | 493 | /** |
@@ -569,11 +564,11 @@ protected <T> CompletableFuture<T> handleResponse(HttpClient client, HttpRequest |
569 | 564 | VersionUsageUtils.log(this.resourceT, this.apiGroupVersion); |
570 | 565 | HttpRequest request = requestBuilder.build(); |
571 | 566 |
|
572 | | - return client.sendAsync(request, byte[].class).thenApply(response -> { |
| 567 | + return client.sendAsync(request, InputStream.class).thenApply(response -> { |
573 | 568 | try { |
574 | 569 | assertResponseCode(request, response); |
575 | 570 | if (type != null && type.getType() != null) { |
576 | | - return Serialization.unmarshal(new ByteArrayInputStream(response.body()), type); |
| 571 | + return Serialization.unmarshal(response.body(), type); |
577 | 572 | } else { |
578 | 573 | return null; |
579 | 574 | } |
@@ -760,4 +755,28 @@ public <R1> R1 restCall(Class<R1> result, String... path) { |
760 | 755 | } |
761 | 756 | } |
762 | 757 |
|
| 758 | + /** |
| 759 | + * Send a raw request - where the type should be one of String, Reader, InputStream |
| 760 | + */ |
| 761 | + public <R1> R1 handleRaw(Class<R1> result, String uri, String method, Object payload) { |
| 762 | + try { |
| 763 | + if (uri.startsWith("/")) { |
| 764 | + // master ends with slash |
| 765 | + uri = config.getMasterUrl() + uri.substring(1, uri.length()); |
| 766 | + } |
| 767 | + String body = null; |
| 768 | + if (payload instanceof String) { |
| 769 | + body = (String) payload; |
| 770 | + } else if (payload != null) { |
| 771 | + body = Serialization.asJson(payload); |
| 772 | + } |
| 773 | + HttpRequest request = httpClient.newHttpRequestBuilder().uri(uri).method(method, JSON, body).build(); |
| 774 | + HttpResponse<R1> response = waitForResult(httpClient.sendAsync(request, result)); |
| 775 | + assertResponseCode(request, response); |
| 776 | + return response.body(); |
| 777 | + } catch (IOException e) { |
| 778 | + throw KubernetesClientException.launderThrowable(e); |
| 779 | + } |
| 780 | + } |
| 781 | + |
763 | 782 | } |
0 commit comments