|
|
|
|
@ -36,7 +36,6 @@ import org.apache.hc.core5.http.Header;
@@ -36,7 +36,6 @@ import org.apache.hc.core5.http.Header;
|
|
|
|
|
import org.apache.hc.core5.http.HttpEntity; |
|
|
|
|
import org.apache.hc.core5.http.HttpHost; |
|
|
|
|
import org.apache.hc.core5.http.io.entity.AbstractHttpEntity; |
|
|
|
|
import org.apache.hc.core5.http.message.StatusLine; |
|
|
|
|
|
|
|
|
|
import org.springframework.boot.buildpack.platform.io.Content; |
|
|
|
|
import org.springframework.boot.buildpack.platform.io.IOConsumer; |
|
|
|
|
@ -51,6 +50,7 @@ import org.springframework.util.StringUtils;
@@ -51,6 +50,7 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
* @author Phillip Webb |
|
|
|
|
* @author Mike Smithson |
|
|
|
|
* @author Scott Frederick |
|
|
|
|
* @author Moritz Halbritter |
|
|
|
|
*/ |
|
|
|
|
abstract class HttpClientTransport implements HttpTransport { |
|
|
|
|
|
|
|
|
|
@ -159,12 +159,12 @@ abstract class HttpClientTransport implements HttpTransport {
@@ -159,12 +159,12 @@ abstract class HttpClientTransport implements HttpTransport {
|
|
|
|
|
ClassicHttpResponse response = this.client.executeOpen(this.host, request, null); |
|
|
|
|
int statusCode = response.getCode(); |
|
|
|
|
if (statusCode >= 400 && statusCode <= 500) { |
|
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
|
Errors errors = (statusCode != 500) ? getErrorsFromResponse(entity) : null; |
|
|
|
|
Message message = getMessageFromResponse(entity); |
|
|
|
|
StatusLine statusLine = new StatusLine(response); |
|
|
|
|
byte[] content = readContent(response); |
|
|
|
|
response.close(); |
|
|
|
|
Errors errors = (statusCode != 500) ? deserializeErrors(content) : null; |
|
|
|
|
Message message = deserializeMessage(content); |
|
|
|
|
throw new DockerEngineException(this.host.toHostString(), request.getUri(), statusCode, |
|
|
|
|
statusLine.getReasonPhrase(), errors, message); |
|
|
|
|
response.getReasonPhrase(), errors, message); |
|
|
|
|
} |
|
|
|
|
return new HttpClientResponse(response); |
|
|
|
|
} |
|
|
|
|
@ -173,19 +173,38 @@ abstract class HttpClientTransport implements HttpTransport {
@@ -173,19 +173,38 @@ abstract class HttpClientTransport implements HttpTransport {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Errors getErrorsFromResponse(HttpEntity entity) { |
|
|
|
|
private byte[] readContent(ClassicHttpResponse response) throws IOException { |
|
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
|
if (entity == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
try (InputStream stream = entity.getContent()) { |
|
|
|
|
if (stream == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
return stream.readAllBytes(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Errors deserializeErrors(byte[] content) { |
|
|
|
|
if (content == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
return SharedObjectMapper.get().readValue(entity.getContent(), Errors.class); |
|
|
|
|
return SharedObjectMapper.get().readValue(content, Errors.class); |
|
|
|
|
} |
|
|
|
|
catch (IOException ex) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Message getMessageFromResponse(HttpEntity entity) { |
|
|
|
|
private Message deserializeMessage(byte[] content) { |
|
|
|
|
if (content == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
return (entity.getContent() != null) |
|
|
|
|
? SharedObjectMapper.get().readValue(entity.getContent(), Message.class) : null; |
|
|
|
|
Message message = SharedObjectMapper.get().readValue(content, Message.class); |
|
|
|
|
return (message.getMessage() != null) ? message : null; |
|
|
|
|
} |
|
|
|
|
catch (IOException ex) { |
|
|
|
|
return null; |
|
|
|
|
|