use of io.restassured.internal.support.Prettifier in project rest-assured by rest-assured.
the class RequestPrinter method addMultiParts.
private static void addMultiParts(FilterableRequestSpecification requestSpec, StringBuilder builder) {
builder.append("Multiparts:");
final List<MultiPartSpecification> multiParts = requestSpec.getMultiPartParams();
if (multiParts.isEmpty()) {
appendTwoTabs(builder).append(NONE).append(NEW_LINE);
} else {
for (int i = 0; i < multiParts.size(); i++) {
MultiPartSpecification multiPart = multiParts.get(i);
if (i == 0) {
appendTwoTabs(builder);
} else {
appendFourTabs(builder.append(NEW_LINE));
}
builder.append("------------");
appendFourTabs(appendFourTabs(builder.append(NEW_LINE)).append("Content-Disposition: " + requestSpec.getContentType().replace("multipart/", "") + "; name = " + multiPart.getControlName() + (multiPart.hasFileName() ? "; filename = " + multiPart.getFileName() : "")).append(NEW_LINE)).append("Content-Type: " + multiPart.getMimeType());
if (multiPart.getContent() instanceof InputStream) {
appendFourTabs(builder.append(NEW_LINE)).append("<inputstream>");
} else {
Parser parser = Parser.fromContentType(multiPart.getMimeType());
String prettified = new Prettifier().prettify(multiPart.getContent().toString(), parser);
String prettifiedIndented = StringUtils.replace(prettified, NEW_LINE, NEW_LINE + TAB + TAB + TAB + TAB);
appendFourTabs(builder.append(NEW_LINE)).append(prettifiedIndented);
}
}
builder.append(NEW_LINE);
}
}
use of io.restassured.internal.support.Prettifier in project rest-assured by rest-assured.
the class ResponsePrinter method print.
/**
* Prints the response to the print stream
*
* @return A string of representing the response
*/
public static String print(ResponseOptions responseOptions, ResponseBody responseBody, PrintStream stream, LogDetail logDetail, boolean shouldPrettyPrint) {
final StringBuilder builder = new StringBuilder();
if (logDetail == ALL || logDetail == STATUS) {
builder.append(responseOptions.statusLine());
}
if (logDetail == ALL || logDetail == HEADERS) {
final Headers headers = responseOptions.headers();
if (headers.exist()) {
appendNewLineIfAll(logDetail, builder).append(toString(headers));
}
} else if (logDetail == COOKIES) {
final Cookies cookies = responseOptions.detailedCookies();
if (cookies.exist()) {
appendNewLineIfAll(logDetail, builder).append(cookies.toString());
}
}
if (logDetail == ALL || logDetail == BODY) {
String responseBodyToAppend;
if (shouldPrettyPrint) {
responseBodyToAppend = new Prettifier().getPrettifiedBodyIfPossible(responseOptions, responseBody);
} else {
responseBodyToAppend = responseBody.asString();
}
if (logDetail == ALL && !isBlank(responseBodyToAppend)) {
builder.append("\n\n");
}
builder.append(responseBodyToAppend);
}
String response = builder.toString();
stream.println(response);
return response;
}
Aggregations