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: */
18:
19: package org.apache.jmeter.protocol.http.sampler;
20:
21: import org.apache.jmeter.util.JMeterUtils;
22:
23: /**
24: * Factory to return the appropriate HTTPSampler for use with classes that need
25: * an HTTPSampler
26: *
27: */
28: public class HTTPSamplerFactory {
29:
30: /** Use the the default Java HTTP implementation */
31: public static final String HTTP_SAMPLER_JAVA = "HTTPSampler"; //$NON-NLS-1$
32:
33: /** Use Apache HTTPClient HTTP implementation */
34: public static final String HTTP_SAMPLER_APACHE = "HTTPSampler2"; //$NON-NLS-1$
35:
36: public static final String DEFAULT_CLASSNAME = JMeterUtils
37: .getPropDefault("jmeter.httpsampler", HTTP_SAMPLER_JAVA); //$NON-NLS-1$
38:
39: private HTTPSamplerFactory() {
40: // Not intended to be instantiated
41: }
42:
43: /**
44: * Create a new instance of the default sampler
45: *
46: * @return instance of default sampler
47: */
48: public static HTTPSamplerBase newInstance() {
49: return newInstance(DEFAULT_CLASSNAME);
50: }
51:
52: /**
53: * Create a new instance of the required sampler type
54: *
55: * @param alias HTTP_SAMPLER or HTTP_SAMPLER_APACHE
56: * @return the appropriate sampler
57: * @throws UnsupportedOperationException if alias is not recognised
58: */
59: public static HTTPSamplerBase newInstance(String alias) {
60: if (alias.length() == 0)
61: alias = DEFAULT_CLASSNAME;
62: if (alias.equals(HTTP_SAMPLER_JAVA)) {
63: return new HTTPSampler();
64: }
65: if (alias.equals(HTTP_SAMPLER_APACHE)) {
66: return new HTTPSampler2();
67: }
68: throw new UnsupportedOperationException("Cannot create class: "
69: + alias);
70: }
71: }
|