Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Attempt to preserve log even when the underlying proxy experiences an…
Browse files Browse the repository at this point in the history
… error.
  • Loading branch information
cburroughs committed Jul 19, 2010
1 parent 3ffe41c commit a1c3e7f
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/main/java/org/browsermob/proxy/BrowserMobProxyHandler.java
Expand Up @@ -133,12 +133,20 @@ private IOStats customProxyPlainTextRequest(URL url, String pathInContext, Strin
proxy_in = http.getErrorStream();

try {
code = http.getResponseCode();
} catch (SSLHandshakeException e) {
throw new RuntimeException("Couldn't establish SSL handshake. Try using trustAllSSLCertificates.\n" + e.getLocalizedMessage(), e);
try {
code = http.getResponseCode();
} catch (SSLHandshakeException e) {
throw new RuntimeException("Couldn't establish SSL handshake. Try using trustAllSSLCertificates.\n" + e.getLocalizedMessage(), e);
}
response.setStatus(code);
response.setReason(http.getResponseMessage());
}
catch (Exception e) {
LOG.fine(e.getMessage(), e);
code = 0;
response.setStatus(code);
response.setReason("ERROR");
}
response.setStatus(code);
response.setReason(http.getResponseMessage());
}

if (proxy_in == null) {
Expand Down Expand Up @@ -182,6 +190,8 @@ private IOStats customProxyPlainTextRequest(URL url, String pathInContext, Strin
protected long proxyPlainTextRequest(URL url, String pathInContext, String pathParams, HttpRequest request, HttpResponse response) throws IOException {
// this is for the control interface, so just do a vanilla proxy and don't simulate bandwidth, track objects, etc
boolean controlRequest = url.getPort() == 8081 && url.getHost().equals("localhost");
Date start = new Date();
HttpObject httpObject = new HttpObject(start, url, request.getMethod());

try {
String urlStr = url.toString();
Expand All @@ -197,8 +207,6 @@ protected long proxyPlainTextRequest(URL url, String pathInContext, String pathP
return -1;
}

Date start = new Date();
HttpObject httpObject = new HttpObject(start, url, request.getMethod());
IOStats stats = customProxyPlainTextRequest(url, pathInContext, pathParams, request, response, controlRequest);

long bytes = 0;
Expand Down Expand Up @@ -230,15 +238,16 @@ protected long proxyPlainTextRequest(URL url, String pathInContext, String pathP
// TODO
}

if (!controlRequest) {
proxyServer.record(httpObject);
}

return bytes;
} catch (Exception e) {
LOG.info("Exception while proxying data", e);
throw new RuntimeException("Exception while proxying data", e);
}
finally {
if (!controlRequest) {
proxyServer.record(httpObject);
}
}
}


Expand Down

0 comments on commit a1c3e7f

Please sign in to comment.