diff --git a/webtau-core/src/main/java/com/twosigma/webtau/expectation/equality/handlers/ByteArrayCompareToHandler.java b/webtau-core/src/main/java/com/twosigma/webtau/expectation/equality/handlers/ByteArrayCompareToHandler.java index fb8aba41f..6be0a8e7c 100644 --- a/webtau-core/src/main/java/com/twosigma/webtau/expectation/equality/handlers/ByteArrayCompareToHandler.java +++ b/webtau-core/src/main/java/com/twosigma/webtau/expectation/equality/handlers/ByteArrayCompareToHandler.java @@ -21,8 +21,8 @@ import com.twosigma.webtau.expectation.equality.CompareToComparator; import com.twosigma.webtau.expectation.equality.CompareToHandler; -import javax.xml.bind.DatatypeConverter; import java.util.Arrays; +import java.util.Formatter; import java.util.Objects; public class ByteArrayCompareToHandler implements CompareToHandler { @@ -78,6 +78,15 @@ private String portionOfArrayAsHex(byte[] array, int startIdx) { String possibleEllipsisPrefix = startIdx > 0 ? "..." : ""; String possibleEllipsisSuffix = (startIdx + len) < array.length ? "..." : ""; - return possibleEllipsisPrefix + DatatypeConverter.printHexBinary(subArray) + possibleEllipsisSuffix; + return possibleEllipsisPrefix + renderAsHex(subArray) + possibleEllipsisSuffix; + } + + private String renderAsHex(byte[] content) { + Formatter formatter = new Formatter(); + for (byte b : content) { + formatter.format("%02X", b); + } + + return formatter.toString(); } } diff --git a/webtau-rest/src/main/java/com/twosigma/webtau/http/HttpDocumentation.java b/webtau-rest/src/main/java/com/twosigma/webtau/http/HttpDocumentation.java index 0c1820a9e..c9a7787b3 100644 --- a/webtau-rest/src/main/java/com/twosigma/webtau/http/HttpDocumentation.java +++ b/webtau-rest/src/main/java/com/twosigma/webtau/http/HttpDocumentation.java @@ -38,7 +38,7 @@ public void capture(String artifactName) { requestHeader); } - if (lastValidationResult.getRequestType() != null) { + if (lastValidationResult.getRequestType() != null && !lastValidationResult.isRequestBinary()) { String fileName = "request." + fileExtensionForType(lastValidationResult.getRequestType()); FileUtils.writeTextContent(path.resolve(fileName), prettyPrintContent(lastValidationResult.getRequestType(), diff --git a/webtau-rest/src/main/java/com/twosigma/webtau/http/validation/HttpValidationResult.java b/webtau-rest/src/main/java/com/twosigma/webtau/http/validation/HttpValidationResult.java index a6c667c0c..8ff7ac134 100644 --- a/webtau-rest/src/main/java/com/twosigma/webtau/http/validation/HttpValidationResult.java +++ b/webtau-rest/src/main/java/com/twosigma/webtau/http/validation/HttpValidationResult.java @@ -93,6 +93,10 @@ public String getRequestType() { return requestBody != null ? requestBody.type() : null; } + public boolean isRequestBinary() { + return requestBody != null && requestBody.isBinary(); + } + public String getResponseType() { return response.getContentType(); }