1 16 17 package org.apache.commons.latka.validators; 18 19 import org.apache.commons.latka.Validator; 20 import org.apache.commons.latka.ValidationException; 21 22 import org.apache.commons.latka.http.Request; 23 import org.apache.commons.latka.http.Response; 24 25 import java.text.MessageFormat ; 26 27 public class MaxRequestTimeValidator extends BaseValidator implements Validator { 28 29 31 protected int _millis = 30000; 33 protected static final MessageFormat MESSAGE = new MessageFormat ("Expected maximum response time of \"{0,number,integer}\" millis, but took at least \"{1,number,integer}\" millis."); 34 35 37 public MaxRequestTimeValidator() { 38 this(null,30000); 39 } 40 41 public MaxRequestTimeValidator(String label) { 42 this(label,30000); 43 } 44 45 public MaxRequestTimeValidator(String label, int millis) { 46 super(label); 47 _millis = millis; 48 } 49 50 52 public void setMaxMillis(int millis) { 53 _millis = millis; 54 } 55 56 public void validate(Response response) throws ValidationException { 57 Request request = response.getRequest(); 58 59 if (request.getRequestTiming() > _millis) { 60 fail(MESSAGE.format(new Object [] { new Integer (_millis), new Integer (request.getRequestTiming()) }).toString()); 61 } 62 } 63 64 } 65 | Popular Tags |