Skip to content

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

first version, of the Serverlet Debugger

allo226f2c5b2c40
diff --git a/htroot/TestApplet.html b/htroot/TestApplet.html
new file mode 100644
index 000000000..a1f1ca2c5
--- /dev/null
+++ b/htroot/TestApplet.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>YaCy '#[clientname]#': test Applet</title>
+ #%env/templates/metas.template%#
+ </head>
+ <body>
+ #%env/templates/header.template%#
+ <h2>Test Applet</h2>
+ #(mode)#
+ <form action="TestApplet.html" method="POST">
+ <table>
+ <tr>
+ <td>relative Path</td>
+ <td><input type="text" name="url"></td>
+ <td>/yacysearch.html</td>
+ </tr>
+ <tr>
+ <td>Parameters</td>
+ <td><textarea row="10" cols="60" name="arguments"></textarea><td>
+ <td>search=yacy</td>
+ </tr>
+ </table>
+ <input type="submit" value="test" />
+ </form>
+ ::
+ returned Templates:<br />
+ <textarea rows="10" cols="70">#[templates]#</textarea><br />
+ returned Template Structure:<br />
+ <textarea rows="10" cols="70">#[structure]#</textarea><br />
+ returned Text:<br />
+ <textarea rows="10" cols="70">#[text]#</textarea><br />
+ #(/mode)#
+ #%env/templates/footer.template%#
+ </body>
+</html>
diff --git a/htroot/TestApplet.java b/htroot/TestApplet.java
new file mode 100644
index 000000000..bc6b5a258
--- /dev/null
+++ b/htroot/TestApplet.java
@@ -0,0 +1,109 @@
+// TestApplet.java
+// -----------------------
+// (C) 2006 by Alexander Schier
+// part of YACY
+//
+// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Iterator;
+
+import de.anomic.http.httpHeader;
+import de.anomic.http.httpTemplate;
+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;
+
+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");
+ return prop;
+ }
+ serverObjects args=new serverObjects();
+
+ String[] lines=((String)post.get("arguments")).split("\n");
+ String[] pair;
+ for(int i=0;i<lines.length;i++){
+ pair=lines[i].split("=");
+ if(pair.length==2){
+ args.put(pair[0], pair[1]);
+ }
+ }
+
+ prop.put("mode", "1");
+ File templatefile=filehandler.getOverlayedFile((String)post.get("url"));
+ File classfile=filehandler.getOverlayedClass((String)post.get("url"));
+ httpHeader header2=new httpHeader();
+ header2.put("CLIENTIP", "127.0.0.1");
+ header2.put("PATH", (String)post.get("url"));
+ serverObjects tp=null;
+ try {
+ if(classfile==null || !classfile.exists()){
+ prop.put("mode_templates", "classfile does not exist");
+ return prop;
+ }else{
+ tp=(serverObjects)filehandler.invokeServlet(classfile, header2, args);
+ }
+ }
+ catch (IllegalArgumentException e) {}
+ catch (IllegalAccessException e) {}
+ catch (InvocationTargetException e) {}
+ if(tp==null){
+ prop.put("templates", "some error occured.");
+ prop.put("structure", "");
+ prop.put("text", "");
+ return prop;
+ }
+ Iterator it=tp.keySet().iterator();
+ StringBuffer tmp=new StringBuffer();
+ String key="";
+ while(it.hasNext()){
+ key=(String)it.next();
+ tmp.append(key).append("=").append(tp.get(key)).append("\n");
+ }
+ prop.put("mode_templates", tmp.toString());
+ FileInputStream fis=null;
+ try {
+ fis=new FileInputStream(templatefile);
+
+ serverByteBuffer o=new serverByteBuffer();
+ byte[] structure=httpTemplate.writeTemplate(fis, (OutputStream)o, tp, "-UNRESOLVED_PATTERN-".getBytes("UTF-8"));
+ prop.put("mode_structure", structure);
+ prop.put("mode_text", o.toString());
+ return prop;
+ }
+ catch (FileNotFoundException e) {}
+ catch (UnsupportedEncodingException e) {}
+ catch (IOException e) {}
+
+ prop.put("mode_text", "could not finish correctly"); //very informative errormessage
+ return prop;
+
+ }
+
+}
diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java
index 07009bd2d..dd88024cf 100644
--- a/source/de/anomic/http/httpdFileHandler.java
+++ b/source/de/anomic/http/httpdFileHandler.java
@@ -919,7 +919,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
}
}
- private File getOverlayedClass(String path) {
+ public File getOverlayedClass(String path) {
File targetClass;
targetClass=rewriteClassFile(new File(htDefaultPath, path)); //works for default and localized files
if(targetClass == null || !targetClass.exists()){
@@ -929,7 +929,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
return targetClass;
}
- private File getOverlayedFile(String path) {
+ public File getOverlayedFile(String path) {
File targetFile;
targetFile = getLocalizedFile(path);
if (!(targetFile.exists())){
@@ -1002,7 +1002,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
return m;
}
- private Object invokeServlet(File targetClass, httpHeader request, serverObjects args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
+ public Object invokeServlet(File targetClass, httpHeader request, serverObjects args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
Object result;
if (safeServletsMode) synchronized (switchboard) {
result = rewriteMethod(targetClass).invoke(null, new Object[] {request, args, switchboard});