package information added.

This commit is contained in:
Zhen Tang 2013-07-15 15:42:18 +08:00
parent 8d929f31de
commit dbd4fbc1d0
9 changed files with 360 additions and 338 deletions

25
descriptor.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>publish</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<files>
<file>
<source>target/bench4q-master.jar</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
</assembly>

48
pom.xml
View File

@ -79,13 +79,51 @@
<version>2.7-b1</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.bench4q.master.Main</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>descriptor.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
<finalName>bench4q-master</finalName>
</build>
</project>

View File

@ -1,67 +1,67 @@
package org.bench4q.master;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.bio.SocketConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.springframework.web.servlet.DispatcherServlet;
public class MasterServer {
private Server server;
private int port;
private Server getServer() {
return server;
}
private void setServer(Server server) {
this.server = server;
}
private int getPort() {
return port;
}
private void setPort(int port) {
this.port = port;
}
public MasterServer(int port) {
this.setPort(port);
}
public boolean start() {
try {
this.setServer(new Server());
Connector connector = new SocketConnector();
connector.setPort(this.getPort());
this.getServer().addConnector(connector);
ServletContextHandler servletContextHandler = new ServletContextHandler();
ServletHolder servletHolder = servletContextHandler.addServlet(
DispatcherServlet.class, "/");
servletHolder.setInitParameter("contextConfigLocation",
"classpath*:/application-context.xml");
this.getServer().setHandler(servletContextHandler);
this.getServer().start();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean stop() {
try {
if (this.getServer() != null) {
this.getServer().stop();
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
this.setServer(null);
}
}
}
package org.bench4q.master;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.bio.SocketConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.springframework.web.servlet.DispatcherServlet;
public class MasterServer {
private Server server;
private int port;
private Server getServer() {
return server;
}
private void setServer(Server server) {
this.server = server;
}
private int getPort() {
return port;
}
private void setPort(int port) {
this.port = port;
}
public MasterServer(int port) {
this.setPort(port);
}
public boolean start() {
try {
this.setServer(new Server());
Connector connector = new SocketConnector();
connector.setPort(this.getPort());
this.getServer().addConnector(connector);
ServletContextHandler servletContextHandler = new ServletContextHandler();
ServletHolder servletHolder = servletContextHandler.addServlet(
DispatcherServlet.class, "/");
servletHolder.setInitParameter("contextConfigLocation",
"classpath*:org/bench4q/master/config/application-context.xml");
this.getServer().setHandler(servletContextHandler);
this.getServer().start();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean stop() {
try {
if (this.getServer() != null) {
this.getServer().stop();
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
this.setServer(null);
}
}
}

View File

@ -1,8 +1,7 @@
package org.bench4q.master.auth;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.KeyStore.PrivateKeyEntry;
import java.security.KeyStore;
import java.security.PrivateKey;
@ -39,14 +38,13 @@ public class CryptoManager {
public CryptoManager() {
try {
String pfxFileName = Thread.currentThread().getContextClassLoader()
.getResource("key.pfx").getFile();
InputStream pfxInputStream = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream("org/bench4q/master/config/key.pfx");
String pfxPassword = "123456";
File pfxFile = new File(pfxFileName);
FileInputStream pfxFileInputStream = new FileInputStream(pfxFile);
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(pfxFileInputStream, pfxPassword.toCharArray());
pfxFileInputStream.close();
keyStore.load(pfxInputStream, pfxPassword.toCharArray());
pfxInputStream.close();
Enumeration<String> aliases = keyStore.aliases();
if (aliases.hasMoreElements()) {
String alias = aliases.nextElement();

View File

@ -2,7 +2,6 @@ package org.bench4q.master.entity.httpcapture;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
import javax.swing.JOptionPane;
@ -26,308 +25,269 @@ import org.python.core.PyTuple;
public class HttpTestCase extends TestCase {
private static final Log log = LogFactory.getLog(HttpTestCase.class);
private Config config = Config.getConfig();
private HashMap connections = new HashMap();
protected HttpMethod method = null;
protected HttpClient client = new HttpClient();
protected String data;
private boolean followRedirects = false;
private static String urlSearch;
private static String urlReplace;
private String charset;
private Config config = Config.getConfig();
protected HttpMethod method = null;
protected HttpClient client = new HttpClient();
protected String data;
private boolean followRedirects = false;
private static String urlSearch;
private static String urlReplace;
private String charset;
public void setCharset(String cs)
{
this.charset = cs;
}
public void setCharset(String cs) {
this.charset = cs;
}
public static String getUrlReplace()
{
return urlReplace;
}
public static String getUrlReplace() {
return urlReplace;
}
public static String getUrlSearch()
{
return urlSearch;
}
public static String getUrlSearch() {
return urlSearch;
}
public static void setURLReplace(String search, String replace)
{
if (urlSearch == null) {
urlSearch = search.trim();
urlReplace = replace.trim();
}
log.debug("Ignoring setURLReplace call: search: " + search + " replace: " + replace);
}
public static void setURLReplace(String search, String replace) {
if (urlSearch == null) {
urlSearch = search.trim();
urlReplace = replace.trim();
}
log.debug("Ignoring setURLReplace call: search: " + search
+ " replace: " + replace);
}
public static String replaceURL(String url)
{
if ((urlSearch == null) || (urlReplace == null))
return url;
public static String replaceURL(String url) {
if ((urlSearch == null) || (urlReplace == null))
return url;
int pos = url.indexOf(urlSearch);
if (pos == -1)
return url;
int pos = url.indexOf(urlSearch);
if (pos == -1)
return url;
String str = url.substring(0, pos) + urlReplace +
url.substring(pos + urlSearch.length());
return str;
}
String str = url.substring(0, pos) + urlReplace
+ url.substring(pos + urlSearch.length());
return str;
}
public HttpTestCase(String name)
{
super(name);
Config.ProxySettings proxy = this.config.getProxySettings();
if (proxy != null) {
HostConfiguration hc = this.client.getHostConfiguration();
hc.setProxy(proxy.host, proxy.port);
}
}
public HttpTestCase(String name) {
super(name);
Config.ProxySettings proxy = this.config.getProxySettings();
if (proxy != null) {
HostConfiguration hc = this.client.getHostConfiguration();
hc.setProxy(proxy.host, proxy.port);
}
}
public void Run()
throws Throwable
{
setUp();
runTest();
tearDown();
}
public void Run() throws Throwable {
setUp();
runTest();
tearDown();
}
public HttpMethod getMethod()
{
return this.method;
}
public HttpMethod getMethod() {
return this.method;
}
@SuppressWarnings("deprecation")
private void cleanupMethod()
{
if (this.method != null) {
this.method.releaseConnection();
this.method.recycle();
this.method = null;
}
}
@SuppressWarnings("deprecation")
private void cleanupMethod() {
if (this.method != null) {
this.method.releaseConnection();
this.method.recycle();
this.method = null;
}
}
public void get(String url) throws IOException
{
get(url, null);
}
public void get(String url) throws IOException {
get(url, null);
}
public void get(String url, Object[] args) throws IOException
{
cleanupMethod();
public void get(String url, Object[] args) throws IOException {
cleanupMethod();
url = replaceURL(url);
this.method = new GetMethod(url);
url = replaceURL(url);
this.method = new GetMethod(url);
if (args != null) {
this.method.setQueryString(paramsToNV(args));
}
if (args != null) {
this.method.setQueryString(paramsToNV(args));
}
this.method.setFollowRedirects(this.followRedirects);
this.client.executeMethod(this.method);
}
this.method.setFollowRedirects(this.followRedirects);
this.client.executeMethod(this.method);
}
public void post(String url) throws IOException
{
post(url, null);
}
public void post(String url) throws IOException {
post(url, null);
}
public void post(String url, Object[] args) throws IOException
{
cleanupMethod();
url = replaceURL(url);
PostMethod post = new PostMethod(url);
public void post(String url, Object[] args) throws IOException {
cleanupMethod();
url = replaceURL(url);
PostMethod post = new PostMethod(url);
if (this.charset != null) {
post.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded; charset=" +
this.charset);
}
if (this.charset != null) {
post.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded; charset="
+ this.charset);
}
if (args != null) {
post.setRequestBody(paramsToNV(args));
}
if (args != null) {
post.setRequestBody(paramsToNV(args));
}
this.method = post;
this.method.setFollowRedirects(this.followRedirects);
this.client.executeMethod(this.method);
}
this.method = post;
this.method.setFollowRedirects(this.followRedirects);
this.client.executeMethod(this.method);
}
public void postMultiPart(String url, String data, int contLen)
throws IOException
{
postMultiPart(url, data, contLen, null);
}
public void postMultiPart(String url, String data, int contLen)
throws IOException {
postMultiPart(url, data, contLen, null);
}
@SuppressWarnings("deprecation")
public void postMultiPart(String url, String data, int contLen, Object[] args)
throws IOException
{
cleanupMethod();
url = replaceURL(url);
@SuppressWarnings("deprecation")
public void postMultiPart(String url, String data, int contLen,
Object[] args) throws IOException {
cleanupMethod();
url = replaceURL(url);
MultipartPostMethod multipartPost = new MultipartPostMethod(url);
multipartPost.addPart(new StringPart("data", data));
if (args != null) {
multipartPost.setQueryString(paramsToNV(args));
}
MultipartPostMethod multipartPost = new MultipartPostMethod(url);
multipartPost.addPart(new StringPart("data", data));
if (args != null) {
multipartPost.setQueryString(paramsToNV(args));
}
this.method = multipartPost;
this.method.setFollowRedirects(this.followRedirects);
this.client.executeMethod(this.method);
}
this.method = multipartPost;
this.method.setFollowRedirects(this.followRedirects);
this.client.executeMethod(this.method);
}
public void setConnections(HttpTestCase test)
{
test.connections = this.connections;
}
public NameValuePair[] paramsToNV(Object[] params) {
NameValuePair[] res = new NameValuePair[params.length];
for (int i = 0; i < params.length; ++i) {
Object param = params[i];
if (param instanceof PyTuple) {
PyTuple pyParam = (PyTuple) param;
res[i] = new NameValuePair(pyParam.__getitem__(0).toString(),
pyParam.__getitem__(1).toString());
} else if (param instanceof NameValuePair) {
res[i] = ((NameValuePair) param);
}
}
return res;
}
public NameValuePair[] paramsToNV(Object[] params)
{
NameValuePair[] res = new NameValuePair[params.length];
for (int i = 0; i < params.length; ++i) {
Object param = params[i];
if (param instanceof PyTuple) {
PyTuple pyParam = (PyTuple)param;
res[i] =
new NameValuePair(pyParam.__getitem__(0).toString(),
pyParam.__getitem__(1).toString());
}
else if (param instanceof NameValuePair) {
res[i] = ((NameValuePair)param); }
}
return res;
}
public String urlDecode(String s) {
return staticUrlDecode(s);
}
public String urlDecode(String s)
{
return staticUrlDecode(s);
}
public static String staticUrlDecode(String s) {
ByteArrayOutputStream out = new ByteArrayOutputStream(s.length());
for (int count = 0; count < s.length(); ++count)
if (s.charAt(count) == '%') {
++count;
if (count < s.length()) {
int a = Character.digit(s.charAt(count++), 16);
a <<= 4;
int b = Character.digit(s.charAt(count), 16);
public static String staticUrlDecode(String s)
{
ByteArrayOutputStream out = new ByteArrayOutputStream(s.length());
for (int count = 0; count < s.length(); ++count)
if (s.charAt(count) == '%') {
++count;
if (count < s.length()) {
int a = Character.digit(s.charAt(count++), 16);
a <<= 4;
int b = Character.digit(s.charAt(count), 16);
if ((a + b == 39) || (a + b == 132))
out.write(92);
out.write(a + b);
} else {
out.write(37);
}
} else if (s.charAt(count) == '+') {
out.write(32);
} else {
out.write(s.charAt(count));
}
if ((a + b == 39) || (a + b == 132)) out.write(92);
out.write(a + b);
}
else
{
out.write(37);
}
}
else if (s.charAt(count) == '+') {
out.write(32);
} else {
out.write(s.charAt(count));
}
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));
}
return out.toString();
}
protected boolean responseContainsURI(String uri) throws URIException {
return ((this.method != null) && (this.method.getURI().getPath()
.indexOf(uri) != -1));
}
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 responseContains(String text) {
try {
if ((this.method == null)
|| (this.method.getResponseBody() == null))
return false;
protected boolean responseContainsURI(String uri)
throws URIException
{
return ((this.method != null) &&
(this.method.getURI().getPath().indexOf(uri) != -1));
}
protected boolean responseContains(String text)
{
try {
if ((this.method == null) || (this.method.getResponseBody() == null)) return false;
this.data = this.method.getResponseBodyAsString();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return (this.data.indexOf(text) != -1);
}
return (this.data.indexOf(text) != -1);
}
protected void printResponse()
{
try {
protected void printResponse() {
try {
System.err.println(new String(this.method.getResponseBody()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public String getResponse() throws IOException
{
return this.method.getResponseBodyAsString();
}
public String getResponse() throws IOException {
return this.method.getResponseBodyAsString();
}
public byte[] getResponseAsBytes() throws IOException
{
return this.method.getResponseBody();
}
public byte[] getResponseAsBytes() throws IOException {
return this.method.getResponseBody();
}
public int getResponseCode()
{
return getMethod().getStatusCode();
}
public int getResponseCode() {
return getMethod().getStatusCode();
}
public PyDictionary getResponseHeader()
{
PyDictionary dict = new PyDictionary();
Header[] headers = this.method.getResponseHeaders();
public PyDictionary getResponseHeader() {
PyDictionary dict = new PyDictionary();
Header[] headers = this.method.getResponseHeaders();
for (int i = 0; i < headers.length; ++i)
dict.__setitem__(new PyString(headers[i].getName()),
new PyString(headers[i].getValue()));
return dict;
}
for (int i = 0; i < headers.length; ++i)
dict.__setitem__(new PyString(headers[i].getName()), new PyString(
headers[i].getValue()));
return dict;
}
public String getScriptArg()
{
return this.config.getScriptArg();
}
public String getScriptArg() {
return this.config.getScriptArg();
}
public boolean userConfirm(String msg)
{
int rc = JOptionPane.showConfirmDialog(null, msg, "HttpCapture",
2);
return (rc == 0);
}
public boolean userConfirm(String msg) {
int rc = JOptionPane.showConfirmDialog(null, msg, "HttpCapture", 2);
return (rc == 0);
}
public String userInput(String msg)
{
return JOptionPane.showInputDialog(null, msg, "HttpCapture",
3);
}
public String userInput(String msg) {
return JOptionPane.showInputDialog(null, msg, "HttpCapture", 3);
}
public String getStrutsToken() throws IOException
{
String responseString = new String(this.method.getResponseBodyAsString());
public String getStrutsToken() throws IOException {
String responseString = new String(
this.method.getResponseBodyAsString());
String strutsToken = null;
String strutsToken = null;
int tokenIDIndex = responseString.toLowerCase().indexOf("org.apache.struts.taglib.html.TOKEN".toLowerCase());
int nextValue = responseString.toLowerCase().indexOf("value=\"".toLowerCase(), tokenIDIndex);
int tokenIDIndex = responseString.toLowerCase().indexOf(
"org.apache.struts.taglib.html.TOKEN".toLowerCase());
int nextValue = responseString.toLowerCase().indexOf(
"value=\"".toLowerCase(), tokenIDIndex);
strutsToken = responseString.substring(nextValue + "value=\"".length(), nextValue + "value=\"".length() + 32);
return strutsToken;
}
strutsToken = responseString.substring(nextValue + "value=\"".length(),
nextValue + "value=\"".length() + 32);
return strutsToken;
}
}

View File

@ -21,7 +21,8 @@ public final class SessionHelper {
public SessionHelper() {
try {
Configuration cfg = new Configuration().configure();
Configuration cfg = new Configuration()
.configure("org/bench4q/master/config/hibernate.cfg.xml");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties()).build();
this.setSessionFactory(cfg.buildSessionFactory(serviceRegistry));

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.bench4q" />
<mvc:annotation-driven />
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.bench4q" />
<mvc:annotation-driven />
</beans>