Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
changed a log
Browse files Browse the repository at this point in the history
error page on null responses
  • Loading branch information
globalworming committed Jan 26, 2015
1 parent 6385bcc commit 07b73c1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
72 changes: 39 additions & 33 deletions sahi-core/src/main/java/net/sf/sahi/RemoteRequestProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ public boolean verify(String urlHostName, SSLSession session) {
}

public HttpResponse processHttp(HttpRequest requestFromBrowser) {
return processHttp(requestFromBrowser, true);
}

public HttpResponse processHttp(HttpRequest requestFromBrowser, boolean modify) {
try {
Session session = requestFromBrowser.session();
ThreadLocalMap.put("session", session);
Expand Down Expand Up @@ -144,37 +140,43 @@ public HttpResponse processHttp(HttpRequest requestFromBrowser, boolean modify)
logger.warn("Returning CannotConnectResponse for: " + urlStr);
logger.debug(Utils.getStackTraceString(uhe));
}

if (response == null || responseCode == -1) {
logger.warn("No response or response code not set");
response = getNoConnectionResponse(requestFromBrowser);
}

if (responseCode != 204 && responseCode != 304) {
String contentTypeHeader = response.contentTypeHeader();
boolean downloadContentType = isDownloadContentType(contentTypeHeader);
boolean attachment = response.isAttachment();

String fileName = null;
boolean contentDispositionForcesDownload = false;
boolean attachment;
String contentTypeHeader;
String contentDisposition;

contentTypeHeader = response.contentTypeHeader();
attachment = response.isAttachment();
contentDisposition = response.getLastSetValueOfHeader("Content-Disposition");

if (fileName == null) fileName = requestFromBrowser.fileName();
boolean downloadContentType = isDownloadContentType(contentTypeHeader);
String fileName = requestFromBrowser.fileName();

boolean downloadURL = isDownloadURL(urlStr);
logger.debug("downloadURL = " + downloadURL);
logger.debug("response.isAttachment() = " + attachment);
logger.debug("fileName = " + fileName);
logger.debug("contentTypeHeader = " + contentTypeHeader);
logger.debug("downloadContentType = " + downloadContentType);
logger.debug("Content-Disposition=" + response.getLastSetValueOfHeader("Content-Disposition"));
if (responseCode == 200
&& (downloadContentType ||
contentDispositionForcesDownload ||
downloadURL)) {
logger.debug("Content-Disposition=" + contentDisposition);
if (responseCode == 200 && (downloadContentType || downloadURL)) {
StringBuilder sb = new StringBuilder();
sb.append("\n-- Calling downloadFile --\n");
sb.append(requestFromBrowser.url());
sb.append("\ndownloadURL = " + downloadURL);
sb.append("\nresponse.isAttachment() = " + attachment);
sb.append("\nfileName = " + fileName);
sb.append("\ncontentTypeHeader = " + contentTypeHeader);
sb.append("\ndownloadContentType = " + downloadContentType);
sb.append("\nContent-Disposition=" + response.getLastSetValueOfHeader("Content-Disposition"));
sb.append("\ncontentDispositionForcesDownload = " + contentDispositionForcesDownload);
sb.append("\ndownloadURL = ").append(downloadURL);
sb.append("\nresponse.isAttachment() = ").append(attachment);
sb.append("\nfileName = ").append(fileName);
sb.append("\ncontentTypeHeader = ").append(contentTypeHeader);
sb.append("\ndownloadContentType = ").append(downloadContentType);
sb.append("\nContent-Disposition=").append(contentDisposition);
sb.append("\ncontentDispositionForcesDownload = " + false);
sb.append("\n--");
logger.info(sb.toString());
downloadFile(requestFromBrowser, response, fileName);
Expand All @@ -185,7 +187,7 @@ public HttpResponse processHttp(HttpRequest requestFromBrowser, boolean modify)
return new NoContentResponse();
}
}
response = addFilters(requestFromBrowser, modify, response, responseCode);
response = addFilters(requestFromBrowser, response, responseCode);
}
if (responseCode == 204) {
session.set204(true);
Expand Down Expand Up @@ -215,22 +217,14 @@ private HttpResponse getWrappedResponse(HttpResponse response) {
return response;
}

private HttpResponse addFilters(HttpRequest requestFromBrowser, boolean modify, HttpResponse response, int responseCode) {
private HttpResponse addFilters(HttpRequest requestFromBrowser, HttpResponse response, int responseCode) {
if (response instanceof StreamingHttpResponse) {
StreamingHttpResponse streamingResponse = (StreamingHttpResponse) response;
// if (modify && !requestFromBrowser.isExcluded() && !requestFromBrowser.session().isAjaxRedirect(requestFromBrowser.url())) {
// if (logger.isLoggable(Level.FINER)){
// logger.finer("Modifying response with HttpModifiedResponse");
// }
// streamingResponse = new HttpModifiedResponse(streamingResponse, requestFromBrowser.isSSL(), requestFromBrowser
// .fileExtension(), responseCode);
// }
// streamingResponse.addFilter(new TrafficLoggerFilter(TrafficLogger.getLoggerForThread()));
streamingResponse.addFilter(new ChunkedFilter());
return streamingResponse;
} else {
final Session session = requestFromBrowser.session();
if (modify && !requestFromBrowser.isExcluded() && !session.isAjaxRedirect(requestFromBrowser.url())) {
if (!requestFromBrowser.isExcluded() && !session.isAjaxRedirect(requestFromBrowser.url())) {
return new HttpModifiedResponse2(response, requestFromBrowser.isSSL(), requestFromBrowser.fileExtension(), responseCode);
}
}
Expand Down Expand Up @@ -366,6 +360,18 @@ private HttpResponse get5xxResponse(int responseCode, InputStream inputStreamFro
props, false, true);
}

private HttpResponse getNoConnectionResponse(HttpRequest requestFromBrowser) {
Properties props = new Properties();
props.put("time", "" + (new Date()));

String message = "No response for " + requestFromBrowser;
props.put("message", message);

return new HttpFileResponse(
Configuration.getHtdocsRoot() + "spr/cannotConnect.htm",
props, false, true);
}

private String getReqHeaders(HttpURLConnection connection) {
StringBuilder sb = new StringBuilder();
Map<String, List<String>> requestProperties = connection.getRequestProperties();
Expand Down
2 changes: 1 addition & 1 deletion sahi-core/src/main/java/net/sf/sahi/ssl/SSLHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private KeyManager[] wrapKeyManagers(KeyManager[] kma, String domain) {

public KeyManagerFactory getKeyManagerFactoryForRemoteFetch() throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
String fileWithPath = Configuration.getSSLClientCertPath();
logger.info(fileWithPath == null ? "No SSL Client Cert specified" : ("\n----\nSSL Client Cert Path = " + fileWithPath + "\n----"));
if (fileWithPath != null) logger.info("Using SSL Cient Cert path at: " + fileWithPath);
return getKeyManagerFactory(clientCertKeystore, Configuration.getSSLClientCertPassword());
}

Expand Down

0 comments on commit 07b73c1

Please sign in to comment.