there is a bug in httpcapture
This commit is contained in:
parent
b1422b22a1
commit
e569cb0a0f
|
@ -1,6 +1,5 @@
|
|||
package org.bench4q.master;
|
||||
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
MasterServer masterServer = new MasterServer(8080);
|
||||
|
|
|
@ -57,7 +57,7 @@ public class MasterServer {
|
|||
"classpath*:org/bench4q/master/config/application-context.xml");
|
||||
this.getServer().setHandler(servletContextHandler);
|
||||
this.getServer().start();
|
||||
this.getAgentPoolService().loadAgentPoolFromDB();
|
||||
//this.getAgentPoolService().loadAgentPoolFromDB();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -48,10 +48,9 @@ public class RecordPortController extends BaseController {
|
|||
LocalPort localPort = new LocalPort();
|
||||
localPort.setPort(port);
|
||||
localPort.setInUse(false);
|
||||
if (this.getPortPoolService().getScriptPortPool().put(port, localPort) == null) {
|
||||
return setOrganizePortResponseModel(false,
|
||||
"add to local pool fails 1");
|
||||
}
|
||||
|
||||
this.getPortPoolService().getScriptPortPool().put(port, localPort);
|
||||
|
||||
if (!this.getPortPoolService().addPortToDBPool(port)) {
|
||||
return setOrganizePortResponseModel(false, "add to DB pool fails 2");
|
||||
}
|
||||
|
|
|
@ -67,6 +67,9 @@ public class RecordScriptController extends BaseController {
|
|||
synchronized (PORT_LOCK) {
|
||||
// TODO:
|
||||
LocalPort localPort = this.getPortPoolService().getAPortNotInUse();
|
||||
if (localPort == null) {
|
||||
return returnResponseModel(false, "port is in use!");
|
||||
}
|
||||
this.setPortForRecord(localPort.getPort());
|
||||
localPort.setInUse(true);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ import java.net.URL;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
||||
public class RequestHandler implements Runnable {
|
||||
|
||||
private static final Log log = LogFactory.getLog(RequestHandler.class);
|
||||
|
@ -31,29 +30,25 @@ public class RequestHandler implements Runnable{
|
|||
private ByteArrayOutputStream buffer;
|
||||
private static Object mutex = new Object();
|
||||
|
||||
RequestHandler(ProxyServer proxyServer, Socket s)
|
||||
{
|
||||
RequestHandler(ProxyServer proxyServer, Socket s) {
|
||||
assert (s != null);
|
||||
this.clientSocket = s;
|
||||
this.buffer = new ByteArrayOutputStream();
|
||||
this.proxyServer = proxyServer;
|
||||
}
|
||||
|
||||
private void initClientServerConnections(Socket s)
|
||||
throws Throwable
|
||||
{
|
||||
private void initClientServerConnections(Socket s) throws Throwable {
|
||||
this.clientIn = new BufferedInputStream(s.getInputStream());
|
||||
this.clientOut = s.getOutputStream();
|
||||
try {
|
||||
this.header = new HttpRequestHeader(this.clientIn);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
} catch (IOException e) {
|
||||
log.info("truncated request from browser: " + e.getMessage());
|
||||
throw new Utils.SilentException();
|
||||
}
|
||||
if (!this.header.url.startsWith("http"))
|
||||
throw new Utils.UserException("MaxQ only supports the HTTP protocol.");
|
||||
throw new Utils.UserException(
|
||||
"MaxQ only supports the HTTP protocol.");
|
||||
URL url = new URL(this.header.url);
|
||||
|
||||
Config.ProxySettings proxy = this.config.getProxySettings();
|
||||
|
@ -91,8 +86,7 @@ public class RequestHandler implements Runnable{
|
|||
}
|
||||
|
||||
private String stripProxyInfoFromRequestHeader()
|
||||
throws MalformedURLException
|
||||
{
|
||||
throws MalformedURLException {
|
||||
String res = "";
|
||||
String origUrl = this.header.url;
|
||||
URL url = new URL(origUrl);
|
||||
|
@ -102,12 +96,9 @@ public class RequestHandler implements Runnable{
|
|||
return res;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
public void run() {
|
||||
try {
|
||||
try {
|
||||
int rs = this.clientSocket.getReceiveBufferSize();
|
||||
int ss = this.clientSocket.getSendBufferSize();
|
||||
int BUF_SIZE = rs < ss ? ss : rs;
|
||||
|
@ -134,11 +125,9 @@ public class RequestHandler implements Runnable{
|
|||
while (num < this.header.contentLength) {
|
||||
try {
|
||||
len = this.clientIn.read(buf, 0, buf.length);
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
log.info("truncated request from browser: " +
|
||||
e.getMessage());
|
||||
} catch (SocketException e) {
|
||||
log.info("truncated request from browser: "
|
||||
+ e.getMessage());
|
||||
throw new Utils.SilentException();
|
||||
}
|
||||
if (len == 0)
|
||||
|
@ -160,36 +149,31 @@ public class RequestHandler implements Runnable{
|
|||
|
||||
this.serverSocket.shutdownOutput();
|
||||
|
||||
synchronized (mutex)
|
||||
{
|
||||
synchronized (mutex) {
|
||||
this.proxyServer.processRequest(this.header, requestBody);
|
||||
log.trace("processed request");
|
||||
|
||||
this.buffer.reset();
|
||||
int len;
|
||||
while ((len = this.serverIn.read(buf, 0, buf.length)) > 0)
|
||||
{
|
||||
while ((len = this.serverIn.read(buf, 0, buf.length)) > 0) {
|
||||
log.trace("read " + Integer.toString(len));
|
||||
try {
|
||||
this.clientOut.write(buf, 0, len);
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
log.info("browser stopped listening: " +
|
||||
e.getMessage());
|
||||
} catch (SocketException e) {
|
||||
log.info("browser stopped listening: "
|
||||
+ e.getMessage());
|
||||
throw new Utils.SilentException();
|
||||
}
|
||||
this.buffer.write(buf, 0, len);
|
||||
}
|
||||
log.trace("transferred response");
|
||||
|
||||
this.proxyServer.processResponse(this.header, this.buffer.toByteArray());
|
||||
this.proxyServer.processResponse(this.header,
|
||||
this.buffer.toByteArray());
|
||||
log.trace("processed response");
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
} finally {
|
||||
if (this.serverSocket != null) {
|
||||
this.serverSocket.close();
|
||||
log.trace("closed server socket");
|
||||
|
@ -205,9 +189,7 @@ public class RequestHandler implements Runnable{
|
|||
|
||||
this.clientSocket.close();
|
||||
log.trace("closed client socket");
|
||||
}
|
||||
catch (Throwable localThrowable)
|
||||
{
|
||||
} catch (Throwable localThrowable) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue