Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

*) Bugfix for: - 302 redirection Problem on Amazon Server - Wrong References in proxymsg/error.html See: http://www.yacy-forum.de/viewtopic.php?t=515

thelic7d294d8d4f6
diff --git a/htroot/proxymsg/error.html b/htroot/proxymsg/error.html
index d0eed2b3c..dfc1a087a 100644
--- a/htroot/proxymsg/error.html
+++ b/htroot/proxymsg/error.html
@@ -7,7 +7,10 @@
<meta name="keywords" content="yacy proxy error message">
<meta name="description" content="YaCy proxy error message">
<meta name="copyright" content="Michael Christen">
+
+<base href="http://#[host]#:#[port]#/">
<link rel="stylesheet" media="all" href="/env/style.css">
+
<!-- (C), Architecture and Realisation: Michael Peter Christen; Contact: mc <at> anomic.de -->
</head>
@@ -32,7 +35,7 @@
</table>
<br><br>
-<table border="0" cellspacing="0" cellpadding="0" style="margin-left: auto; margin-right: auto; margin-top: 5em;">
+<table border="0" cellspacing="0" cellpadding="0" style="margin-left: 5em; margin-right: 5em; margin-top: 5em;">
<tr>
<td>
<p>
@@ -66,7 +69,7 @@
::
<tr>
<td>
- <code><font color="red">#[stacktrace]#</font></code>
+ <font color="red"><code>#[stacktrace]#</code></font>
</td>
</tr>
#(/printStackTrace)#
diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.java
index b597f582e..a1e1b0e87 100644
--- a/source/de/anomic/http/httpd.java
+++ b/source/de/anomic/http/httpd.java
@@ -1086,23 +1086,27 @@ public final class httpd implements serverHandler {
// set rewrite values
serverObjects tp = new serverObjects();
+
+ tp.put("host", serverCore.publicIP().getHostAddress());
+ tp.put("port", switchboard.getConfig("port", "8080"));
+
tp.put("errorMessageType", errorcase);
tp.put("httpStatus", Integer.toString(httpStatusCode) + " " + httpStatusText);
tp.put("requestMethod", conProp.getProperty(httpd.CONNECTION_PROP_METHOD));
tp.put("requestURL", urlString);
- tp.put("detailedErrorMsg",(detailedErrorMsg != null) ? detailedErrorMsg : "");
+ tp.put("errorMessageType_detailedErrorMsg",(detailedErrorMsg != null) ? detailedErrorMsg : "");
// building the stacktrace
if (stackTrace != null) {
serverByteBuffer errorMsg = new serverByteBuffer();
- errorMsg.append("Exception occurred:\r\n")
+ errorMsg.append("Exception occurred:\r\n\r\n")
.append(stackTrace.toString())
.append("\r\n")
- .append("[TRACE: ");
+ .append("TRACE: ");
stackTrace.printStackTrace(new PrintStream(errorMsg));
- errorMsg.write(("]\r\n").getBytes());
+ errorMsg.write(("\r\n").getBytes());
tp.put("printStackTrace",1);
- tp.put("printStackTrace_stacktrace",errorMsg.toString());
+ tp.put("printStackTrace_stacktrace",errorMsg.toString().replaceAll("\n","<br>"));
} else {
tp.put("printStackTrace",0);
}
diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java
index 6e11b888b..51012c1b0 100644
--- a/source/de/anomic/http/httpdFileHandler.java
+++ b/source/de/anomic/http/httpdFileHandler.java
@@ -343,7 +343,6 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
}
Date filedate;
- long filelength;
File rc = null;
try {
// locate the file
@@ -481,15 +480,34 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
httpd.sendRespondError(conProp,out,3,404,"File not Found",null,null);
//textMessage(out, 404, "404 File not Found\r\n"); // would be a possible vuln to return original the original path
}
- } catch (Exception e) {
- //textMessage(out, 503, "Exception with query: " + path + "; '" + e.toString() + ":" + e.getMessage() + "'\r\n");
- //e.printStackTrace();
- this.theLogger.logError("ERROR: Exception with query: " + path + "; '" + e.toString() + ":" + e.getMessage() + "'");
- }
- out.flush();
- if (!(requestHeader.get(httpHeader.CONNECTION, "close").equals("keep-alive"))) {
- // wait a little time until everything closes so that clients can read from the streams/sockets
- try {Thread.currentThread().sleep(1000);} catch (InterruptedException e) {}
+ } catch (Exception e) {
+ if (e instanceof InterruptedException) {
+ this.theLogger.logInfo("Interruption detected while processing query: " + path + "; '" + e.toString() + ":" + e.getMessage() + "'");
+ if (!conProp.containsKey(httpd.CONNECTION_PROP_PROXY_RESPOND_HEADER)) {
+ httpd.sendRespondError(conProp,out, 4, 503, null, "Exception with query: " + path + "; Service unavailable because of server shutdown.",e);
+ } else {
+ conProp.put(httpd.CONNECTION_PROP_PERSISTENT,"close");
+ }
+ } else {
+ if (e.getMessage().startsWith("Broken pipe") || e.getMessage().startsWith("Connection reset by peer")) {
+ // client closed the connection, so we just end silently
+ this.theLogger.logInfo("Client unexpectedly closed connection while processing query: " + path + "; '" + e.toString() + ":" + e.getMessage() + "'");
+ conProp.put(httpd.CONNECTION_PROP_PERSISTENT,"close");
+ } else {
+ this.theLogger.logError("ERROR: Exception with query: " + path + "; '" + e.toString() + ":" + e.getMessage() + "'");
+ if (!conProp.containsKey(httpd.CONNECTION_PROP_PROXY_RESPOND_HEADER)) {
+ httpd.sendRespondError(conProp,out, 4, 503, null, "Exception with query: " + path + "; '" + e.toString() + ":" + e.getMessage() + "'",e);
+ } else {
+ conProp.put(httpd.CONNECTION_PROP_PERSISTENT,"close");
+ }
+ }
+ }
+ } finally {
+ try {out.flush();}catch (Exception e) {}
+ if (!(requestHeader.get(httpHeader.CONNECTION, "close").equals("keep-alive"))) {
+ // wait a little time until everything closes so that clients can read from the streams/sockets
+ try {Thread.currentThread().sleep(1000);} catch (InterruptedException e) {}
+ }
}
}
diff --git a/source/de/anomic/http/httpdProxyHandler.java b/source/de/anomic/http/httpdProxyHandler.java
index 99ae7ed8e..c273bb2d8 100644
--- a/source/de/anomic/http/httpdProxyHandler.java
+++ b/source/de/anomic/http/httpdProxyHandler.java
@@ -598,7 +598,14 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
// request has been placed and result has been returned. work off response
try {
- httpd.sendRespondHeader(conProp,respond,httpVer,Integer.parseInt(res.status.split(" ")[0]),res.status.split(" ")[1],res.responseHeader);
+ String[] resStatus = res.status.split(" ");
+ httpd.sendRespondHeader(
+ conProp,
+ respond,
+ httpVer,
+ Integer.parseInt((resStatus.length > 0) ? resStatus[0]:"503"),
+ (resStatus.length > 1) ? resStatus[1] : null,
+ res.responseHeader);
String storeError;
if ((storeError = cacheEntry.shallStoreCache()) == null) {