remove the bug
This commit is contained in:
parent
e033a20c32
commit
e6526432a8
|
@ -1 +1,17 @@
|
|||
<html><body></body></html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bench4Q Test Case</title>
|
||||
<link href="style/bootstrap-cerulean.css" />
|
||||
<link href="style/bootstrap-classic.css" />
|
||||
<link href="style/bootstrap-cerulean.css" />
|
||||
</head>
|
||||
<body>
|
||||
<img src="images/1.jpg" alt="No this one" />
|
||||
<img src="images/2.jpg" alt="No this one" />
|
||||
<img src="images/3.jpg" alt="No this one" />
|
||||
|
||||
<script src="script/agentTable.js" type="text/javascript"></script>
|
||||
<script src="script/base.js" type="text/javascript"></script>
|
||||
</body>
|
||||
|
||||
</html
|
|
@ -1,124 +1,291 @@
|
|||
package org.bench4q.master.scriptrecord.httpcapture;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.impl.io.DefaultHttpRequestParser;
|
||||
import org.apache.http.impl.io.HttpTransportMetricsImpl;
|
||||
import org.apache.http.impl.io.SessionInputBufferImpl;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class HttpRequestHeader {
|
||||
private static final Logger log = Logger.getLogger(HttpRequestHeader.class);
|
||||
/**
|
||||
* Parses and stores a http server request. Originally posted to
|
||||
* comp.lang.java in 1996.
|
||||
*
|
||||
* @author Sherman Janes
|
||||
*/
|
||||
public class HttpRequestHeader
|
||||
{
|
||||
private static final Log log = LogFactory.getLog(HttpRequestHeader.class);
|
||||
|
||||
public String charset = new String();
|
||||
/**
|
||||
* Http Request method. Such as get or post.
|
||||
*/
|
||||
public String method = new String();
|
||||
|
||||
public String method = new String();
|
||||
/**
|
||||
* The requested url. The universal resource locator that
|
||||
* hopefully uniquely describes the object or service the
|
||||
* client is requesting.
|
||||
*/
|
||||
public String url = new String();
|
||||
|
||||
public String url = new String();
|
||||
/**
|
||||
* Version of http being used. Such as HTTP/1.0
|
||||
*/
|
||||
public String version = new String();
|
||||
|
||||
public String version = new String();
|
||||
/**
|
||||
* The client's browser's name.
|
||||
*/
|
||||
public String userAgent = new String();
|
||||
|
||||
public String userAgent = new String();
|
||||
/**
|
||||
* The requesting documents that contained the url link.
|
||||
*/
|
||||
public String referer = new String();
|
||||
|
||||
public String referer = new String();
|
||||
/**
|
||||
* A internet address date of the remote copy.
|
||||
*/
|
||||
public String ifModifiedSince = new String();
|
||||
|
||||
public String ifModifiedSince = new String();
|
||||
/**
|
||||
* A list of mime types the client can accept.
|
||||
*/
|
||||
public String accept = new String();
|
||||
|
||||
public String accept = new String();
|
||||
/**
|
||||
* The clients authorization. Don't belive it.
|
||||
*/
|
||||
public String authorization = new String();
|
||||
/**
|
||||
* The type of content following the request header.
|
||||
* Normally there is no content and this is blank, however
|
||||
* the post method usually does have a content and a content
|
||||
* length.
|
||||
*/
|
||||
public String contentType = new String();
|
||||
/**
|
||||
* The length of the content following the header. Usually
|
||||
* blank.
|
||||
*/
|
||||
public int contentLength = -1;
|
||||
/**
|
||||
* The content length of a remote copy of the requested object.
|
||||
*/
|
||||
public int oldContentLength = -1;
|
||||
/**
|
||||
* Anything in the header that was unrecognized by this class.
|
||||
*/
|
||||
public String unrecognized = new String();
|
||||
/**
|
||||
* Indicates that no cached versions of the requested object are
|
||||
* to be sent. Usually used to tell proxy not to send a cached copy.
|
||||
* This may also effect servers that are front end for data bases.
|
||||
*/
|
||||
public boolean pragmaNoCache = false;
|
||||
|
||||
public String authorization = new String();
|
||||
final static String CR = "\r\n";
|
||||
|
||||
public String contentType = new String();
|
||||
/**
|
||||
* That from which we read.
|
||||
*/
|
||||
private InputStream input;
|
||||
|
||||
public int contentLength = -1;
|
||||
|
||||
public int oldContentLength = -1;
|
||||
/**
|
||||
* Parses a http header from a stream.
|
||||
*
|
||||
* @param in The stream to parse.
|
||||
*/
|
||||
public HttpRequestHeader(InputStream in) throws IOException
|
||||
{
|
||||
input = in;
|
||||
|
||||
public String unrecognized = new String();
|
||||
/*
|
||||
* Read by lines
|
||||
*/
|
||||
StringTokenizer tz = new StringTokenizer(readLine());
|
||||
|
||||
public boolean pragmaNoCache = false;
|
||||
/*
|
||||
* HTTP COMMAND LINE < <METHOD==get> <URL> <HTTP_VERSION> >
|
||||
*/
|
||||
method = getToken(tz).toUpperCase();
|
||||
url = getToken(tz);
|
||||
version = getToken(tz);
|
||||
|
||||
static final String CR = "\r\n";
|
||||
while (true) {
|
||||
String line = readLine();
|
||||
log.trace(line);
|
||||
tz = new StringTokenizer(line);
|
||||
String Token = getToken(tz);
|
||||
|
||||
private HttpRequest httpRequest;
|
||||
// look for termination of HTTP command
|
||||
if (0 == Token.length())
|
||||
break;
|
||||
|
||||
private HttpRequest getHttpRequest() {
|
||||
return httpRequest;
|
||||
}
|
||||
if (Token.equalsIgnoreCase("USER-AGENT:")) {
|
||||
// line =<User-Agent: <Agent Description>>
|
||||
userAgent = getRemainder(tz);
|
||||
} else if (Token.equalsIgnoreCase("ACCEPT:")) {
|
||||
// line=<Accept: <Type>/<Form>
|
||||
// examp: Accept image/jpeg
|
||||
accept += " " + getRemainder(tz);
|
||||
|
||||
private void setHttpRequest(HttpRequest httpRequest) {
|
||||
this.httpRequest = httpRequest;
|
||||
}
|
||||
} else if (Token.equalsIgnoreCase("REFERER:")) {
|
||||
// line =<Referer: <URL>>
|
||||
referer = getRemainder(tz);
|
||||
|
||||
public HttpRequestHeader(InputStream in) throws IOException {
|
||||
SessionInputBufferImpl inputBuffer = new SessionInputBufferImpl(
|
||||
new HttpTransportMetricsImpl(), 1024);
|
||||
inputBuffer.bind(in);
|
||||
try {
|
||||
this.setHttpRequest(new DefaultHttpRequestParser(inputBuffer)
|
||||
.parse());
|
||||
} else if (Token.equalsIgnoreCase("PRAGMA:")) {
|
||||
// Pragma: <no-cache>
|
||||
Token = getToken(tz);
|
||||
|
||||
this.url = this.httpRequest.getRequestLine().getUri();
|
||||
this.method = this.httpRequest.getRequestLine().getMethod();
|
||||
this.version = this.httpRequest.getRequestLine()
|
||||
.getProtocolVersion().toString();
|
||||
if (Token.equalsIgnoreCase("NO-CACHE"))
|
||||
pragmaNoCache = true;
|
||||
else
|
||||
unrecognized += "Pragma:" + Token + " "
|
||||
+ getRemainder(tz) + "\n";
|
||||
} else if (Token.equalsIgnoreCase("AUTHORIZATION:")) {
|
||||
// Authenticate: Basic UUENCODED
|
||||
authorization = getRemainder(tz);
|
||||
|
||||
this.accept = this.getHeaderValue(HeaderValue.REQUEST_ACCEPT);
|
||||
this.referer = this.getHeaderValue(HeaderValue.REQUEST_REFERER);
|
||||
this.userAgent = this
|
||||
.getHeaderValue(HeaderValue.REQUEST_USER_AGENT);
|
||||
this.ifModifiedSince = this.getHeaderValue("if-modified-since");
|
||||
this.authorization = this
|
||||
.getHeaderValue(HeaderValue.REQUEST_AUTHORIZATION);
|
||||
this.contentType = this
|
||||
.getHeaderValue(HeaderValue.ENTITY_CONTENT_TYPE);
|
||||
this.pragmaNoCache = this
|
||||
.getHeaderValue(HeaderValue.GENERAL_PRAGMA)
|
||||
.equalsIgnoreCase("NO-CACHE");
|
||||
if (this.getHttpRequest().containsHeader(
|
||||
HeaderValue.ENTITY_CONTENT_LENGHT)) {
|
||||
this.contentLength = Integer.parseInt(this.httpRequest
|
||||
.getFirstHeader(HeaderValue.ENTITY_CONTENT_LENGHT)
|
||||
.getValue());
|
||||
} else {
|
||||
this.contentLength = 0;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
} catch (HttpException e) {
|
||||
log.error(ExceptionLog.getExceptionStackTrace(e));
|
||||
} catch (NumberFormatException e) {
|
||||
log.error(ExceptionLog.getExceptionStackTrace(e));
|
||||
}
|
||||
}
|
||||
} else if (Token.equalsIgnoreCase("IF-MODIFIED-SINCE:")) {
|
||||
// line =<If-Modified-Since: <http date>
|
||||
// *** Conditional GET replaces HEAD method ***
|
||||
String str = getRemainder(tz);
|
||||
int index = str.indexOf(";");
|
||||
if (index == -1) {
|
||||
ifModifiedSince = str;
|
||||
} else {
|
||||
ifModifiedSince = str.substring(0, index);
|
||||
|
||||
public boolean containsHeader(String name) {
|
||||
return this.getHttpRequest().containsHeader(name);
|
||||
}
|
||||
index = str.indexOf("=");
|
||||
if (index != -1) {
|
||||
str = str.substring(index + 1);
|
||||
oldContentLength = Integer.parseInt(str);
|
||||
}
|
||||
}
|
||||
} else if (Token.equalsIgnoreCase("CONTENT-LENGTH:")) {
|
||||
Token = getToken(tz);
|
||||
contentLength = Integer.parseInt(Token);
|
||||
} else if (Token.equalsIgnoreCase("CONTENT-TYPE:")) {
|
||||
contentType = getRemainder(tz);
|
||||
} else {
|
||||
unrecognized += Token + " " + getRemainder(tz) + CR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return if contains this header return the header's value; if not return
|
||||
* ""
|
||||
*/
|
||||
public String getHeaderValue(String name) {
|
||||
if (!this.containsHeader(name)) {
|
||||
return "";
|
||||
}
|
||||
return this.getHttpRequest().getFirstHeader(name).getValue();
|
||||
}
|
||||
/**
|
||||
* We would like to use BufferedReader.readLine(), but it may read past
|
||||
* the header while filling its buffer. Anything it over-read would thus
|
||||
* be missed from the body. (Reading the body cannot be via a Reader-
|
||||
* derived class because we do not want to do any character set conversion
|
||||
* at this stage. It might be binary data!)
|
||||
*/
|
||||
String readLine() throws IOException
|
||||
{
|
||||
int c;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while ((c = input.read()) != '\n') {
|
||||
if (c == -1)
|
||||
throw new IOException("unterminated line in request header");
|
||||
sb.append((char) c);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String result = this.getHttpRequest().getRequestLine().toString();
|
||||
for (Header header : this.getHttpRequest().getAllHeaders()) {
|
||||
result += CR + header.getName() + ": " + header.getValue();
|
||||
}
|
||||
System.out.println(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Rebuilds the header in a string
|
||||
* @return The header in a string.
|
||||
*/
|
||||
public String toString(boolean sendUnknowen)
|
||||
{
|
||||
String Request;
|
||||
|
||||
if (0 == method.length())
|
||||
method = "GET";
|
||||
|
||||
Request = method + " " + url + " HTTP/1.0" + CR;
|
||||
|
||||
if (0 < userAgent.length())
|
||||
Request += "User-Agent:" + userAgent + CR;
|
||||
|
||||
if (0 < referer.length())
|
||||
Request += "Referer:" + referer + CR;
|
||||
|
||||
if (pragmaNoCache)
|
||||
Request += "Pragma: no-cache" + CR;
|
||||
|
||||
if (0 < ifModifiedSince.length())
|
||||
Request += "If-Modified-Since: " + ifModifiedSince + CR;
|
||||
|
||||
// ACCEPT TYPES //
|
||||
if (0 < accept.length())
|
||||
Request += "Accept: " + accept + CR;
|
||||
else
|
||||
Request += "Accept: */" + "* \r\n";
|
||||
|
||||
if (0 < contentType.length())
|
||||
Request += "Content-Type: " + contentType + CR;
|
||||
|
||||
if (0 < contentLength)
|
||||
Request += "Content-Length: " + contentLength + CR;
|
||||
|
||||
|
||||
if (0 != authorization.length())
|
||||
Request += "Authorization: " + authorization + CR;
|
||||
|
||||
if (sendUnknowen) {
|
||||
if (0 != unrecognized.length())
|
||||
Request += unrecognized;
|
||||
}
|
||||
|
||||
Request += CR;
|
||||
|
||||
return Request;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* (Re)builds the header in a string.
|
||||
*
|
||||
* @return The header in a string.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return toString(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next token in a string
|
||||
*
|
||||
* @param tk String that is partially tokenized.
|
||||
* @return The remainder
|
||||
*/
|
||||
String getToken(StringTokenizer tk)
|
||||
{
|
||||
String str = "";
|
||||
if (tk.hasMoreTokens())
|
||||
str = tk.nextToken();
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the remainder of a tokenized string
|
||||
*
|
||||
* @param tk String that is partially tokenized.
|
||||
* @return The remainder
|
||||
*/
|
||||
String getRemainder(StringTokenizer tk)
|
||||
{
|
||||
String str = "";
|
||||
if (tk.hasMoreTokens())
|
||||
str = tk.nextToken();
|
||||
while (tk.hasMoreTokens()) {
|
||||
str += " " + tk.nextToken();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ public class RequestHandler implements Runnable {
|
|||
this.clientSocket.close();
|
||||
log.trace("closed client socket");
|
||||
} catch (Throwable localThrowable) {
|
||||
ExceptionLog.getExceptionStackTrace(localThrowable);
|
||||
log.error(ExceptionLog.getExceptionStackTrace(localThrowable));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import org.bench4q.share.models.master.ScriptModel;
|
|||
import org.junit.Test;
|
||||
|
||||
public class RecordScriptControllerTest extends TestBase {
|
||||
private static final int RECORD_TIME = 600000;
|
||||
private static final int RECORD_TIME = 60000;
|
||||
private final String SCRIPT_URL = TestBase.BASE_URL + "/RecordScript";
|
||||
|
||||
public OperateScriptServerResponseModel startRecord() throws IOException,
|
||||
|
|
Loading…
Reference in New Issue