debug the httpcapture
This commit is contained in:
parent
020d09177f
commit
90f076ed4e
|
@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||
@RequestMapping("/RecordScript")
|
||||
public class RecordScriptController extends BaseController {
|
||||
private int portForRecord;
|
||||
private ScriptCapturer scriptCapturer;
|
||||
private ScriptCapturer scriptCapturer = null;
|
||||
private ScriptService scriptService;
|
||||
private static final Object PORT_LOCK = new Object();
|
||||
private PortPoolService portPoolService = new PortPoolService();
|
||||
|
@ -72,7 +72,6 @@ public class RecordScriptController extends BaseController {
|
|||
}
|
||||
this.setPortForRecord(port.getPort());
|
||||
}
|
||||
|
||||
// String pathString = this.getClass().getResource("/").getPath();
|
||||
// scriptCapturer = new ScriptCapturer(portForRecord, "C:\\Script\\",
|
||||
// this.getPrincipal().getUserName());
|
||||
|
@ -96,15 +95,16 @@ public class RecordScriptController extends BaseController {
|
|||
* if (!checkScope(Constant.NORAML_AUTHENTICATION)) { return
|
||||
* returnResponseModel(false, "has no power for this!!!"); }
|
||||
*/
|
||||
if (this.getScriptCapturer().equals(null)) {
|
||||
if (this.getScriptCapturer() == null) {
|
||||
return returnResponseModel(false,
|
||||
"there is no RecordingServer to stop");
|
||||
}
|
||||
|
||||
this.getScriptCapturer().stopCurrentRecord();
|
||||
this.getScriptCapturer().shutHttpCaptureProxyServer();
|
||||
|
||||
|
||||
this.getPortPoolService().backThePortToPool(this.getPortForRecord());
|
||||
|
||||
return returnResponseModel(true, "RecordServer stop");
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,11 @@ import javax.swing.JTextArea;
|
|||
import org.bench4q.master.entity.httpcapture.HttpCapture;
|
||||
import org.bench4q.master.entity.httpcapture.Utils.UserException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ScriptCapturer {
|
||||
|
||||
//private HttpCapture httpCapture = null;
|
||||
|
||||
// private HttpCapture httpCapture = null;
|
||||
private int portForRecord;
|
||||
private String scriptPath;
|
||||
private boolean isRecording;
|
||||
|
@ -20,17 +21,18 @@ public class ScriptCapturer {
|
|||
private HttpCapture httpCapture;
|
||||
private String scriptContentString;
|
||||
private static final String HTTPCATUREGENERATOR_STRING = "org.bench4q.master.entity.httpcapture.generator.IsacCodeGenerator";
|
||||
|
||||
public ScriptCapturer(){}
|
||||
|
||||
public ScriptCapturer(int portForRecord, String scriptParentPath, String userName)
|
||||
{
|
||||
|
||||
public ScriptCapturer() {
|
||||
}
|
||||
|
||||
public ScriptCapturer(int portForRecord, String scriptParentPath,
|
||||
String userName) {
|
||||
this.setPortForRecord(portForRecord);
|
||||
this.setScriptPath(scriptParentPath + userName);
|
||||
//TODO get the machine's ipAdress
|
||||
// TODO get the machine's ipAdress
|
||||
this.setIpHttpCaptureServerAdress(Constant.TESTIPADRESS);
|
||||
}
|
||||
|
||||
|
||||
public boolean isRecording() {
|
||||
return isRecording;
|
||||
}
|
||||
|
@ -38,7 +40,7 @@ public class ScriptCapturer {
|
|||
public void setRecording(boolean isRecording) {
|
||||
this.isRecording = isRecording;
|
||||
}
|
||||
|
||||
|
||||
public String getScriptPath() {
|
||||
return scriptPath;
|
||||
}
|
||||
|
@ -46,7 +48,7 @@ public class ScriptCapturer {
|
|||
public void setScriptPath(String scriptPath) {
|
||||
this.scriptPath = scriptPath;
|
||||
}
|
||||
|
||||
|
||||
public boolean isProxyServerRunning() {
|
||||
return isProxyServerRunning;
|
||||
}
|
||||
|
@ -54,7 +56,7 @@ public class ScriptCapturer {
|
|||
public void setProxyServerRunning(boolean isProxyServerRunning) {
|
||||
this.isProxyServerRunning = isProxyServerRunning;
|
||||
}
|
||||
|
||||
|
||||
public String getIpHttpCaptureServerAdress() {
|
||||
return ipHttpCaptureServerAdress;
|
||||
}
|
||||
|
@ -62,7 +64,7 @@ public class ScriptCapturer {
|
|||
public void setIpHttpCaptureServerAdress(String ipHttpCaptureServerAdress) {
|
||||
this.ipHttpCaptureServerAdress = ipHttpCaptureServerAdress;
|
||||
}
|
||||
|
||||
|
||||
public int getPortForRecord() {
|
||||
return portForRecord;
|
||||
}
|
||||
|
@ -70,14 +72,16 @@ public class ScriptCapturer {
|
|||
public void setPortForRecord(int portForRecord) {
|
||||
this.portForRecord = portForRecord;
|
||||
}
|
||||
|
||||
|
||||
private void startHttpCaptureProxyServer() {
|
||||
try {
|
||||
httpCapture = new HttpCapture( this.getScriptPath(), this.getPortForRecord(),
|
||||
HTTPCATUREGENERATOR_STRING, new JTextArea());
|
||||
httpCapture = new HttpCapture(this.getScriptPath(),
|
||||
this.getPortForRecord(), HTTPCATUREGENERATOR_STRING,
|
||||
new JTextArea());
|
||||
httpCapture.startProxyServer();
|
||||
this.setProxyServerRunning(true);
|
||||
System.out.println("INFO: Proxy Server Started at Port: " + this.getPortForRecord());
|
||||
System.out.println("INFO: Proxy Server Started at Port: "
|
||||
+ this.getPortForRecord());
|
||||
} catch (IOException e1) {
|
||||
System.out.println("Error When build the proxy server!");
|
||||
e1.printStackTrace();
|
||||
|
@ -86,16 +90,17 @@ public class ScriptCapturer {
|
|||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void shutHttpCaptureProxyServer(){
|
||||
|
||||
public void shutHttpCaptureProxyServer() {
|
||||
try {
|
||||
if (!isProxyServerRunning()) {
|
||||
return;
|
||||
}
|
||||
if(this.isRecording()){
|
||||
if (this.isRecording()) {
|
||||
httpCapture.stopRecording();
|
||||
}
|
||||
httpCapture.shutProxyServer();
|
||||
this.setProxyServerRunning(false);
|
||||
} catch (IOException e1) {
|
||||
System.out.println("Error When shut the httpCapture proxy server!");
|
||||
e1.printStackTrace();
|
||||
|
@ -104,12 +109,10 @@ public class ScriptCapturer {
|
|||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void startCurrentRecord()
|
||||
{
|
||||
|
||||
public void startCurrentRecord() {
|
||||
try {
|
||||
if(!this.isProxyServerRunning())
|
||||
{
|
||||
if (!this.isProxyServerRunning()) {
|
||||
this.startHttpCaptureProxyServer();
|
||||
}
|
||||
httpCapture.startRecording();
|
||||
|
@ -122,23 +125,23 @@ public class ScriptCapturer {
|
|||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void stopCurrentRecord() {
|
||||
try {
|
||||
if(!this.isRecording())
|
||||
{
|
||||
if (!this.isRecording()) {
|
||||
return;
|
||||
}
|
||||
httpCapture.stopRecording();
|
||||
this.setRecording(false);
|
||||
this.setScriptContentString(this.httpCapture.getScriptContentString());
|
||||
this.setScriptContentString(this.httpCapture
|
||||
.getScriptContentString());
|
||||
} catch (IOException e1) {
|
||||
System.out.println("Error When stop recording!");
|
||||
e1.printStackTrace();
|
||||
} catch (UserException e1) {
|
||||
System.out.println("Error When stop recording!");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getScriptContentString() {
|
||||
|
|
|
@ -55,8 +55,9 @@ public class Config {
|
|||
String maxqDir = System.getProperty("maxq.dir");
|
||||
String pathSep = System.getProperty("file.separator");
|
||||
|
||||
String propertiesFileName = System.getProperty("properties.file",
|
||||
"maxq.properties");
|
||||
String propertiesFileName = System.getProperty("user.dir")
|
||||
+ "\\src\\main\\resources\\org\\bench4q\\master\\config\\httpCaptureConfig\\maxq.properties";
|
||||
|
||||
InputStream propertiesStream = Config.class.getClassLoader()
|
||||
.getResourceAsStream(propertiesFileName);
|
||||
props = new Properties();
|
||||
|
|
|
@ -5,8 +5,6 @@ import java.io.IOException;
|
|||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.httpclient.Header;
|
||||
import org.apache.commons.httpclient.HostConfiguration;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
|
@ -14,17 +12,14 @@ import org.apache.commons.httpclient.HttpMethod;
|
|||
import org.apache.commons.httpclient.NameValuePair;
|
||||
import org.apache.commons.httpclient.URIException;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.commons.httpclient.methods.MultipartPostMethod;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.multipart.StringPart;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.python.core.PyDictionary;
|
||||
import org.python.core.PyString;
|
||||
import org.python.core.PyTuple;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class HttpTestCase extends TestCase {
|
||||
public class HttpTestCase {
|
||||
private static final Log log = LogFactory.getLog(HttpTestCase.class);
|
||||
private Config config = Config.getConfig();
|
||||
protected HttpMethod method = null;
|
||||
|
@ -70,7 +65,6 @@ public class HttpTestCase extends TestCase {
|
|||
}
|
||||
|
||||
public HttpTestCase(String name) {
|
||||
super(name);
|
||||
Config.ProxySettings proxy = this.config.getProxySettings();
|
||||
if (proxy != null) {
|
||||
HostConfiguration hc = this.client.getHostConfiguration();
|
||||
|
@ -79,9 +73,6 @@ public class HttpTestCase extends TestCase {
|
|||
}
|
||||
|
||||
public void Run() throws Throwable {
|
||||
setUp();
|
||||
runTest();
|
||||
tearDown();
|
||||
}
|
||||
|
||||
public HttpMethod getMethod() {
|
||||
|
@ -91,7 +82,7 @@ public class HttpTestCase extends TestCase {
|
|||
private void cleanupMethod() {
|
||||
if (this.method != null) {
|
||||
this.method.releaseConnection();
|
||||
this.method.recycle();
|
||||
// this.method.recycle();
|
||||
this.method = null;
|
||||
}
|
||||
}
|
||||
|
@ -148,13 +139,14 @@ public class HttpTestCase extends TestCase {
|
|||
cleanupMethod();
|
||||
url = replaceURL(url);
|
||||
|
||||
MultipartPostMethod multipartPost = new MultipartPostMethod(url);
|
||||
multipartPost.addPart(new StringPart("data", data));
|
||||
PostMethod multipartPostMethod = new PostMethod(url);
|
||||
|
||||
multipartPostMethod.addParameter("data", data);
|
||||
if (args != null) {
|
||||
multipartPost.setQueryString(paramsToNV(args));
|
||||
multipartPostMethod.setQueryString(paramsToNV(args));
|
||||
}
|
||||
|
||||
this.method = multipartPost;
|
||||
this.method = multipartPostMethod;
|
||||
this.method.setFollowRedirects(this.followRedirects);
|
||||
this.client.executeMethod(this.method);
|
||||
}
|
||||
|
@ -179,6 +171,7 @@ public class HttpTestCase extends TestCase {
|
|||
}
|
||||
|
||||
public static String staticUrlDecode(String s) {
|
||||
String sUrl = "";
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(s.length());
|
||||
for (int count = 0; count < s.length(); ++count)
|
||||
if (s.charAt(count) == '%') {
|
||||
|
@ -197,17 +190,14 @@ public class HttpTestCase extends TestCase {
|
|||
} else if (s.charAt(count) == '+') {
|
||||
out.write(32);
|
||||
} else {
|
||||
sUrl += s.charAt(count);
|
||||
out.write(s.charAt(count));
|
||||
}
|
||||
|
||||
System.out.println(sUrl);
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
protected void responseOK() throws URIException {
|
||||
int status = getResponseCode();
|
||||
assertTrue("Invalid HTTP response: " + this.method + " for URI: "
|
||||
+ this.method.getURI(), (status == 200) || (status == 302)
|
||||
|| (status == 304));
|
||||
}
|
||||
|
||||
protected boolean responseContainsURI(String uri) throws URIException {
|
||||
|
|
|
@ -54,6 +54,7 @@ public class ProxyServer extends Thread {
|
|||
|
||||
public void run()
|
||||
{
|
||||
System.out.println(" in run");
|
||||
while (!Thread.interrupted())
|
||||
if (!this.srvSock.isClosed())
|
||||
try {
|
||||
|
|
|
@ -43,7 +43,8 @@ public class RequestHandler implements Runnable {
|
|||
try {
|
||||
this.header = new HttpRequestHeader(this.clientIn);
|
||||
} catch (IOException e) {
|
||||
log.info("truncated request from browser: " + e.getMessage());
|
||||
log.info("truncated request from browser: " + e.getMessage()
|
||||
+ this.header.url);
|
||||
throw new Utils.SilentException();
|
||||
}
|
||||
if (!this.header.url.startsWith("http"))
|
||||
|
@ -161,7 +162,7 @@ public class RequestHandler implements Runnable {
|
|||
this.clientOut.write(buf, 0, len);
|
||||
} catch (SocketException e) {
|
||||
log.info("browser stopped listening: "
|
||||
+ e.getMessage());
|
||||
+ e.getMessage() + this.buffer.toString());
|
||||
throw new Utils.SilentException();
|
||||
}
|
||||
this.buffer.write(buf, 0, len);
|
||||
|
|
|
@ -1,38 +1,25 @@
|
|||
package org.bench4q.master.entity.httpcapture;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.httpclient.HttpMethod;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class Validator {
|
||||
private static final Log log = LogFactory.getLog(Validator.class);
|
||||
private static String[] stdRspErrTags = new String[0];
|
||||
private static String[] stdRspErrPats = new String[0];
|
||||
|
||||
public static void validateResponse(HttpTestCase test, HttpMethod httpMethod, String url, Object[] params) throws IOException
|
||||
{
|
||||
log.debug("------Validator.validateResponse: method: " + httpMethod.getName() + " url: " + url + " params: " + params);
|
||||
public static void validateResponse(HttpTestCase test,
|
||||
HttpMethod httpMethod, String url, Object[] params)
|
||||
throws IOException {
|
||||
log.debug("------Validator.validateResponse: method: "
|
||||
+ httpMethod.getName() + " url: " + url + " params: " + params);
|
||||
|
||||
String response = httpMethod.getResponseBodyAsString();
|
||||
httpMethod.getResponseBodyAsString();
|
||||
}
|
||||
|
||||
for (int i = 0; i < stdRspErrTags.length; ++i) {
|
||||
HttpTestCase.assertEquals("Standard invariant tag found in response: " +
|
||||
stdRspErrTags[i], -1, response.indexOf(stdRspErrTags[i]));
|
||||
}
|
||||
|
||||
for (int i = 0; i < stdRspErrPats.length; ++i) {
|
||||
Pattern re = Pattern.compile(stdRspErrPats[i], 32);
|
||||
HttpTestCase.assertFalse("Standard invariant pattern found in response: " +
|
||||
stdRspErrPats[i], re.matcher(response).find());
|
||||
}
|
||||
}
|
||||
|
||||
public static void validateRequest(HttpTestCase test, HttpMethod httpMethod, String method, String url, Object[] params)
|
||||
{
|
||||
log.debug("------Validator.validateRequest: method: " + method +
|
||||
" url: " + url + " params: " + params);
|
||||
}
|
||||
public static void validateRequest(HttpTestCase test,
|
||||
HttpMethod httpMethod, String method, String url, Object[] params) {
|
||||
log.debug("------Validator.validateRequest: method: " + method
|
||||
+ " url: " + url + " params: " + params);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -102,7 +102,7 @@ public class PortPoolService {
|
|||
.createCriteria(Port.class)
|
||||
.add(Restrictions.eq("inUse", false)).list();
|
||||
|
||||
if (portList == null) {
|
||||
if (portList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
# This file specifies configuration for maxq.
|
||||
|
||||
# Names of generator classes to make available in the GUI. We do not
|
||||
# include the Java generator here by default because MaxQ cannot run
|
||||
# these scripts, only generate them. We do not include SampleGenerator
|
||||
# because it is only of interest to people writing new generators and
|
||||
# might confuse regular MaxQ users.
|
||||
#
|
||||
# Class names are separated by colons.
|
||||
generator.classnames=com.bitmechanic.maxq.generator.IsacCodeGenerator
|
||||
|
||||
# What port MaxQ should listen on for requests from the browser. Default is
|
||||
# port 8090.
|
||||
local.proxy.port=8090
|
||||
|
||||
# HTTP proxy settings for MaxQ's own requests; MaxQ can operate behind a
|
||||
# firewall.
|
||||
#remote.proxy.host=myproxy
|
||||
#remote.proxy.port=3128
|
||||
|
||||
|
||||
##########################################
|
||||
# properties used in TemplateCodeGenerator
|
||||
##########################################
|
||||
template.theme=HttpUnit
|
||||
|
||||
##########################################
|
||||
# properties used in IsacCodeGenerator
|
||||
##########################################
|
||||
#for constant think times
|
||||
generator.isac.timer=ConstantTimer
|
||||
|
||||
#not to capture think times
|
||||
#generator.isac.timer=null
|
||||
|
||||
#for randomized think times
|
||||
#generator.isac.timer=Random
|
||||
|
||||
#extra properties for a uniform distribution
|
||||
#generator.isac.timer.random.dist=uniform
|
||||
#generator.isac.timer.random.delta=1000
|
||||
|
||||
#extra properties for a gaussian distribution
|
||||
#generator.isac.timer.random.dist=gaussian
|
||||
#generator.isac.timer.random.delta=1000
|
||||
#generator.isac.timer.random.deviation=10
|
||||
|
||||
#extra properties for a Poisson law distribution
|
||||
#generator.isac.timer.random.dist=poisson
|
||||
#generator.isac.timer.random.unit=1
|
||||
|
||||
#extra properties for a negative exponential law distribution
|
||||
#generator.isac.timer.random.dist=negexpo
|
||||
#generator.isac.timer.random.delta=10
|
Loading…
Reference in New Issue