Search in sources :

Example 1 with RestAssuredResponseImpl

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;
}
Also used : MockMvcResponse(io.restassured.module.mockmvc.response.MockMvcResponse) RestAssuredResponseImpl(io.restassured.internal.RestAssuredResponseImpl)

Example 2 with RestAssuredResponseImpl

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;
}
Also used : Response(io.restassured.response.Response) RestAssuredResponseImpl(io.restassured.internal.RestAssuredResponseImpl) ResponseBuilder(io.restassured.builder.ResponseBuilder)

Example 3 with RestAssuredResponseImpl

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;
}
Also used : RestAssuredResponseImpl(io.restassured.internal.RestAssuredResponseImpl)

Example 4 with RestAssuredResponseImpl

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;
}
Also used : Response(io.restassured.response.Response) RestAssuredResponseImpl(io.restassured.internal.RestAssuredResponseImpl)

Aggregations

RestAssuredResponseImpl (io.restassured.internal.RestAssuredResponseImpl)4 Response (io.restassured.response.Response)2 ResponseBuilder (io.restassured.builder.ResponseBuilder)1 MockMvcResponse (io.restassured.module.mockmvc.response.MockMvcResponse)1