KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > latka > validators > MaxRequestTimeValidator


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
26
27 public class MaxRequestTimeValidator extends BaseValidator implements Validator {
28
29   // --------------------------------------------------------------- Attributes
30

31   protected int _millis = 30000; // shouldn't this be long?
32

33   protected static final MessageFormat JavaDoc MESSAGE = new MessageFormat JavaDoc("Expected maximum response time of \"{0,number,integer}\" millis, but took at least \"{1,number,integer}\" millis.");
34
35   // ------------------------------------------------------------- Constructors
36

37   public MaxRequestTimeValidator() {
38     this(null,30000);
39   }
40
41   public MaxRequestTimeValidator(String JavaDoc label) {
42     this(label,30000);
43   }
44
45   public MaxRequestTimeValidator(String JavaDoc label, int millis) {
46     super(label);
47     _millis = millis;
48   }
49
50   // ------------------------------------------------------------------ Methods
51

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 JavaDoc[] { new Integer JavaDoc(_millis), new Integer JavaDoc(request.getRequestTiming()) }).toString());
61     }
62   }
63
64 }
65
Popular Tags