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; }
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) { Response response = ctx.next(requestSpec, responseSpec); final int statusCode = response.statusCode(); if (matcher.matches(statusCode)) { ResponsePrinter.print(response, response, stream, logDetail, shouldPrettyPrint); final byte[] responseBody; if (logDetail == BODY || logDetail == ALL) { responseBody = response.asByteArray(); } else { responseBody = null; } response = cloneResponseIfNeeded(response, responseBody); } return response; }
.header(IF_MATCH, getResponse.getHeader(ETAG)) .contentType(getResponse.contentType()) .body(getResponse.asByteArray()) .when() .put(resourceUri); .body(getResponse.asByteArray()) .when() .put(resourceUri);
@Test( groups = {SHOULD}, description = "LDP clients SHOULD use the HTTP If-Match header and HTTP ETags " + "to ensure it isn’t modifying a resource that has changed since the " + "client last retrieved its representation. LDP servers SHOULD require " + "the HTTP If-Match header and HTTP ETags to detect collisions.") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-put-precond", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED, comment = "Covers only part of the specification requirement. " + "testConditionFailedStatusCode, testPreconditionRequiredStatusCode " + "and testPutBadETag covers the rest.") public void testPutRequiresIfMatch() throws URISyntaxException { skipIfMethodNotAllowed(HttpMethod.PUT); String resourceUri = getResourceUri(); Response response = buildBaseRequestSpecification() .expect() .statusCode(isSuccessful()) .header(ETAG, isValidEntityTag()) .when() .get(resourceUri); buildBaseRequestSpecification() .contentType(response.getContentType()) .body(response.asByteArray()) .expect() .statusCode(not(isSuccessful())) .when() .put(resourceUri); }
.contentType(response.getContentType()) .header(IF_MATCH, "\"This is not the ETag you're looking for\"") // bad ETag value .body(response.asByteArray()) .expect() .statusCode(HttpStatus.SC_PRECONDITION_FAILED)
.contentType(contentType) .header(IF_MATCH, "\"These aren't the ETags you're looking for.\"") .body(response.asByteArray()) .expect() .statusCode(HttpStatus.SC_PRECONDITION_FAILED)