Skip to content

Commit 9bdabc1

Browse files
authored
Merge pull request #1180 from sschuberth/json-message
Unwrap JSON messages in ResponseStatusExceptionFilter
2 parents f67d2a6 + 2769032 commit 9bdabc1

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/main/java/com/github/dockerjava/jaxrs/filter/ResponseStatusExceptionFilter.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
import org.apache.commons.io.IOUtils;
1313

14+
import com.fasterxml.jackson.databind.JsonNode;
15+
import com.fasterxml.jackson.databind.ObjectMapper;
16+
1417
import com.github.dockerjava.api.exception.BadRequestException;
1518
import com.github.dockerjava.api.exception.ConflictException;
1619
import com.github.dockerjava.api.exception.DockerException;
@@ -55,7 +58,7 @@ public void filter(ClientRequestContext requestContext, ClientResponseContext re
5558
}
5659
}
5760

58-
private String getBodyAsMessage(ClientResponseContext responseContext) throws IOException {
61+
private String getBodyAsMessage(ClientResponseContext responseContext) {
5962
if (responseContext.hasEntity()) {
6063
try (InputStream entityStream = responseContext.getEntityStream()) {
6164
Charset charset = null;
@@ -73,7 +76,17 @@ private String getBodyAsMessage(ClientResponseContext responseContext) throws IO
7376
charset = Charset.defaultCharset();
7477
}
7578

76-
return IOUtils.toString(entityStream, charset);
79+
String message = IOUtils.toString(entityStream, charset);
80+
81+
if (MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
82+
ObjectMapper mapper = new ObjectMapper();
83+
JsonNode node = mapper.readTree(entityStream).get("message");
84+
if (node != null) {
85+
message = node.textValue();
86+
}
87+
}
88+
89+
return message;
7790
} catch (Exception ignored) { }
7891
}
7992
return null;

src/test/java/com/github/dockerjava/cmd/LoadImageCmdIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void loadImageFromTar() throws Exception {
4141
dockerRule.getClient().loadImageCmd(uploadStream).exec();
4242
}
4343

44-
//swarm needs some time to refelct new images
44+
//swarm needs some time to reflect new images
4545
synchronized (this) {
4646
wait(5000);
4747
}

0 commit comments

Comments
 (0)