📄 proxycontrol.java
字号:
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.jmeter.protocol.http.proxy;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.apache.jmeter.assertions.ResponseAssertion;
import org.apache.jmeter.assertions.gui.AssertionGui;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.config.ConfigElement;
import org.apache.jmeter.config.ConfigTestElement;
import org.apache.jmeter.control.GenericController;
import org.apache.jmeter.control.gui.LogicControllerGui;
import org.apache.jmeter.engine.util.ValueReplacer;
import org.apache.jmeter.exceptions.IllegalUserActionException;
import org.apache.jmeter.functions.InvalidVariableException;
import org.apache.jmeter.gui.GuiPackage;
import org.apache.jmeter.gui.tree.JMeterTreeModel;
import org.apache.jmeter.gui.tree.JMeterTreeNode;
import org.apache.jmeter.protocol.http.control.HeaderManager;
import org.apache.jmeter.protocol.http.control.RecordingController;
import org.apache.jmeter.protocol.http.gui.HeaderPanel;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
import org.apache.jmeter.samplers.SampleEvent;
import org.apache.jmeter.samplers.SampleListener;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestListener;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.testelement.WorkBench;
import org.apache.jmeter.testelement.property.BooleanProperty;
import org.apache.jmeter.testelement.property.CollectionProperty;
import org.apache.jmeter.testelement.property.IntegerProperty;
import org.apache.jmeter.testelement.property.JMeterProperty;
import org.apache.jmeter.testelement.property.PropertyIterator;
import org.apache.jmeter.testelement.property.StringProperty;
import org.apache.jmeter.threads.ThreadGroup;
import org.apache.jmeter.timers.Timer;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
import org.apache.oro.text.MalformedCachePatternException;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.Perl5Compiler;
//For unit tests, @see TestProxyControl
/**
* Class handles storing of generated samples, etc
*/
public class ProxyControl extends GenericController {
private static final Logger log = LoggingManager.getLoggerForClass();
private static final String ASSERTION_GUI = AssertionGui.class.getName();
private static final String LOGIC_CONTROLLER_GUI = LogicControllerGui.class.getName();
private static final String HEADER_PANEL = HeaderPanel.class.getName();
private transient Daemon server;
public static final int DEFAULT_PORT = 8080;
// and as a string
public static final String DEFAULT_PORT_S =
Integer.toString(DEFAULT_PORT);// Used by GUI
//+ JMX file attributes
private static final String PORT = "ProxyControlGui.port"; // $NON-NLS-1$
private static final String EXCLUDE_LIST = "ProxyControlGui.exclude_list"; // $NON-NLS-1$
private static final String INCLUDE_LIST = "ProxyControlGui.include_list"; // $NON-NLS-1$
private static final String CAPTURE_HTTP_HEADERS = "ProxyControlGui.capture_http_headers"; // $NON-NLS-1$
private static final String ADD_ASSERTIONS = "ProxyControlGui.add_assertion"; // $NON-NLS-1$
private static final String GROUPING_MODE = "ProxyControlGui.grouping_mode"; // $NON-NLS-1$
private static final String SAMPLER_TYPE_NAME = "ProxyControlGui.sampler_type_name"; // $NON-NLS-1$
private static final String SAMPLER_REDIRECT_AUTOMATICALLY = "ProxyControlGui.sampler_redirect_automatically"; // $NON-NLS-1$
private static final String SAMPLER_FOLLOW_REDIRECTS = "ProxyControlGui.sampler_follow_redirects"; // $NON-NLS-1$
private static final String USE_KEEPALIVE = "ProxyControlGui.use_keepalive"; // $NON-NLS-1$
private static final String SAMPLER_DOWNLOAD_IMAGES = "ProxyControlGui.sampler_download_images"; // $NON-NLS-1$
private static final String REGEX_MATCH = "ProxyControlGui.regex_match"; // $NON-NLS-1$
private static final String HTTPS_SPOOF = "ProxyControlGui.https_spoof"; // $NON-NLS-1$
private static final String HTTPS_SPOOF_MATCH = "ProxyControlGui.https_spoof_match"; // $NON-NLS-1$
private static final String CONTENT_TYPE_EXCLUDE = "ProxyControlGui.content_type_exclude"; // $NON-NLS-1$
private static final String CONTENT_TYPE_INCLUDE = "ProxyControlGui.content_type_include"; // $NON-NLS-1$
//- JMX file attributes
public static final int GROUPING_NO_GROUPS = 0;
public static final int GROUPING_ADD_SEPARATORS = 1;
public static final int GROUPING_IN_CONTROLLERS = 2;
public static final int GROUPING_STORE_FIRST_ONLY = 3;
// Must agree with the order of entries in the drop-down
// created in ProxyControlGui.createHTTPSamplerPanel()
public static final int SAMPLER_TYPE_HTTP_SAMPLER = 0;
public static final int SAMPLER_TYPE_HTTP_SAMPLER2 = 1;
private long lastTime = 0;// When was the last sample seen?
private static final long sampleGap =
JMeterUtils.getPropDefault("proxy.pause", 1000); // $NON-NLS-1$
// Detect if user has pressed a new link
private boolean addAssertions;
private int groupingMode;
private boolean samplerRedirectAutomatically;
private boolean samplerFollowRedirects;
private boolean useKeepAlive;
private boolean samplerDownloadImages;
private boolean regexMatch = false;// Should we match using regexes?
/**
* Tree node where the samples should be stored.
* <p>
* This property is not persistent.
*/
private JMeterTreeNode target;
public ProxyControl() {
setPort(DEFAULT_PORT);
setExcludeList(new HashSet());
setIncludeList(new HashSet());
setCaptureHttpHeaders(true); // maintain original behaviour
}
public void setPort(int port) {
this.setProperty(new IntegerProperty(PORT, port));
}
public void setPort(String port) {
setProperty(PORT, port);
}
public void setCaptureHttpHeaders(boolean capture) {
setProperty(new BooleanProperty(CAPTURE_HTTP_HEADERS, capture));
}
public void setGroupingMode(int grouping) {
this.groupingMode = grouping;
setProperty(new IntegerProperty(GROUPING_MODE, grouping));
}
public void setAssertions(boolean b) {
addAssertions = b;
setProperty(new BooleanProperty(ADD_ASSERTIONS, b));
}
public void setSamplerTypeName(int samplerTypeName) {
setProperty(new IntegerProperty(SAMPLER_TYPE_NAME, samplerTypeName));
}
public void setSamplerRedirectAutomatically(boolean b) {
samplerRedirectAutomatically = b;
setProperty(new BooleanProperty(SAMPLER_REDIRECT_AUTOMATICALLY, b));
}
public void setSamplerFollowRedirects(boolean b) {
samplerFollowRedirects = b;
setProperty(new BooleanProperty(SAMPLER_FOLLOW_REDIRECTS, b));
}
/**
* @param b
*/
public void setUseKeepAlive(boolean b) {
useKeepAlive = b;
setProperty(new BooleanProperty(USE_KEEPALIVE, b));
}
public void setSamplerDownloadImages(boolean b) {
samplerDownloadImages = b;
setProperty(new BooleanProperty(SAMPLER_DOWNLOAD_IMAGES, b));
}
public void setIncludeList(Collection list) {
setProperty(new CollectionProperty(INCLUDE_LIST, new HashSet(list)));
}
public void setExcludeList(Collection list) {
setProperty(new CollectionProperty(EXCLUDE_LIST, new HashSet(list)));
}
/**
* @param b
*/
public void setRegexMatch(boolean b) {
regexMatch = b;
setProperty(new BooleanProperty(REGEX_MATCH, b));
}
public void setHttpsSpoof(boolean b) {
setProperty(new BooleanProperty(HTTPS_SPOOF, b));
}
public void setHttpsSpoofMatch(String s) {
setProperty(new StringProperty(HTTPS_SPOOF_MATCH, s));
}
public void setContentTypeExclude(String contentTypeExclude) {
setProperty(new StringProperty(CONTENT_TYPE_EXCLUDE, contentTypeExclude));
}
public void setContentTypeInclude(String contentTypeInclude) {
setProperty(new StringProperty(CONTENT_TYPE_INCLUDE, contentTypeInclude));
}
public String getClassLabel() {
return JMeterUtils.getResString("proxy_title"); // $NON-NLS-1$
}
public boolean getAssertions() {
return getPropertyAsBoolean(ADD_ASSERTIONS);
}
public int getGroupingMode() {
return getPropertyAsInt(GROUPING_MODE);
}
public int getPort() {
return getPropertyAsInt(PORT);
}
public String getPortString() {
return getPropertyAsString(PORT);
}
public int getDefaultPort() {
return DEFAULT_PORT;
}
public boolean getCaptureHttpHeaders() {
return getPropertyAsBoolean(CAPTURE_HTTP_HEADERS);
}
public int getSamplerTypeName() {
return getPropertyAsInt(SAMPLER_TYPE_NAME);
}
public boolean getSamplerRedirectAutomatically() {
return getPropertyAsBoolean(SAMPLER_REDIRECT_AUTOMATICALLY, false);
}
public boolean getSamplerFollowRedirects() {
return getPropertyAsBoolean(SAMPLER_FOLLOW_REDIRECTS, true);
}
public boolean getUseKeepalive() {
return getPropertyAsBoolean(USE_KEEPALIVE, true);
}
public boolean getSamplerDownloadImages() {
return getPropertyAsBoolean(SAMPLER_DOWNLOAD_IMAGES, false);
}
public boolean getRegexMatch() {
return getPropertyAsBoolean(REGEX_MATCH, false);
}
public boolean getHttpsSpoof() {
return getPropertyAsBoolean(HTTPS_SPOOF, false);
}
public String getHttpsSpoofMatch() {
return getPropertyAsString(HTTPS_SPOOF_MATCH, "");
}
public String getContentTypeExclude() {
return getPropertyAsString(CONTENT_TYPE_EXCLUDE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -