This commit is contained in:
coderfengyun 2014-09-01 11:07:48 +08:00
commit 37622fc0ee
13 changed files with 172 additions and 20 deletions

File diff suppressed because one or more lines are too long

View File

@ -216,7 +216,7 @@ public class RequestHandler implements Runnable {
sb.append(changeList2String(headerMap.get(key)) + "\r\n");
continue;
}
if (key.equals("Transfer-Encoding") || key.equals("Content-Encoding")) {
if (key.equals("Transfer-Encoding")) {
continue;
}
sb.append(key + ": " + changeList2String(headerMap.get(key))

View File

@ -344,7 +344,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
dealWithHtmlResponse(header, responseParser);
doParseRequest(header, requestBody);
response.setResponse(doParseHtmlContent(responseParser.getResponseBody(), header.url));
response.setResponse(responseParser.encodeCoent(doParseHtmlContent(responseParser.getResponseBody(), header.url)));
setStruts(new String(response.getResponse()).toLowerCase().indexOf(
"org.apache.struts.taglib.html.token") > 0);
doEndTransaction();
@ -444,7 +444,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
* @param rootUrl
* @return new response body
*/
public abstract byte[] doParseHtmlContent(String responseBody, String rootUrl);
public abstract String doParseHtmlContent(String responseBody, String rootUrl);
public abstract void doHeaders(HeaderValue[] paramArrayOfHeaderValue);

View File

@ -2,6 +2,7 @@ package org.bench4q.recorder.httpcapture.generator;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
@ -200,11 +201,11 @@ public class Bench4qCodeGenerator extends AbstractCodeGenerator {
}
@Override
public byte[] doParseHtmlContent(String responseBody, String rootUrl) {
public String doParseHtmlContent(String responseBody, String rootUrl) {
int htmlStart = responseBody.indexOf("<html");
int bodyStart = responseBody.indexOf("<body");
if (htmlStart == -1 || bodyStart == -1) {
return responseBody.getBytes();
return responseBody;
}
int htmlEnd = responseBody.indexOf("</html>");
int bodyEnd = responseBody.indexOf("</body>");
@ -216,7 +217,7 @@ public class Bench4qCodeGenerator extends AbstractCodeGenerator {
responseBody += "</html>";
htmlEnd = responseBody.indexOf("</html>");
}
return parseDocument(rootUrl, responseBody, htmlStart, htmlEnd).getBytes();
return parseDocument(rootUrl, responseBody, htmlStart, htmlEnd);
}
private String parseDocument(String rootUrl, String responseContent,

View File

@ -0,0 +1,25 @@
package org.bench4q.recorder.httpcapture.generator;
import org.apache.log4j.Logger;
public class ContentEncoder {
protected Logger logger = Logger.getLogger(ContentEncoder.class);
protected ContentEncoder() {
}
public static ContentEncoder createEncoder(String encodeType) {
if (encodeType == null) {
return new ContentEncoder();
}
if (encodeType.equalsIgnoreCase("gzip")) {
return new GzipEncoder();
} else {
return new ContentEncoder();
}
}
public byte[] encoderContent(byte[] content){
return content;
}
}

View File

@ -6,6 +6,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class GzipDecoder extends ContentDecoder {
@ -25,7 +26,6 @@ public class GzipDecoder extends ContentDecoder {
return null;
}
}
public String decodeContent(InputStream inputStream, Charset charset){
InputStream is = inputStream;
GZIPInputStream gzin;

View File

@ -0,0 +1,25 @@
package org.bench4q.recorder.httpcapture.generator;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;
public class GzipEncoder extends ContentEncoder{
public byte[] encoderContent(byte[] content){
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream);
gzipOutputStream.write(content, 0, content.length);
gzipOutputStream.finish();
gzipOutputStream.flush();
gzipOutputStream.close();
return outputStream.toByteArray();
} catch (IOException e) {
logger.error("decodeContent", e);
return null;
}
}
}

View File

@ -183,4 +183,17 @@ public class ResponseParser {
}
this.setResponseBody(new String(contentBodyAfterDecoded, charset));
}
public byte[] encodeCoent(String responseBody){
ContentEncoder contentEncoder = ContentEncoder.createEncoder(this
.getResponseHeader().getContentEncoding());
Charset charset = null;
try {
charset = Charset.forName(this.getResponseHeader().getCharset());
} catch (Exception e) {
charset = Charset.forName("utf-8");
logger.error(e, e);
}
return contentEncoder.encoderContent(responseBody.getBytes(charset));
}
}

View File

@ -1,6 +1,7 @@
package org.bench4q.recorder;
import java.io.IOException;
import java.nio.charset.Charset;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
@ -52,12 +53,12 @@ public class Test_RequestHandler {
get.addRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
get.addRequestHeader("Accept-Language", "zh-CN,zh;q=0.8");
get.addRequestHeader("Cache-Control", "max-age=0");
// get.addRequestHeader("Accept-Encoding", "gzip,deflate,sdch");
// get.addRequestHeader("Cookie","__zpspc=188.1.1409195668.1409195668.1%234%7C%7C%7C%7C%7C; BDUSS=E45eXUtamxkY2JUbS12ZjFUSmJPbWdmUU13Ri1ZVHlzWWx2S1B3YXRxRVNUU1pVQVFBQUFBJCQAAAAAAAAAAAEAAAAOfOsxd29uYW5ndW8xMQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABLA~lMSwP5Tc; cflag=65535%3A1; BD_UPN=123143; BD_HOME=1; BAIDUID=12B697CB05FD662D2CA4416FF118FCD8:FG=1; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; BD_CK_SAM=1; H_PS_PSSID=8307_5228_1466_7800_8235_8488_8057_6506_6017_8251_7607_7799_8483_8457_8167_8509_8435_8382_8114; BD_HOME=1");
get.addRequestHeader("Accept-Encoding", "gzip,deflate,sdch");
get.addRequestHeader("Cookie","__zpspc=188.1.1409195668.1409195668.1%234%7C%7C%7C%7C%7C; BDUSS=E45eXUtamxkY2JUbS12ZjFUSmJPbWdmUU13Ri1ZVHlzWWx2S1B3YXRxRVNUU1pVQVFBQUFBJCQAAAAAAAAAAAEAAAAOfOsxd29uYW5ndW8xMQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABLA~lMSwP5Tc; cflag=65535%3A1; BD_UPN=123143; BD_HOME=1; BAIDUID=12B697CB05FD662D2CA4416FF118FCD8:FG=1; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; BD_CK_SAM=1; H_PS_PSSID=8307_5228_1466_7800_8235_8488_8057_6506_6017_8251_7607_7799_8483_8457_8167_8509_8435_8382_8114; BD_HOME=1");
int statusCode = this.httpClient.executeMethod(get);
System.out.println(statusCode);
System.out.println(get.getResponseBodyAsString());
System.out.println(new String(get.getResponseBody(),Charset.forName("utf-8")));
} catch (URIException e) {
// TODO Auto-generated catch block
e.printStackTrace();

View File

@ -29,7 +29,7 @@ public class ScriptMessager extends MasterMessager {
public OperateScriptServerResponseModel startRecording(
String accessToken, String port, String fileNameUUID) {
String url = this.getBaseUrl() + "/startRecording";
String url = this.getBaseUrl() + "/startScriptRecording";
Map<String, String> params = new HashMap<String, String>();
params.put("port", port);
params.put("fileNameUUID", fileNameUUID);

View File

@ -207,7 +207,7 @@ body {
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary"
onClick="javascript:window.location.href='http://www.baidu.com/'" id="startRecording">
onClick="startRecording()" id="startRecording">
<fmt:message key="startRecording" />
</button>
<button type="button" class="btn btn-primary"

View File

@ -132,7 +132,7 @@ function testRecordProxy() {
if (data.success) {
$('#mySecondModal').modal('hide');
$('#myThirdModal').modal('show');
server = data.server;
//server = data.server;
$('#scriptInfo3').text(
$.i18n.prop("RecordingScript"));
//$('#startServer').attr('disabled', true);
@ -145,7 +145,7 @@ function testRecordProxy() {
}
function startRecording() {
//if (server != null) {
if (server != null) {
$.post("startRecording", {
port : server.port,
scriptRecordUUID : server.fileName
@ -157,10 +157,10 @@ function startRecording() {
$('#startRecording').attr('disabled', true);
}
else {
window.location.href='http://www.baidu.com/';
window.open('http://www.baidu.com/')
}
}, "json");
// } else {
// $('#scriptInfo3').text("record script server has not started");
// }
} else {
$('#scriptInfo3').text("record script server has not started");
}
}

View File

@ -123,7 +123,7 @@ EditorFactory.prototype.createFile = function(label, name, required, size, id, v
var file = document.createElement("input");
$(file).attr("type", "file");
if(required == "true"){
$(field).attr("required", "required");
$(file).attr("required", "required");
}
// $(field).attr("maxlength", size);
$(fileEditor).append(fieldName.outerHTML + file.outerHTML);