From 24e25e1141200c1e747894855c702c396b8fe31f Mon Sep 17 00:00:00 2001 From: orbiter Date: Thu, 9 Aug 2007 21:58:38 +0000 Subject: [PATCH] enhanced SSI server-side support: - SSIs may now refer to servlets, not only files - calling a servlet, the servlet/SSI engine is called recursively - SSIs now work also for non-chunked-encoding supporting clients This will support the new search page functionality, to show search results dynamically without using javascript. To test this method, a test page has been added http://localhost:8080/ssitest.html ..calls dynamicalls 3 servlets, which produce some delays during their execution please verify that you can see the result step-by-step on your browser To implement this feature, some refactoring had been taken place, mostly code had been made static and will execute faster. git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4037 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/TestApplet.java | 7 +- htroot/ssitest.html | 3 + htroot/ssitestservlet.html | 4 + htroot/ssitestservlet.java | 55 +++ source/de/anomic/http/httpSSI.java | 78 +++-- source/de/anomic/http/httpd.java | 32 +- .../de/anomic/http/httpdAbstractHandler.java | 79 ----- source/de/anomic/http/httpdFileHandler.java | 108 +++--- source/de/anomic/http/httpdHandler.java | 157 --------- source/de/anomic/http/httpdProxyHandler.java | 331 +++++++++--------- source/de/anomic/soap/httpdSoapHandler.java | 8 +- source/yacy.java | 4 +- 12 files changed, 337 insertions(+), 529 deletions(-) create mode 100644 htroot/ssitestservlet.html create mode 100644 htroot/ssitestservlet.java delete mode 100644 source/de/anomic/http/httpdAbstractHandler.java delete mode 100644 source/de/anomic/http/httpdHandler.java diff --git a/htroot/TestApplet.java b/htroot/TestApplet.java index 921af4bbd..afa43fd91 100644 --- a/htroot/TestApplet.java +++ b/htroot/TestApplet.java @@ -23,7 +23,6 @@ import java.util.Iterator; import de.anomic.http.httpHeader; import de.anomic.http.httpdFileHandler; -import de.anomic.plasma.plasmaSwitchboard; import de.anomic.server.serverByteBuffer; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; @@ -31,8 +30,6 @@ import de.anomic.server.serverSwitch; public class TestApplet { public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) { serverObjects prop = new serverObjects(); - plasmaSwitchboard sb = (plasmaSwitchboard) env; - httpdFileHandler filehandler=new httpdFileHandler(sb); if(post== null || !post.containsKey("url")){ prop.put("mode", "0"); @@ -51,7 +48,7 @@ public class TestApplet { prop.put("mode", "1"); //File templatefile=filehandler.getOverlayedFile((String)post.get("url")); - File classfile=filehandler.getOverlayedClass((String)post.get("url")); + File classfile = httpdFileHandler.getOverlayedClass((String)post.get("url")); httpHeader header2=new httpHeader(); header2.put("CLIENTIP", "127.0.0.1"); header2.put("PATH", post.get("url")); @@ -61,7 +58,7 @@ public class TestApplet { prop.put("mode_templates", "classfile does not exist"); return prop; } - tp=(serverObjects)filehandler.invokeServlet(classfile, header2, args); + tp=(serverObjects) httpdFileHandler.invokeServlet(classfile, header2, args); } catch (IllegalArgumentException e) {} catch (IllegalAccessException e) {} diff --git a/htroot/ssitest.html b/htroot/ssitest.html index 3656e977d..6446e2d22 100644 --- a/htroot/ssitest.html +++ b/htroot/ssitest.html @@ -7,5 +7,8 @@

Dynamisches HTML mit Server Side Includes

+ + + \ No newline at end of file diff --git a/htroot/ssitestservlet.html b/htroot/ssitestservlet.html new file mode 100644 index 000000000..00d2300cf --- /dev/null +++ b/htroot/ssitestservlet.html @@ -0,0 +1,4 @@ +

+testservlet ok nach #[delay]# millisekunden Pause.
+start = #[start]#, stop = #[stop]# +

\ No newline at end of file diff --git a/htroot/ssitestservlet.java b/htroot/ssitestservlet.java new file mode 100644 index 000000000..54e70802f --- /dev/null +++ b/htroot/ssitestservlet.java @@ -0,0 +1,55 @@ +// ssitestservlet.java +// -------------------- +// (C) 2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany +// first published 09.08.2007 on http://yacy.net +// +// This is a part of YaCy, a peer-to-peer based web search engine +// +// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $ +// $LastChangedRevision: 1986 $ +// $LastChangedBy: orbiter $ +// +// LICENSE +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import de.anomic.http.httpHeader; +import de.anomic.server.serverObjects; +import de.anomic.server.serverSwitch; + +public class ssitestservlet { + + public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) { + + //plasmaSwitchboard sb = (plasmaSwitchboard) env; + serverObjects prop = new serverObjects(); + int delay = 0; + long start = System.currentTimeMillis(); + + if (post != null) { + delay = post.getInt("delay", 1000); + } + + // make a delay to see how the ssi loads and displays this page + try {Thread.sleep(delay);} catch (InterruptedException e) {} + + prop.put("delay", delay); + prop.put("start", start); + prop.put("stop", System.currentTimeMillis()); + + return prop; + } + +} diff --git a/source/de/anomic/http/httpSSI.java b/source/de/anomic/http/httpSSI.java index 265ae3e39..920e02f7b 100644 --- a/source/de/anomic/http/httpSSI.java +++ b/source/de/anomic/http/httpSSI.java @@ -27,50 +27,70 @@ package de.anomic.http; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; +import java.io.OutputStream; +import java.util.Properties; import de.anomic.server.serverByteBuffer; public class httpSSI { - public static void writeSSI(File referenceFile, serverByteBuffer in, httpChunkedOutputStream out) throws IOException { - writeSSI(referenceFile, in, 0, out); + public static void writeSSI(serverByteBuffer in, OutputStream out) throws IOException { + writeSSI(in, 0, out); } - public static void writeSSI(File referenceFile, serverByteBuffer in, int start, httpChunkedOutputStream out) throws IOException { - int p = in.indexOf("".getBytes(), start + 10); - assert q >= 0; - parseSSI(referenceFile, in, start, q + 3 - start, out); - writeSSI(referenceFile, in, start + q + 3, out); - } else if (p > 0) { + public static void writeSSI(serverByteBuffer in, int off, OutputStream out) throws IOException { + int p = in.indexOf("".getBytes(), p + 10); - out.write(in, start, p - start); - parseSSI(referenceFile, in, start + p, q + 3 - start - p, out); - writeSSI(referenceFile, in, start + q + 3, out); + if (out instanceof httpChunkedOutputStream) { + ((httpChunkedOutputStream) out).write(in, off, p - off); + } else { + out.write(in.getBytes(off, p - off)); + } + parseSSI(in, p, q + 3 - p, out); + writeSSI(in, q + 3, out); } else /* p < 0 */ { - out.write(in, start, in.length() - start); + if (out instanceof httpChunkedOutputStream) { + ((httpChunkedOutputStream) out).write(in, off, in.length() - off); + } else { + out.write(in.getBytes(off, in.length() - off)); + } } } - private static void parseSSI(File referenceFile, serverByteBuffer in, int start, int length, httpChunkedOutputStream out) { - if (in.startsWith("