Update of /cvsroot/jwebunit/jWebUnit/test/net/sourceforge/jwebunit/util
In directory
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31101/test/net/sourceforge/jwebunit/util
Modified Files:
JettySetup.java
Added Files:
HtmlHelper.java ParamsServlet.java
Log Message:
Using a servlet to replace params.jsp, so that the tests are faster and do not
need ant.jar.
--- NEW FILE: HtmlHelper.java ---
package net.sourceforge.jwebunit.util;
public abstract class HtmlHelper {
private static final String VAR_TITLE = "title not set";
public static final String START =
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
"<%@ page language=\"java\" contentType=\"text/html; charset=UTF-8\"\n"
+
" pageEncoding=\"UTF-8\"%>\n" +
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" +
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
"<head>\n" +
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"
/>\n" +
"<title>" + VAR_TITLE + "</title>\n" +
"</head>\n" +
"<body>\n";
public static final String END =
"</body>\n" +
"</html>\n";
public static String getStart(String title) {
return START.replaceFirst(VAR_TITLE, title);
}
public static String getEnd() {
return END;
}
public static String getLinkParagraph(String id, String url) {
return "<p><a id=\"" + id + "\" href=\"" + url + "\">return</a></p>\n";
}
}
--- NEW FILE: ParamsServlet.java ---
package net.sourceforge.jwebunit.util;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ParamsServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.write(HtmlHelper.getStart("Submitted parameters"));
out.write("<h1>Submitted parameters</h1>\n<p>Params are:");
/* Prints POST and GET parameters as name=value1[,value2...] separated
with spaces */
java.util.Enumeration params = request.getParameterNames();
for (; params.hasMoreElements() ;) {
String p = params.nextElement().toString();
String[] v = request.getParameterValues(p);
out.write(" " + p + "=");
int n = v.length;
if (n > 0) {
out.write(v[0]);
for (int i = 1; i < n; i++) {
out.write("," + v[i]);
}
}
}
out.write(" \n");
out.write(HtmlHelper.getLinkParagraph("return",
request.getHeader("Referer")));
out.write(HtmlHelper.getEnd());
}
}
Index: JettySetup.java
===================================================================
RCS file:
/cvsroot/jwebunit/jWebUnit/test/net/sourceforge/jwebunit/util/JettySetup.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** JettySetup.java 12 Jul 2004 21:46:09 -0000 1.1
--- JettySetup.java 2 Jan 2006 16:31:26 -0000 1.2
***************
*** 9,12 ****
--- 9,13 ----
import org.mortbay.jetty.Server;
+ import org.mortbay.jetty.servlet.ServletHandler;
import org.mortbay.util.MultiException;
***************
*** 49,53 ****
}
jettyServer = new Server(jettyConfig);
!
jettyServer.start();
} catch (IOException e) {
--- 50,54 ----
}
jettyServer = new Server(jettyConfig);
! addCustomHandlers(jettyServer);
jettyServer.start();
} catch (IOException e) {
***************
*** 61,64 ****
--- 62,78 ----
/**
+ * Adds any extra handlers programmatically
+ * @param jettyServer2
+ * @deprecated remove this method if the webapp seems to work
+ */
+ private void addCustomHandlers(Server jettyServer) {
+ // Use web.xml instead so that the servlet can have the same path as
the jsp
+ //ServletHandler handler= new ServletHandler();
+ //handler.addServlet("Params","/params.do",
+ // ParamsServlet.class.getName());
+ //jettyServer.getContext("/").addHandler(handler);
+ }
+
+ /**
* Stops the Jetty server.
*
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Jwebunit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development