01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.threadtest.tester;
18:
19: import java.util.List;
20:
21: import org.apache.commons.httpclient.HttpClient;
22: import org.apache.wicket.util.string.Strings;
23:
24: public abstract class AbstractGetCommand extends AbstractCommand {
25:
26: /**
27: * Construct.
28: *
29: * @param urls
30: * URLs to visit
31: * @param iterations
32: * number of executions of the urls
33: */
34: public AbstractGetCommand(List<String> urls, int iterations) {
35: super (urls, iterations);
36: }
37:
38: /**
39: * @see org.apache.wicket.threadtest.tester.Command#execute(CommandRunner)
40: */
41: public void execute(CommandRunner runner) throws Exception {
42:
43: int iterations = getIterations();
44: for (int i = 0; i < iterations; i++) {
45: List<String> urls = getUrls();
46: for (String url : urls) {
47:
48: String modUrl = Strings.replaceAll(url, "${iteration}",
49: String.valueOf(i)).toString();
50: doGet(runner.getClient(), modUrl);
51: }
52: }
53: }
54:
55: /**
56: * Execute a GET request using the provided url.
57: *
58: * @param url
59: * The url to GET
60: * @param client
61: * the http client
62: * @throws Exception
63: */
64: protected abstract void doGet(HttpClient client, String url)
65: throws Exception;
66: }
|