use of io.restassured.internal.RestAssuredResponseImpl in project rest-assured by rest-assured.
the class ResponseConverter method toStandardResponse.
static Response toStandardResponse(MockMvcResponse response) {
if (!(response instanceof MockMvcRestAssuredResponseImpl)) {
throw new IllegalArgumentException(MockMvcResponse.class.getName() + " must be an instance of " + MockMvcRestAssuredResponseImpl.class.getName());
}
MockMvcRestAssuredResponseImpl mvc = (MockMvcRestAssuredResponseImpl) response;
RestAssuredResponseImpl std = new RestAssuredResponseImpl();
std.setConnectionManager(mvc.getConnectionManager());
std.setContent(mvc.getContent());
std.setContentType(mvc.getContentType());
std.setCookies(mvc.detailedCookies());
std.setDecoderConfig(mvc.getDecoderConfig());
std.setDefaultContentType(mvc.getDefaultContentType());
std.setHasExpectations(mvc.getHasExpectations());
std.setResponseHeaders(mvc.getResponseHeaders());
std.setSessionIdName(mvc.getSessionIdName());
std.setStatusCode(mvc.getStatusCode());
std.setStatusLine(mvc.getStatusLine());
std.setRpr(mvc.getRpr());
std.setFilterContextProperties(mvc.getFilterContextProperties());
std.setLogRepository(mvc.getLogRepository());
return std;
}
use of io.restassured.internal.RestAssuredResponseImpl in project rest-assured by rest-assured.
the class StatusCodeBasedLoggingFilter method cloneResponseIfNeeded.
/*
* If body expectations are defined we need to return a new Response otherwise the stream
* has been closed due to the logging.
*/
private Response cloneResponseIfNeeded(Response response, byte[] responseAsString) {
if (responseAsString != null && response instanceof RestAssuredResponseImpl && !((RestAssuredResponseImpl) response).getHasExpectations()) {
final Response build = new ResponseBuilder().clone(response).setBody(responseAsString).build();
((RestAssuredResponseImpl) build).setHasExpectations(true);
return build;
}
return response;
}
use of io.restassured.internal.RestAssuredResponseImpl in project rest-assured by rest-assured.
the class ResponseBuilder method clone.
/**
* Clone an already existing response.
*
* @return Builder.
*/
public ResponseBuilder clone(Response response) {
if (isRestAssuredResponse(response)) {
final RestAssuredResponseImpl raResponse = raResponse(response);
restAssuredResponse.setContent(raResponse.getContent());
restAssuredResponse.setHasExpectations(raResponse.getHasExpectations());
restAssuredResponse.setDefaultContentType(raResponse.getDefaultContentType());
restAssuredResponse.setDecoderConfig(raResponse.getDecoderConfig());
restAssuredResponse.setSessionIdName(raResponse.getSessionIdName());
restAssuredResponse.setConnectionManager(raResponse.getConnectionManager());
restAssuredResponse.setConfig(raResponse.getConfig());
restAssuredResponse.setRpr(raResponse.getRpr());
restAssuredResponse.setLogRepository(raResponse.getLogRepository());
restAssuredResponse.setFilterContextProperties(raResponse.getFilterContextProperties());
} else {
restAssuredResponse.setContent(response.asInputStream());
}
restAssuredResponse.setContentType(response.getContentType());
restAssuredResponse.setCookies(response.getDetailedCookies());
restAssuredResponse.setResponseHeaders(response.getHeaders());
restAssuredResponse.setStatusCode(response.getStatusCode());
restAssuredResponse.setStatusLine(response.getStatusLine());
return this;
}
use of io.restassured.internal.RestAssuredResponseImpl in project rest-assured by rest-assured.
the class TimingFilter method filter.
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
long start = System.currentTimeMillis();
Response response = ctx.next(requestSpec, responseSpec);
if (shouldConsumeStream && response instanceof RestAssuredResponseImpl && ((RestAssuredResponseImpl) response).isInputStream()) {
// Consume the body of the request (important if measure time also should include downloading of body)
response.asByteArray();
}
long end = System.currentTimeMillis();
long responseTime = end - start;
ctx.setValue(RESPONSE_TIME_MILLISECONDS, responseTime);
return response;
}
Aggregations