adapt the httpcapture to our new Scenario
This commit is contained in:
parent
0de37bdd11
commit
11b7992691
|
@ -20,7 +20,9 @@ public class ScriptCapturer {
|
|||
private String ipHttpCaptureServerAdress;
|
||||
private HttpCapture httpCapture;
|
||||
private String scriptContentString;
|
||||
private static final String HTTPCATUREGENERATOR_STRING = "org.bench4q.master.entity.httpcapture.generator.IsacCodeGenerator";
|
||||
// private static final String HTTPCATUREGENERATOR_STRING =
|
||||
// "org.bench4q.master.entity.httpcapture.generator.IsacCodeGenerator";
|
||||
private static final String HTTPCATUREGENERATOR_STRING = "org.bench4q.master.entity.httpcapture.generator.Bench4qCodeGenerator";
|
||||
|
||||
public ScriptCapturer() {
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package org.bench4q.master.entity.httpcapture;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.bench4q.master.communication.agent.RunScenarioModel;
|
||||
import org.bench4q.master.communication.agent.UsePluginModel;
|
||||
import org.bench4q.master.communication.agent.UserBehaviorModel;
|
||||
|
||||
public class Bench4qTestScriptAdapter implements IScriptAdapter {
|
||||
private RunScenarioModel runScenarioModel;
|
||||
|
||||
public Bench4qTestScriptAdapter(RunScenarioModel runScenarioModel) {
|
||||
this.runScenarioModel = runScenarioModel;
|
||||
}
|
||||
|
||||
public void appendUsePluginsToScenario(List<UsePluginModel> usePluginModels) {
|
||||
this.runScenarioModel.setUsePlugins(usePluginModels);
|
||||
}
|
||||
|
||||
public void insertUserBehaviorsToScenario(UserBehaviorModel userModel) {
|
||||
this.runScenarioModel.getUserBehaviors().add(userModel);
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
try {
|
||||
Marshaller marshaller = JAXBContext.newInstance(
|
||||
this.runScenarioModel.getClass()).createMarshaller();
|
||||
marshaller.marshal(this.runScenarioModel, stringWriter);
|
||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
try {
|
||||
Unmarshaller unmarshaller = JAXBContext.newInstance(
|
||||
this.runScenarioModel.getClass()).createUnmarshaller();
|
||||
this.runScenarioModel = (RunScenarioModel) unmarshaller
|
||||
.unmarshal(new ByteArrayInputStream(text.getBytes()));
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -4,20 +4,20 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
import org.bench4q.master.communication.agent.RunScenarioModel;
|
||||
|
||||
public class HttpCapture {
|
||||
private int localport;
|
||||
private Config config;
|
||||
private Test currentTest;
|
||||
private ProxyServer proxy;
|
||||
private File resultFile;
|
||||
private JTextArea textArea;
|
||||
private String scriptContentString;
|
||||
|
||||
public HttpCapture(String filepath, int localport, String generator,
|
||||
JTextArea textArea) {
|
||||
this.localport = localport;
|
||||
this.resultFile = new File(filepath + "\\Script.xml");
|
||||
this.textArea = textArea;
|
||||
this.config = Config.getConfig();
|
||||
try {
|
||||
this.config.completeInit();
|
||||
|
@ -25,8 +25,8 @@ public class HttpCapture {
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.currentTest = new Test(this.proxy, new JTextAreaTestScriptAdapter(
|
||||
this.textArea), generator);
|
||||
this.currentTest = new Test(this.proxy, new Bench4qTestScriptAdapter(
|
||||
new RunScenarioModel()), generator);
|
||||
}
|
||||
|
||||
public void startProxyServer() throws IOException, Utils.UserException {
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
package org.bench4q.master.entity.httpcapture;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.master.communication.agent.UsePluginModel;
|
||||
import org.bench4q.master.communication.agent.UserBehaviorModel;
|
||||
|
||||
public interface IScriptAdapter {
|
||||
|
||||
public abstract void append(String paramString);
|
||||
public abstract void appendUsePluginsToScenario(
|
||||
List<UsePluginModel> usePluginModels);
|
||||
|
||||
public abstract void insert(String paramString, int paramInt);
|
||||
public abstract void insertUserBehaviorsToScenario(
|
||||
UserBehaviorModel userModel);
|
||||
|
||||
public abstract String getText();
|
||||
public abstract String getText();
|
||||
|
||||
public abstract void setText(String paramString);
|
||||
public abstract void setText(String paramString);
|
||||
|
||||
public abstract void replace(String paramString, int paramInt1, int paramInt2)
|
||||
throws IllegalArgumentException;
|
||||
}
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
package org.bench4q.master.entity.httpcapture;
|
||||
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
public class JTextAreaTestScriptAdapter
|
||||
implements IScriptAdapter
|
||||
{
|
||||
private JTextArea jTextArea;
|
||||
|
||||
public JTextAreaTestScriptAdapter(JTextArea jTextArea)
|
||||
{
|
||||
this.jTextArea = jTextArea;
|
||||
jTextArea.setText("");
|
||||
}
|
||||
|
||||
public void append(String text)
|
||||
{
|
||||
this.jTextArea.append(text);
|
||||
}
|
||||
|
||||
public void insert(String text, int position)
|
||||
{
|
||||
this.jTextArea.insert(text, position);
|
||||
}
|
||||
|
||||
public String getText()
|
||||
{
|
||||
return this.jTextArea.getText();
|
||||
}
|
||||
|
||||
public void setText(String text)
|
||||
{
|
||||
this.jTextArea.setText(text);
|
||||
}
|
||||
|
||||
public void replace(String string, int start, int end) throws IllegalArgumentException
|
||||
{
|
||||
this.jTextArea.replaceRange(string, start, end);
|
||||
}
|
||||
}
|
|
@ -9,143 +9,131 @@ import java.io.PrintWriter;
|
|||
import org.bench4q.master.entity.httpcapture.generator.GeneratorFactory;
|
||||
import org.bench4q.master.entity.httpcapture.generator.IScriptGenerator;
|
||||
|
||||
|
||||
public class Test {
|
||||
private IScriptGenerator generator;
|
||||
private IScriptAdapter scriptAdapter;
|
||||
private boolean isRecording;
|
||||
private File testFile;
|
||||
private String testName;
|
||||
ProxyServer proxyServer;
|
||||
private IScriptGenerator generator;
|
||||
private IScriptAdapter scriptAdapter;
|
||||
private boolean isRecording;
|
||||
private File testFile;
|
||||
private String testName;
|
||||
ProxyServer proxyServer;
|
||||
|
||||
public Test(ProxyServer proxy, IScriptAdapter adapter, String generatorClass)
|
||||
{
|
||||
this.proxyServer = proxy;
|
||||
this.scriptAdapter = adapter;
|
||||
adapter.setText("");
|
||||
this.generator = GeneratorFactory.newGenerator(generatorClass, adapter);
|
||||
this.generator.doNew();
|
||||
}
|
||||
public Test(ProxyServer proxy, IScriptAdapter adapter, String generatorClass) {
|
||||
this.proxyServer = proxy;
|
||||
this.scriptAdapter = adapter;
|
||||
adapter.setText("");
|
||||
this.generator = GeneratorFactory.newGenerator(generatorClass, adapter);
|
||||
this.generator.doNew();
|
||||
}
|
||||
|
||||
public Test(ProxyServer proxy, IScriptAdapter adapter, File file)
|
||||
throws IOException, Utils.UserException
|
||||
{
|
||||
this.proxyServer = proxy;
|
||||
this.scriptAdapter = adapter;
|
||||
this.testFile = file;
|
||||
public Test(ProxyServer proxy, IScriptAdapter adapter, File file)
|
||||
throws IOException, Utils.UserException {
|
||||
this.proxyServer = proxy;
|
||||
this.scriptAdapter = adapter;
|
||||
this.testFile = file;
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
BufferedReader r = new BufferedReader(new FileReader(this.testFile));
|
||||
String line = r.readLine();
|
||||
while (line != null) {
|
||||
buffer.append(line);
|
||||
buffer.append(IScriptGenerator.EOL);
|
||||
line = r.readLine();
|
||||
}
|
||||
r.close();
|
||||
String script = buffer.toString();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
BufferedReader r = new BufferedReader(new FileReader(this.testFile));
|
||||
String line = r.readLine();
|
||||
while (line != null) {
|
||||
buffer.append(line);
|
||||
buffer.append(IScriptGenerator.EOL);
|
||||
line = r.readLine();
|
||||
}
|
||||
r.close();
|
||||
String script = buffer.toString();
|
||||
|
||||
String generatorClass = null;
|
||||
String[] classes = GeneratorFactory.getClasses();
|
||||
String generatorClass = null;
|
||||
String[] classes = GeneratorFactory.getClasses();
|
||||
|
||||
for (int i = 0; i < classes.length; i++) {
|
||||
if (script.indexOf(classes[i]) != -1) {
|
||||
generatorClass = classes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (generatorClass == null) {
|
||||
throw new Utils.UserException("Your file does not appear to have been generated by MaxQ.\n\n(MaxQ expects to find the class name of the generator somewhere in the script.\nPerhaps you have mistakenly deleted it?)");
|
||||
}
|
||||
for (int i = 0; i < classes.length; i++) {
|
||||
if (script.indexOf(classes[i]) != -1) {
|
||||
generatorClass = classes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (generatorClass == null) {
|
||||
throw new Utils.UserException(
|
||||
"Your file does not appear to have been generated by MaxQ.\n\n(MaxQ expects to find the class name of the generator somewhere in the script.\nPerhaps you have mistakenly deleted it?)");
|
||||
}
|
||||
|
||||
adapter.setText(script);
|
||||
this.generator = GeneratorFactory.newGenerator(generatorClass, adapter);
|
||||
this.generator.doLoad();
|
||||
this.testName = this.generator.parseTestName();
|
||||
}
|
||||
adapter.setText(script);
|
||||
this.generator = GeneratorFactory.newGenerator(generatorClass, adapter);
|
||||
this.generator.doLoad();
|
||||
this.testName = this.generator.parseTestName();
|
||||
}
|
||||
|
||||
public String getTestName()
|
||||
{
|
||||
return this.testName;
|
||||
}
|
||||
public String getTestName() {
|
||||
return this.testName;
|
||||
}
|
||||
|
||||
public File getTestFile()
|
||||
{
|
||||
return this.testFile;
|
||||
}
|
||||
public File getTestFile() {
|
||||
return this.testFile;
|
||||
}
|
||||
|
||||
public void setTestFile(File file)
|
||||
{
|
||||
this.testFile = file;
|
||||
}
|
||||
public void setTestFile(File file) {
|
||||
this.testFile = file;
|
||||
}
|
||||
|
||||
public String getCurrentPath()
|
||||
{
|
||||
if (this.testFile == null) {
|
||||
return System.getProperty("user.dir");
|
||||
}
|
||||
return stripFileName(this.testFile.getAbsolutePath());
|
||||
}
|
||||
public String getCurrentPath() {
|
||||
if (this.testFile == null) {
|
||||
return System.getProperty("user.dir");
|
||||
}
|
||||
return stripFileName(this.testFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
public String[] getvalidTestFileExtensions()
|
||||
{
|
||||
return this.generator.getValidFileExtensions();
|
||||
}
|
||||
public String[] getvalidTestFileExtensions() {
|
||||
return this.generator.getValidFileExtensions();
|
||||
}
|
||||
|
||||
public boolean isRecording()
|
||||
{
|
||||
return this.isRecording;
|
||||
}
|
||||
public boolean isRecording() {
|
||||
return this.isRecording;
|
||||
}
|
||||
|
||||
public void stopRecording()
|
||||
{
|
||||
this.proxyServer.removeObserver(this.generator);
|
||||
assert (this.isRecording);
|
||||
this.generator.doStopRecording();
|
||||
this.isRecording = false;
|
||||
}
|
||||
public void stopRecording() {
|
||||
this.proxyServer.removeObserver(this.generator);
|
||||
assert (this.isRecording);
|
||||
this.generator.doStopRecording();
|
||||
this.isRecording = false;
|
||||
}
|
||||
|
||||
public void startRecording()
|
||||
{
|
||||
assert (!this.isRecording);
|
||||
this.proxyServer.addObserver(this.generator);
|
||||
this.isRecording = true;
|
||||
this.generator.doStartRecording();
|
||||
}
|
||||
public void startRecording() {
|
||||
assert (!this.isRecording);
|
||||
this.proxyServer.addObserver(this.generator);
|
||||
this.isRecording = true;
|
||||
this.generator.doStartRecording();
|
||||
}
|
||||
|
||||
public String save() throws IOException
|
||||
{
|
||||
this.generator.doSave(stripFileName(this.testFile.getAbsolutePath()), this.testFile.getName());
|
||||
public String save() throws IOException {
|
||||
this.generator.doSave(stripFileName(this.testFile.getAbsolutePath()),
|
||||
this.testFile.getName());
|
||||
|
||||
PrintWriter writer = new PrintWriter(new FileWriter(this.testFile));
|
||||
String str = this.scriptAdapter.getText();
|
||||
str = Utils.replace(str, "\r\n", "\n");
|
||||
str = Utils.replace(str, "\n", IScriptGenerator.EOL);
|
||||
PrintWriter writer = new PrintWriter(new FileWriter(this.testFile));
|
||||
String str = this.scriptAdapter.getText();
|
||||
str = Utils.replace(str, "\r\n", "\n");
|
||||
str = Utils.replace(str, "\n", IScriptGenerator.EOL);
|
||||
|
||||
//TODO£ºwriter the string to DB
|
||||
writer.println(str);
|
||||
writer.close();
|
||||
// TODO£ºwriter the string to DB
|
||||
writer.println(str);
|
||||
writer.close();
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
private String stripFileName(String absolutePath)
|
||||
{
|
||||
int index = absolutePath.lastIndexOf(System.getProperty("file.separator"));
|
||||
if (index == -1) {
|
||||
return absolutePath;
|
||||
}
|
||||
return absolutePath.substring(0, index);
|
||||
}
|
||||
private String stripFileName(String absolutePath) {
|
||||
int index = absolutePath.lastIndexOf(System
|
||||
.getProperty("file.separator"));
|
||||
if (index == -1) {
|
||||
return absolutePath;
|
||||
}
|
||||
return absolutePath.substring(0, index);
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
if (this.isRecording)
|
||||
this.proxyServer.removeObserver(this.generator);
|
||||
this.generator.close();
|
||||
}
|
||||
public void close() {
|
||||
if (this.isRecording)
|
||||
this.proxyServer.removeObserver(this.generator);
|
||||
this.generator.close();
|
||||
}
|
||||
|
||||
public IScriptGenerator getGenerator()
|
||||
{
|
||||
return this.generator;
|
||||
}
|
||||
public IScriptGenerator getGenerator() {
|
||||
return this.generator;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.bench4q.master.communication.agent.UserBehaviorModel;
|
||||
import org.bench4q.master.entity.httpcapture.Action;
|
||||
import org.bench4q.master.entity.httpcapture.Config;
|
||||
import org.bench4q.master.entity.httpcapture.HeaderValue;
|
||||
|
@ -41,14 +42,13 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
|
|||
private String testPath;
|
||||
private boolean ignoreNextResponse;
|
||||
private Pattern[] namePatterns;
|
||||
private LinkedList<String> outstandingInserts;
|
||||
private LinkedList<UserBehaviorModel> outstandingInserts;
|
||||
private Thread insertThread;
|
||||
private String charset;
|
||||
private final Pattern insertMarkerRE = Pattern.compile("(^[ \\t]*" + EOL
|
||||
+ ")?" + ".*\\^\\^\\^ Insert new recording.*", 8);
|
||||
private long timeElapsedSinceLastestRequest = 0L;
|
||||
private Date latestRequestDate = new Date();
|
||||
private boolean isFirstRequest = true;
|
||||
|
||||
static final boolean $assertionsDisabled = !(AbstractCodeGenerator.class
|
||||
.desiredAssertionStatus());
|
||||
|
||||
|
@ -62,13 +62,12 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
|
|||
|
||||
public AbstractCodeGenerator(IScriptAdapter adapter, String[] nameRegExps) {
|
||||
this.scriptAdapter = adapter;
|
||||
|
||||
this.namePatterns = new Pattern[nameRegExps.length];
|
||||
for (int i = 0; i < nameRegExps.length; ++i)
|
||||
this.namePatterns[i] = Pattern.compile(nameRegExps[i], 8);
|
||||
|
||||
this.testName = this.config.getProperty("test.default_testname",
|
||||
"MaxQTest");
|
||||
"Bench4QTest");
|
||||
this.defaultTestName = this.testName;
|
||||
|
||||
this.insertThread = new Thread(this);
|
||||
|
@ -112,12 +111,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
|
|||
}
|
||||
|
||||
public String parseTestName() {
|
||||
Matcher m = this.namePatterns[0].matcher(getScript());
|
||||
if (!(m.find()))
|
||||
throw new IllegalArgumentException(
|
||||
"You have fiddled with the formatting of the name of the test embedded in this file. I can no longer understand it.");
|
||||
|
||||
return m.group(1);
|
||||
return this.testName;
|
||||
}
|
||||
|
||||
public void doSave(String path, String fileName) {
|
||||
|
@ -127,16 +121,6 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
|
|||
name = fileName.substring(0, dotPos);
|
||||
setTestName(name);
|
||||
setTestPath(path);
|
||||
|
||||
for (int i = 0; i < this.namePatterns.length; ++i) {
|
||||
Matcher m = this.namePatterns[i].matcher(getScript());
|
||||
if (!(m.find()))
|
||||
throw new IllegalArgumentException(
|
||||
"Regular expression (\""
|
||||
+ this.namePatterns[i].pattern()
|
||||
+ "\") provided to constructor cannot match the contents of the script");
|
||||
this.scriptAdapter.replace(name, m.start(1), m.end(1));
|
||||
}
|
||||
}
|
||||
|
||||
public void doLoad() {
|
||||
|
@ -338,30 +322,20 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
|
|||
}
|
||||
|
||||
public void run() {
|
||||
this.outstandingInserts = new LinkedList<String>();
|
||||
this.outstandingInserts = new LinkedList<UserBehaviorModel>();
|
||||
try {
|
||||
while (!(Thread.interrupted())) {
|
||||
try {
|
||||
synchronized (this.outstandingInserts) {
|
||||
this.outstandingInserts.wait();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (this.outstandingInserts.size() > 0) {
|
||||
sb.append((String) this.outstandingInserts
|
||||
.removeFirst());
|
||||
}
|
||||
synchronized (this.outstandingInserts) {
|
||||
this.outstandingInserts.wait();
|
||||
|
||||
Matcher m = this.insertMarkerRE.matcher(this
|
||||
.getScriptAdapter().getText());
|
||||
if (!(m.find()))
|
||||
throw new Utils.UserException(
|
||||
"You have altered your script and it no longer includes the lines that you were told not to alter.");
|
||||
System.out.println(sb.toString());
|
||||
this.getScriptAdapter().insert(sb.toString(),
|
||||
m.start(0));
|
||||
while (this.outstandingInserts.size() > 0) {
|
||||
UserBehaviorModel userBehaviorModel = this.outstandingInserts
|
||||
.removeFirst();
|
||||
this.getScriptAdapter().insertUserBehaviorsToScenario(
|
||||
userBehaviorModel);
|
||||
}
|
||||
} catch (Utils.UserException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -412,9 +386,10 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
|
|||
return this.scriptAdapter.getText();
|
||||
}
|
||||
|
||||
protected void insert(String s) throws Utils.UserException {
|
||||
protected void insert(UserBehaviorModel userBehaviorModel)
|
||||
throws Utils.UserException {
|
||||
synchronized (this.outstandingInserts) {
|
||||
this.outstandingInserts.add(s);
|
||||
this.outstandingInserts.add(userBehaviorModel);
|
||||
this.outstandingInserts.notifyAll();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,14 @@ import java.util.List;
|
|||
|
||||
import org.bench4q.master.communication.agent.ParameterModel;
|
||||
import org.bench4q.master.communication.agent.UsePluginModel;
|
||||
import org.bench4q.master.communication.agent.UserBehaviorModel;
|
||||
import org.bench4q.master.entity.httpcapture.Config;
|
||||
import org.bench4q.master.entity.httpcapture.HeaderValue;
|
||||
import org.bench4q.master.entity.httpcapture.IScriptAdapter;
|
||||
import org.bench4q.master.entity.httpcapture.Param;
|
||||
import org.bench4q.master.entity.httpcapture.Utils;
|
||||
|
||||
public class IsacCodeGenerator extends AbstractCodeGenerator {
|
||||
public class Bench4qCodeGenerator extends AbstractCodeGenerator {
|
||||
static final String TIMER_PROP = "generator.isac.timer";
|
||||
static final String NULL_TIMER = "null";
|
||||
static final String CONSTANT_TIMER = "ConstantTimer";
|
||||
|
@ -57,7 +58,7 @@ public class IsacCodeGenerator extends AbstractCodeGenerator {
|
|||
return result;
|
||||
}
|
||||
|
||||
public IsacCodeGenerator(IScriptAdapter adapter) {
|
||||
public Bench4qCodeGenerator(IScriptAdapter adapter) {
|
||||
super(adapter, new String[0]);
|
||||
}
|
||||
|
||||
|
@ -66,111 +67,16 @@ public class IsacCodeGenerator extends AbstractCodeGenerator {
|
|||
}
|
||||
|
||||
public void doNew() {
|
||||
wl("<?xml version=\"1.0\"?>");
|
||||
|
||||
wl("<scenario>");
|
||||
wl("\t<behaviors>");
|
||||
wl("\t\t<plugins>");
|
||||
wl("\t\t\t<use id=\"replayHttp\" name=\"HttpInjector\">");
|
||||
wl("\t\t\t\t<params>");
|
||||
wl("\t\t\t\t\t<param name=\"indepthload\" value=\"\"></param>");
|
||||
wl("\t\t\t\t\t<param name=\"proxyuserpass\" value=\"\"></param>");
|
||||
wl("\t\t\t\t\t<param name=\"useragent\" value=\"\"></param>");
|
||||
wl("\t\t\t\t\t<param name=\"proxyport\" value=\"\"></param>");
|
||||
wl("\t\t\t\t\t<param name=\"proxyhost\" value=\"\"></param>");
|
||||
wl("\t\t\t\t\t<param name=\"proxyusername\" value=\"\"></param>");
|
||||
wl("\t\t\t\t\t<param name=\"preemptiveauthentication\" value=\"\"></param>");
|
||||
wl("\t\t\t\t</params>");
|
||||
wl("\t\t\t</use>");
|
||||
|
||||
Config conf = Config.getConfig();
|
||||
this.timer = conf.getProperty("generator.isac.timer", "ConstantTimer");
|
||||
|
||||
if (this.timer.equals("ConstantTimer")) {
|
||||
wl("\t\t\t<use id=\"replayTimer\" name=\"ConstantTimer\"></use>");
|
||||
} else if (this.timer.equals("Random")) {
|
||||
wl(" <use id=\"replayTimer\" name=\"Random\"></use>");
|
||||
this.randomDist = Config.getConfig().getProperty(
|
||||
"generator.isac.timer.random.dist", "uniform");
|
||||
try {
|
||||
if (this.randomDist.equals("uniform")) {
|
||||
this.delta = conf.getPropertyInt(
|
||||
"generator.isac.timer.random.delta").intValue();
|
||||
} else if (this.randomDist.equals("gaussian")) {
|
||||
this.delta = conf.getPropertyInt(
|
||||
"generator.isac.timer.random.delta").intValue();
|
||||
this.deviation = conf.getPropertyInt(
|
||||
"generator.isac.timer.random.deviation").intValue();
|
||||
} else if (this.randomDist.equals("poisson")) {
|
||||
this.unit = conf.getPropertyInt(
|
||||
"generator.isac.timer.random.unit").intValue();
|
||||
} else if (!(this.randomDist.equals("negexpo"))) {
|
||||
|
||||
} else {
|
||||
this.delta = conf.getPropertyInt(
|
||||
"generator.isac.timer.random.delta").intValue();
|
||||
}
|
||||
|
||||
} catch (Utils.UserException ex) {
|
||||
ex.printStackTrace(System.err);
|
||||
System.err
|
||||
.println("Warning: incorrect property settings for Isac random timer distribution "
|
||||
+ this.randomDist);
|
||||
}
|
||||
}
|
||||
|
||||
wl("\t\t</plugins>");
|
||||
wl("\t\t<behavior id=\"session\">");
|
||||
wl("");
|
||||
wl("\t\t<!-- ^^^ Insert new recordings here. (Do not remove this line.) -->");
|
||||
wl("");
|
||||
wl("\t\t</behavior>");
|
||||
wl("\t</behaviors>");
|
||||
wl("\t<loadprofile></loadprofile>");
|
||||
wl("</scenario>");
|
||||
}
|
||||
|
||||
public void doNewForNewScenarioModel() {
|
||||
|
||||
List<UsePluginModel> usePlugins = new ArrayList<UsePluginModel>();
|
||||
UsePluginModel usePlugin1 = new UsePluginModel();
|
||||
UsePluginModel usePlugin2 = new UsePluginModel();
|
||||
List<UsePluginModel> usePlugins = new ArrayList<UsePluginModel>();
|
||||
ParameterModel param1 = new ParameterModel();
|
||||
ParameterModel param2 = new ParameterModel();
|
||||
ParameterModel param3 = new ParameterModel();
|
||||
ParameterModel param4 = new ParameterModel();
|
||||
ParameterModel param5 = new ParameterModel();
|
||||
ParameterModel param6 = new ParameterModel();
|
||||
ParameterModel param7 = new ParameterModel();
|
||||
|
||||
param1.setKey("indepthload");
|
||||
param1.setValue("");
|
||||
param2.setKey("proxyuserpass");
|
||||
param2.setValue("");
|
||||
param3.setKey("useragent");
|
||||
param3.setValue("");
|
||||
param4.setKey("proxyport");
|
||||
param4.setValue("");
|
||||
param5.setKey("proxyhost");
|
||||
param5.setValue("");
|
||||
param6.setKey("proxyusername");
|
||||
param6.setValue("");
|
||||
param7.setKey("preemptiveauthentication");
|
||||
param7.setValue("");
|
||||
usePlugin1.setParameters(new ArrayList<ParameterModel>());
|
||||
usePlugin1.setId("http");
|
||||
usePlugin1.setName("Http");
|
||||
|
||||
List<ParameterModel> params = new ArrayList<ParameterModel>();
|
||||
params.add(param1);
|
||||
params.add(param2);
|
||||
params.add(param3);
|
||||
params.add(param4);
|
||||
params.add(param5);
|
||||
params.add(param6);
|
||||
params.add(param7);
|
||||
|
||||
usePlugin1.setParameters(params);
|
||||
usePlugin1.setId("replayHttp");
|
||||
usePlugin1.setName("HttpInjector");
|
||||
usePlugin2.setId("replayTimer");
|
||||
usePlugin2.setId("timer");
|
||||
usePlugin2.setParameters(new ArrayList<ParameterModel>());
|
||||
|
||||
Config conf = Config.getConfig();
|
||||
this.timer = conf.getProperty("generator.isac.timer", "ConstantTimer");
|
||||
|
@ -207,8 +113,11 @@ public class IsacCodeGenerator extends AbstractCodeGenerator {
|
|||
+ this.randomDist);
|
||||
}
|
||||
}
|
||||
|
||||
usePlugins.add(usePlugin1);
|
||||
usePlugins.add(usePlugin2);
|
||||
|
||||
appendUserPluginsToScenario(usePlugins);
|
||||
}
|
||||
|
||||
public String[] getValidFileExtensions() {
|
||||
|
@ -237,50 +146,38 @@ public class IsacCodeGenerator extends AbstractCodeGenerator {
|
|||
String contentLength) throws Utils.UserException {
|
||||
if (!(isFirstRequest()))
|
||||
doInsertDelay(getTimeElapsedSinceLastestRequest());
|
||||
StringBuilder sample = new StringBuilder();
|
||||
UserBehaviorModel userBehavior = createUserBehavior(url, method);
|
||||
insertStmt(userBehavior);
|
||||
|
||||
sample.append("\t\t\t<sample use=\"replayHttp\" name=\"" + method
|
||||
+ "\">" + EOL);
|
||||
sample.append("\t\t\t\t<params>" + EOL);
|
||||
sample.append("\t\t\t\t\t<param name=\"password\" value=\"\"></param>"
|
||||
+ EOL);
|
||||
sample.append("\t\t\t\t\t<param name=\"parameters\" value=\""
|
||||
+ this.queryStringParameters + "\"></param>" + EOL);
|
||||
if (method.equalsIgnoreCase("post")) {
|
||||
sample.append("\t\t\t\t\t<param name=\"bodyparameters\" value=\""
|
||||
+ this.bodyParameters + "\"></param>" + EOL);
|
||||
}
|
||||
sample.append("\t\t\t\t\t<param name=\"realm\" value=\"\"></param>"
|
||||
+ EOL);
|
||||
sample.append("\t\t\t\t\t<param name=\"proxyport\" value=\"\"></param>"
|
||||
+ EOL);
|
||||
sample.append("\t\t\t\t\t<param name=\"proxyhost\" value=\"\"></param>"
|
||||
+ EOL);
|
||||
sample.append("\t\t\t\t\t<param name=\"cookies\" value=\"\"></param>"
|
||||
+ EOL);
|
||||
sample.append("\t\t\t\t\t<param name=\"proxypassword\" value=\"\"></param>"
|
||||
+ EOL);
|
||||
sample.append("\t\t\t\t\t<param name=\"hostauth\" value=\"\"></param>"
|
||||
+ EOL);
|
||||
sample.append("\t\t\t\t\t<param name=\"cookiepolicy\" value=\"\"></param>"
|
||||
+ EOL);
|
||||
sample.append("\t\t\t\t\t<param name=\"uri\" value=\"" + url
|
||||
+ "\"></param>" + EOL);
|
||||
sample.append("\t\t\t\t\t<param name=\"username\" value=\"\"></param>"
|
||||
+ EOL);
|
||||
sample.append("\t\t\t\t\t<param name=\"redirect\" value=\"\"></param>"
|
||||
+ EOL);
|
||||
sample.append("\t\t\t\t\t<param name=\"localaddress\" value=\"\"></param>"
|
||||
+ EOL);
|
||||
sample.append("\t\t\t\t\t<param name=\"proxylogin\" value=\"\"></param>"
|
||||
+ EOL);
|
||||
sample.append("\t\t\t\t</params>" + EOL);
|
||||
sample.append("\t\t\t</sample>" + EOL);
|
||||
insertStmt(sample.toString());
|
||||
this.queryStringParameters = "";
|
||||
this.bodyParameters = "";
|
||||
}
|
||||
|
||||
private UserBehaviorModel createUserBehavior(String url, String method) {
|
||||
UserBehaviorModel userBehavior = new UserBehaviorModel();
|
||||
ParameterModel param1 = new ParameterModel();
|
||||
ParameterModel param3 = new ParameterModel();
|
||||
List<ParameterModel> params = new ArrayList<ParameterModel>();
|
||||
param1.setKey("uri");
|
||||
param1.setValue(url);
|
||||
param3.setKey("parameters");
|
||||
param3.setValue(this.queryStringParameters);
|
||||
params.add(param1);
|
||||
params.add(param3);
|
||||
if (method.equalsIgnoreCase("post")) {
|
||||
ParameterModel param2 = new ParameterModel();
|
||||
param2.setKey("bodyparameters");
|
||||
param2.setValue(this.bodyParameters);
|
||||
params.add(param2);
|
||||
}
|
||||
|
||||
userBehavior.setName(method);
|
||||
userBehavior.setUse("Http");
|
||||
userBehavior.setParameters(params);
|
||||
|
||||
return userBehavior;
|
||||
}
|
||||
|
||||
public void doAssertResponse(String respCode) {
|
||||
}
|
||||
|
||||
|
@ -311,16 +208,26 @@ public class IsacCodeGenerator extends AbstractCodeGenerator {
|
|||
public void doHeaders(HeaderValue[] headers) {
|
||||
}
|
||||
|
||||
private void wl(String s) {
|
||||
getScriptAdapter().append(s + EOL);
|
||||
private void appendUserPluginsToScenario(List<UsePluginModel> usePlugins) {
|
||||
|
||||
this.getScriptAdapter().appendUsePluginsToScenario(usePlugins);
|
||||
}
|
||||
|
||||
private void insertStmt(String s) throws Utils.UserException {
|
||||
insert(s + EOL);
|
||||
private void insertStmt(UserBehaviorModel userBehaviorModel)
|
||||
throws Utils.UserException {
|
||||
insert(userBehaviorModel);
|
||||
}
|
||||
|
||||
private void doInsertDelay(long delay) throws Utils.UserException {
|
||||
StringBuilder timerStr = new StringBuilder();
|
||||
timerStr = createTimer(delay);
|
||||
System.out.println(timerStr);
|
||||
// insertStmt(timerStr.toString());
|
||||
}
|
||||
|
||||
private StringBuilder createTimer(long delay) {
|
||||
StringBuilder timerStr = new StringBuilder();
|
||||
|
||||
if (this.timer.equals("Random")) {
|
||||
int min = (int) (delay - this.delta);
|
||||
if (min < 0)
|
||||
|
@ -382,7 +289,7 @@ public class IsacCodeGenerator extends AbstractCodeGenerator {
|
|||
timerStr.append("\t\t\t\t</params>" + EOL);
|
||||
timerStr.append("\t\t\t</timer>" + EOL);
|
||||
}
|
||||
insertStmt(timerStr.toString());
|
||||
return timerStr;
|
||||
}
|
||||
|
||||
public void doSetCharset(String cs) throws Utils.UserException {
|
Loading…
Reference in New Issue