1。script name can't be null
2.get the charset from html 3.close record server when web page closed
This commit is contained in:
parent
86a52df435
commit
ed62f1d8f0
|
@ -1,5 +1,6 @@
|
|||
package org.bench4q.recorder.httpcapture.generator;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ResponseHeader {
|
||||
|
@ -18,6 +19,7 @@ public class ResponseHeader {
|
|||
private String contentEncoding;
|
||||
private int contentLength;
|
||||
private String transferEncoding;
|
||||
private Charset contentCharset;
|
||||
|
||||
public int getRespCode() {
|
||||
return respCode;
|
||||
|
@ -81,4 +83,12 @@ public class ResponseHeader {
|
|||
public void setTransferEncoding(String transferEncoding) {
|
||||
this.transferEncoding = transferEncoding;
|
||||
}
|
||||
|
||||
public Charset getContentCharset() {
|
||||
return contentCharset;
|
||||
}
|
||||
|
||||
public void setContentCharset(Charset charset) {
|
||||
this.contentCharset = charset;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.nio.charset.Charset;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.recorder.httpcapture.ResponseModel;
|
||||
import org.jsoup.Jsoup;
|
||||
|
||||
public class ResponseParser {
|
||||
private Logger logger = Logger.getLogger(ResponseParser.class);
|
||||
|
@ -80,7 +81,7 @@ public class ResponseParser {
|
|||
}
|
||||
|
||||
private String parseContentType(HttpURLConnection httpURLConnection) {
|
||||
|
||||
|
||||
String ret = null;
|
||||
String value = httpURLConnection.getHeaderField("Content-Type");
|
||||
int pos;
|
||||
|
@ -96,14 +97,11 @@ public class ResponseParser {
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
private String parseTransferEncoding(HttpURLConnection httpURLConnection) {
|
||||
|
||||
|
||||
return httpURLConnection.getHeaderField("Transfer-Encoding");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void parseResponseBody() {
|
||||
ContentDecoder contentDecoder = ContentDecoder.createDecoder(this
|
||||
.getResponseHeader().getContentEncoding());
|
||||
|
@ -119,25 +117,54 @@ public class ResponseParser {
|
|||
try {
|
||||
charset = Charset.forName(this.getResponseHeader().getCharset());
|
||||
} catch (Exception e) {
|
||||
charset = Charset.forName("utf-8");
|
||||
charset = getCharsetFromContent(contentBodyAfterDecoded);
|
||||
if(charset == null){
|
||||
charset = Charset.forName("utf-8");
|
||||
}
|
||||
this.getResponseHeader().setContentCharset(charset);
|
||||
logger.error(e, e);
|
||||
}
|
||||
this.setResponseBody(new String(contentBodyAfterDecoded, charset));
|
||||
}
|
||||
|
||||
public byte[] encodeCoent(String responseBody){
|
||||
|
||||
private Charset getCharsetFromContent(byte[] content) {
|
||||
String contentString = new String(content,
|
||||
Charset.forName("iso-8859-1")).toLowerCase();
|
||||
int pos = contentString.indexOf("charset=");
|
||||
if (pos == -1)
|
||||
return null;
|
||||
pos += 8;
|
||||
char tempChar = contentString.charAt(pos);
|
||||
StringBuilder sBuilder = new StringBuilder();
|
||||
if (tempChar == '"') {
|
||||
pos++;
|
||||
}
|
||||
while ((tempChar = contentString.charAt(pos)) != '"') {
|
||||
sBuilder.append(tempChar);
|
||||
pos++;
|
||||
}
|
||||
try {
|
||||
return Charset.forName(sBuilder.toString());
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
charset = this.getResponseHeader().getContentCharset();
|
||||
if(charset == null)
|
||||
charset = Charset.forName("utf-8");
|
||||
logger.error(e, e);
|
||||
}
|
||||
byte[] responseBytes = responseBody.getBytes(charset);
|
||||
responseBytes = contentEncoder.encoderContent(responseBytes);
|
||||
|
||||
|
||||
return responseBytes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,9 +118,9 @@ body {
|
|||
<tr>
|
||||
<td>
|
||||
<button id="createNewScript"
|
||||
class="btn btn-primary" onclick="startServer()" type="submit">
|
||||
class="btn btn-primary" type="submit" onclick="startServer()">
|
||||
<fmt:message key="script_jsp_recordScript" />
|
||||
</button> <a href="createScript.jsp"><button id="createScript"
|
||||
</button><a href="createScript.jsp"><button id="createScript"
|
||||
class="btn btn-primary" onclick="#" type="submit">
|
||||
<fmt:message key="home-createScript" />
|
||||
</button> </a>
|
||||
|
|
|
@ -112,6 +112,10 @@ function testRecordProxy() {
|
|||
|
||||
function saveScript() {
|
||||
var scriptName = document.getElementsByName("scriptname")[0].value;
|
||||
if (scriptName == undefined || scriptName == "") {
|
||||
information("need a script name!");
|
||||
return;
|
||||
}
|
||||
$.post("saveScriptRecorded", {
|
||||
scriptName : scriptName,
|
||||
port : server.port,
|
||||
|
@ -126,5 +130,7 @@ function saveScript() {
|
|||
$('#fileName').hide();
|
||||
}
|
||||
loadScript(table, 2);
|
||||
}).error(function(){
|
||||
information("failed to connect server");
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,7 +2,12 @@ $('.btn-setting').click(function(e) {
|
|||
e.preventDefault();
|
||||
$('#myModal').modal('show');
|
||||
});
|
||||
|
||||
window.onbeforeunload = function() {
|
||||
if(startRecordingSuccess){
|
||||
stopRecording();
|
||||
}else if(startServerSuccess)
|
||||
stopServer();
|
||||
}
|
||||
function dismiss(container){
|
||||
$(container).modal('hide');
|
||||
if(startRecordingSuccess){
|
||||
|
|
|
@ -33,7 +33,7 @@ function submitScript(pages,usePlugins,formData) {
|
|||
|
||||
var scriptName = $("#scriptName").val();
|
||||
if (scriptName == undefined || scriptName == "") {
|
||||
information("need a script name!")
|
||||
information("need a script name!");
|
||||
return;
|
||||
}
|
||||
var runScenarioModel = new RunScenarioModel(0,usePlugins,new Array(),pages);
|
||||
|
|
Loading…
Reference in New Issue