Author: metskem
Date: Mon Sep 10 19:47:19 2012
New Revision: 1383085
URL: http://svn.apache.org/viewvc?rev=1383085&view=rev
Log:
2012-09-10 Harry Metske <[email protected]>
* 2.9.0-incubating-12
* rewrote TestContainer to jetty version 7
* upgraded to selenium-server-standalone-2.25.0.jar
Added:
incubator/jspwiki/trunk/tests/org/apache/wiki/web/StreamRedirector.java
(with props)
Modified:
incubator/jspwiki/trunk/.classpath
incubator/jspwiki/trunk/ChangeLog
incubator/jspwiki/trunk/build.properties
incubator/jspwiki/trunk/build.xml
incubator/jspwiki/trunk/src/org/apache/wiki/Release.java
incubator/jspwiki/trunk/tests/org/apache/wiki/auth/authorize/JDBCGroupDatabaseTest.java
incubator/jspwiki/trunk/tests/org/apache/wiki/auth/user/JDBCUserDatabaseTest.java
incubator/jspwiki/trunk/tests/org/apache/wiki/web/TestContainer.java
Modified: incubator/jspwiki/trunk/.classpath
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/.classpath?rev=1383085&r1=1383084&r2=1383085&view=diff
==============================================================================
--- incubator/jspwiki/trunk/.classpath (original)
+++ incubator/jspwiki/trunk/.classpath Mon Sep 10 19:47:19 2012
@@ -1,47 +1,44 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry excluding="**/package.html|images/|webdocs/|wikipages/"
kind="src" output="build" path="src"/>
- <classpathentry excluding="build/|etc/|lib/|libs-opt/|reports/"
kind="src" output="tests/build" path="tests"/>
- <classpathentry kind="lib" path="lib/commons-lang-2.6.jar"/>
- <classpathentry kind="lib" path="lib/commons-logging-api-1.0.4.jar"/>
- <classpathentry kind="lib" path="lib/ecs-1.4.2.jar"/>
- <classpathentry kind="lib" path="lib/jdom-1.0.jar"/>
- <classpathentry kind="lib" path="lib/log4j-1.2.14.jar"/>
- <classpathentry kind="lib" path="lib/akismet-java-1.02.jar"/>
- <classpathentry kind="lib" path="lib/jsonrpc-1.0.jar"
sourcepath="/Users/jalkanen/Java/json-rpc-java-1.0/src"/>
- <classpathentry kind="lib" path="lib/xmlrpc-2.0.1.jar"
sourcepath="/Users/jalkanen/Java/xmlrpc-2.0.1/xmlrpc-2.0.1-sources.jar"/>
- <classpathentry kind="lib" path="lib/jrcs-diff-0.4.2.jar"/>
- <classpathentry kind="lib" path="tests/lib/xercesImpl-2.6.2.jar"/>
- <classpathentry kind="lib" path="lib/sandler-0.5.jar"/>
- <classpathentry kind="lib" path="lib/oscache-2.3.jar"
sourcepath="/Users/jalkanen/Java/oscache-2.3/src/java"/>
- <classpathentry kind="lib" path="lib/oro-2.0.7.jar"/>
- <classpathentry kind="lib" path="lib/nekohtml-0.9.4.jar"/>
- <classpathentry kind="lib" path="lib/lucene-core-3.6.0.jar"/>
- <classpathentry kind="lib" path="tests/lib/junit-3.8.2.jar"/>
- <classpathentry kind="lib" path="tests/etc"/>
- <classpathentry kind="lib" path="lib/jaxen-1.1-beta-6.jar"/>
- <classpathentry kind="lib" path="tests/lib/xml-apis-1.0.b2.jar"/>
- <classpathentry kind="lib" path="lib/lucene-highlighter-3.6.0.jar"/>
- <classpathentry kind="lib" path="lib/mail-1.4.jar"/>
- <classpathentry kind="lib" path="lib/activation-1.1.jar"/>
- <classpathentry kind="lib" path="etc/i18n"/>
- <classpathentry kind="lib" path="lib/freshcookies-security-0.60.jar"/>
- <classpathentry kind="lib" path="lib/commons-httpclient-3.0.1.jar"/>
- <classpathentry kind="lib" path="lib/jstl-1.1.2.jar"/>
- <classpathentry kind="lib" path="lib/standard-1.1.2.jar"/>
- <classpathentry kind="lib" path="lib/commons-fileupload-1.2.1.jar"/>
- <classpathentry kind="lib" path="lib/commons-codec-1.3.jar"/>
- <classpathentry kind="lib" path="lib/servlet-api-2.4.jar"/>
- <classpathentry kind="lib" path="lib/jsp-api-2.0.jar"/>
- <classpathentry kind="lib" path="tests/lib/commons-el-1.0.jar"/>
- <classpathentry kind="lib" path="tests/lib/hsqldb-1.8.0.10.jar"/>
- <classpathentry kind="lib" path="tests/lib/jasper-compiler-5.5.25.jar"/>
- <classpathentry kind="lib" path="tests/lib/jasper-runtime-5.5.25.jar"/>
- <classpathentry kind="lib" path="tests/lib/jetty-jmx-5.1.14.jar"/>
- <classpathentry kind="lib" path="tests/lib/jetty-plus-5.1.14.jar"/>
- <classpathentry kind="lib" path="tests/lib/jetty-servlet-5.1.14.jar"/>
- <classpathentry kind="lib" path="tests/lib/stripes-1.5.7.jar"/>
- <classpathentry kind="lib"
path="tests/lib/selenium-server-1.0-beta1.jar"/>
- <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="output" path="classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry excluding="**/package.html|images/|webdocs/|wikipages/"
kind="src" output="build" path="src"/>
+ <classpathentry excluding="build/|etc/|lib/|libs-opt/|reports/"
kind="src" output="tests/build" path="tests"/>
+ <classpathentry kind="lib" path="lib/commons-lang-2.6.jar"/>
+ <classpathentry kind="lib" path="lib/commons-logging-api-1.0.4.jar"/>
+ <classpathentry kind="lib" path="lib/ecs-1.4.2.jar"/>
+ <classpathentry kind="lib" path="lib/jdom-1.0.jar"/>
+ <classpathentry kind="lib" path="lib/log4j-1.2.14.jar"/>
+ <classpathentry kind="lib" path="lib/akismet-java-1.02.jar"/>
+ <classpathentry kind="lib" path="lib/jsonrpc-1.0.jar"
sourcepath="/Users/jalkanen/Java/json-rpc-java-1.0/src"/>
+ <classpathentry kind="lib" path="lib/xmlrpc-2.0.1.jar"
sourcepath="/Users/jalkanen/Java/xmlrpc-2.0.1/xmlrpc-2.0.1-sources.jar"/>
+ <classpathentry kind="lib" path="tests/lib/xercesImpl-2.6.2.jar"/>
+ <classpathentry kind="lib" path="lib/sandler-0.5.jar"/>
+ <classpathentry kind="lib" path="lib/oscache-2.3.jar"
sourcepath="/Users/jalkanen/Java/oscache-2.3/src/java"/>
+ <classpathentry kind="lib" path="lib/oro-2.0.7.jar"/>
+ <classpathentry kind="lib" path="lib/nekohtml-0.9.4.jar"/>
+ <classpathentry kind="lib" path="lib/lucene-core-3.6.0.jar"/>
+ <classpathentry kind="lib" path="tests/lib/junit-3.8.2.jar"/>
+ <classpathentry kind="lib" path="tests/etc"/>
+ <classpathentry kind="lib" path="lib/jaxen-1.1-beta-6.jar"/>
+ <classpathentry kind="lib" path="tests/lib/xml-apis-1.0.b2.jar"/>
+ <classpathentry kind="lib" path="lib/lucene-highlighter-3.6.0.jar"/>
+ <classpathentry kind="lib" path="lib/mail-1.4.jar"/>
+ <classpathentry kind="lib" path="lib/activation-1.1.jar"/>
+ <classpathentry kind="lib" path="etc/i18n"/>
+ <classpathentry kind="lib" path="lib/freshcookies-security-0.60.jar"/>
+ <classpathentry kind="lib" path="lib/commons-httpclient-3.0.1.jar"/>
+ <classpathentry kind="lib" path="lib/commons-fileupload-1.2.1.jar"/>
+ <classpathentry kind="lib" path="lib/commons-codec-1.3.jar"/>
+ <classpathentry kind="lib" path="lib/servlet-api-2.4.jar"/>
+ <classpathentry kind="lib" path="lib/jsp-api-2.0.jar"/>
+ <classpathentry kind="lib" path="lib/jrcs-diff-0.4.2.jar"/>
+ <classpathentry kind="lib" path="lib/jstl-1.1.2.jar"/>
+ <classpathentry kind="lib" path="tests/lib/commons-el-1.0.jar"/>
+ <classpathentry kind="lib" path="tests/lib/hsqldb-1.8.0.10.jar"/>
+ <classpathentry kind="lib" path="tests/lib/jasper-compiler-5.5.25.jar"/>
+ <classpathentry kind="lib" path="tests/lib/jasper-runtime-5.5.25.jar"/>
+ <classpathentry kind="lib" path="tests/lib/stripes-1.5.7.jar"/>
+ <classpathentry kind="lib"
path="tests/lib/selenium-server-standalone-2.25.0.jar"/>
+ <classpathentry kind="lib"
path="tests/lib/jetty-all-7.6.5.v20120716.jar"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="classes"/>
+</classpath>
Modified: incubator/jspwiki/trunk/ChangeLog
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=1383085&r1=1383084&r2=1383085&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Mon Sep 10 19:47:19 2012
@@ -1,3 +1,11 @@
+2012-09-10 Harry Metske <[email protected]>
+
+ * 2.9.0-incubating-12
+
+ * rewrote TestContainer to jetty version 7
+
+ * upgraded to selenium-server-standalone-2.25.0.jar
+
2012-09-06 Juan Pablo Santos (juanpablo AT apache DOT org)
* 2.9.0-incubating-11
Modified: incubator/jspwiki/trunk/build.properties
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/build.properties?rev=1383085&r1=1383084&r2=1383085&view=diff
==============================================================================
--- incubator/jspwiki/trunk/build.properties (original)
+++ incubator/jspwiki/trunk/build.properties Mon Sep 10 19:47:19 2012
@@ -52,9 +52,10 @@ jdbc.user.password=password
#
# Which browser to use?
-webtests.browser=*safari
+#webtests.browser=*safari
# if you run firefox, and it is not in your PATH, you can specify this :
-#webtests.browser=*firefox /usr/lib/firefox/firefox-2-bin
+#webtests.browser=*firefox /usr/bin/firefox
+webtests.browser=*firefox /usr/lib/firefox/firefox
# For generating API diffs (you must have DependencyFinder installed)
#dependencyfinder.dir=../lib/DependencyFinder
Modified: incubator/jspwiki/trunk/build.xml
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/build.xml?rev=1383085&r1=1383084&r2=1383085&view=diff
==============================================================================
--- incubator/jspwiki/trunk/build.xml (original)
+++ incubator/jspwiki/trunk/build.xml Mon Sep 10 19:47:19 2012
@@ -117,9 +117,8 @@
<property name="webtests.reports" value="${basedir}/tests/reports/selenium"
/>
<property name="webtests.build" value="tests/build/webtests" />
<property name="webtests.port" value="10024" />
- <property name="webtests.shutdown" value="19041" />
<property name="webtests.temp" value="${java.io.tmpdir}/webtests" />
- <property name="selenium-rc.jar"
value="tests/lib/selenium-server-1.0-beta1.jar" />
+ <property name="selenium-rc.jar"
value="tests/lib/selenium-server-standalone-2.25.0.jar" />
<!-- The place where the javadocs are created -->
@@ -264,12 +263,9 @@
<get-element to-file="${libs.tests}/hsqldb-1.8.0.10.jar"
url="${central.url}/org/hsqldb/hsqldb/1.8.0.10/hsqldb-1.8.0.10.jar" />
<get-element to-file="${libs.tests}/jasper-compiler-5.5.25.jar"
url="${svn.repository}/libs/${libs.tests}/jasper-compiler-5.5.25.jar" />
<get-element to-file="${libs.tests}/jasper-runtime-5.5.25.jar"
url="${svn.repository}/libs/${libs.tests}/jasper-runtime-5.5.25.jar" />
- <get-element to-file="${libs.tests}/jetty-jmx-5.1.14.jar"
url="${svn.repository}/libs/${libs.tests}/jetty-jmx-5.1.14.jar" />
- <get-element to-file="${libs.tests}/jetty-plus-5.1.14.jar"
url="${svn.repository}/libs/${libs.tests}/jetty-plus-5.1.14.jar" />
- <get-element to-file="${libs.tests}/jetty-servlet-5.1.14.jar"
url="${svn.repository}/libs/${libs.tests}/jetty-servlet-5.1.14.jar" />
+ <get-element to-file="${libs.tests}/jetty-all-7.6.5.v20120716.jar"
url="${svn.repository}/libs/${libs.tests}/jetty-all-7.6.5.v20120716.jar" />
<get-element to-file="${libs.tests}/junit-3.8.2.jar"
url="${central.url}/junit/junit/3.8.2/junit-3.8.2.jar" />
- <get-element
to-file="${libs.tests}/selenium-java-client-driver-1.0-beta1.jar"
url="${svn.repository}/libs/${libs.tests}/selenium-java-client-driver-1.0-beta1.jar"
/>
- <get-element to-file="${libs.tests}/selenium-server-1.0-beta1.jar"
url="${svn.repository}/libs/${libs.tests}/selenium-server-1.0-beta1.jar" />
+ <get-element
to-file="${libs.tests}/selenium-server-standalone-2.25.0.jar"
url="${svn.repository}/libs/${libs.tests}/selenium-server-standalone-2.25.0.jar"
/>
<get-element to-file="${libs.tests}/stripes-1.5.7.jar"
url="${central.url}/net/sourceforge/stripes/stripes/1.5.7/stripes-1.5.7.jar" />
<get-element to-file="${libs.tests}/xercesImpl-2.6.2.jar"
url="${central.url}/xerces/xercesImpl/2.6.2/xercesImpl-2.6.2.jar" />
<get-element to-file="${libs.tests}/xml-apis-1.0.b2.jar"
url="${central.url}/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar" />
@@ -437,6 +433,7 @@
<available file="${jarfile}"/>
</condition>
<antcall target="buildjar" /> <!-- needed to avoid circular references
when invoking tests target -->
+ <!-- comment out the following line if you only want to run the
webtests and not the normal tests -->
<antcall target="tests" />
</target>
@@ -1066,15 +1063,20 @@ If all of the tests ran successfully, th
<macrodef name="webtest-exec">
<attribute name="context"/>
<sequential>
- <!-- If already running, shut down the embedded Jetty server by pinging
the shutdown port -->
+ <!-- If already running, shut down the embedded Jetty server by sending
the shutdown command -->
<echo message="Shutting down Jetty (if it is up)."/>
- <get src="http://localhost:${webtests.shutdown}/"
dest="${webtests.temp}/shutdown.log"
+ <get src="http://localhost:${webtests.port}/GO_AWAY/"
dest="${webtests.temp}/shutdown.log"
ignoreerrors="true" verbose="true" />
- <sleep seconds="2"/>
+ <sleep seconds="3"/>
<!-- Start Jetty with our test context -->
<echo message="Starting Jetty."/>
- <java classname="org.apache.wiki.web.TestContainer" fork="true"
spawn="true">
+ <java classname="org.apache.wiki.web.StreamRedirector" fork="true"
spawn="true">
+ <!--java classname="org.apache.wiki.web.TestContainer" fork="true"
spawn="true"-->
+ <arg value="org.apache.wiki.web.TestContainer"/>
+ <arg value="/tmp/jetty-redirectedoutput.log"/>
+ <!--jvmarg value="-Dlog4j.debug=yesplease"/--> <!-- to enable log4j
debugging-->
+ <jvmarg value="-Dorg.eclipse.jetty.LEVEL=info"/> <!-- to enable jetty
debugging-->
<classpath>
<path refid="path.tests" />
</classpath>
Modified: incubator/jspwiki/trunk/src/org/apache/wiki/Release.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/org/apache/wiki/Release.java?rev=1383085&r1=1383084&r2=1383085&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/org/apache/wiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/org/apache/wiki/Release.java Mon Sep 10
19:47:19 2012
@@ -77,7 +77,7 @@ public final class Release
* <p>
* If the build identifier is empty, it is not added.
*/
- public static final String BUILD = "11";
+ public static final String BUILD = "12";
/**
* This is the generic version string you should use
Modified:
incubator/jspwiki/trunk/tests/org/apache/wiki/auth/authorize/JDBCGroupDatabaseTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/org/apache/wiki/auth/authorize/JDBCGroupDatabaseTest.java?rev=1383085&r1=1383084&r2=1383085&view=diff
==============================================================================
---
incubator/jspwiki/trunk/tests/org/apache/wiki/auth/authorize/JDBCGroupDatabaseTest.java
(original)
+++
incubator/jspwiki/trunk/tests/org/apache/wiki/auth/authorize/JDBCGroupDatabaseTest.java
Mon Sep 10 19:47:19 2012
@@ -28,6 +28,7 @@ import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
+import javax.naming.NameAlreadyBoundException;
import javax.sql.DataSource;
import junit.framework.TestCase;
@@ -65,7 +66,14 @@ public class JDBCGroupDatabaseTest exten
// Set up the mock JNDI initial context
TestJNDIContext.initialize();
Context initCtx = new InitialContext();
- initCtx.bind( "java:comp/env", new TestJNDIContext() );
+ try
+ {
+ initCtx.bind( "java:comp/env", new TestJNDIContext() );
+ }
+ catch( NameAlreadyBoundException e )
+ {
+ // ignore
+ }
Context ctx = (Context) initCtx.lookup( "java:comp/env" );
DataSource ds = new TestJDBCDataSource( new File( "build.properties" )
);
ctx.bind( JDBCGroupDatabase.DEFAULT_GROUPDB_DATASOURCE, ds );
Modified:
incubator/jspwiki/trunk/tests/org/apache/wiki/auth/user/JDBCUserDatabaseTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/org/apache/wiki/auth/user/JDBCUserDatabaseTest.java?rev=1383085&r1=1383084&r2=1383085&view=diff
==============================================================================
---
incubator/jspwiki/trunk/tests/org/apache/wiki/auth/user/JDBCUserDatabaseTest.java
(original)
+++
incubator/jspwiki/trunk/tests/org/apache/wiki/auth/user/JDBCUserDatabaseTest.java
Mon Sep 10 19:47:19 2012
@@ -32,6 +32,7 @@ import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
+import javax.naming.NameAlreadyBoundException;
import javax.sql.DataSource;
import junit.framework.TestCase;
@@ -89,7 +90,14 @@ public class JDBCUserDatabaseTest extend
// Set up the mock JNDI initial context
TestJNDIContext.initialize();
Context initCtx = new InitialContext();
- initCtx.bind( "java:comp/env", new TestJNDIContext() );
+ try
+ {
+ initCtx.bind( "java:comp/env", new TestJNDIContext() );
+ }
+ catch( NameAlreadyBoundException e )
+ {
+ // ignore
+ }
Context ctx = (Context) initCtx.lookup( "java:comp/env" );
DataSource ds = new TestJDBCDataSource( new File( "build.properties" )
);
ctx.bind( JDBCUserDatabase.DEFAULT_DB_JNDI_NAME, ds );
Added: incubator/jspwiki/trunk/tests/org/apache/wiki/web/StreamRedirector.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/org/apache/wiki/web/StreamRedirector.java?rev=1383085&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/org/apache/wiki/web/StreamRedirector.java
(added)
+++ incubator/jspwiki/trunk/tests/org/apache/wiki/web/StreamRedirector.java Mon
Sep 10 19:47:19 2012
@@ -0,0 +1,48 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.wiki.web;
+
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+
+/**
+ * Catching the stdout and stderr when running under a spawned ant java task
is difficult, therefore we wrap the TestContainer with this
+ * class and redirect the output to files.
+ *
+ */
+public class StreamRedirector
+{
+ public static void main( String[] args ) throws Exception
+ {
+ String mainClass = args[0];
+ String logFile = args[1];
+
+ // redirect the streams
+ PrintStream outfile = new PrintStream( new FileOutputStream( logFile )
);
+ System.setErr( outfile );
+ System.setOut( outfile );
+
+ // call the TestContainer after stripping of the first two args and
redirecting the output.
+ String[] strippedArgs = new String[args.length - 2];
+ System.arraycopy( args, 2, strippedArgs, 0, strippedArgs.length );
+ Class.forName( mainClass ).getMethod( "main", String[].class ).invoke(
null, (Object) strippedArgs );
+ }
+}
Propchange:
incubator/jspwiki/trunk/tests/org/apache/wiki/web/StreamRedirector.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/jspwiki/trunk/tests/org/apache/wiki/web/TestContainer.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/org/apache/wiki/web/TestContainer.java?rev=1383085&r1=1383084&r2=1383085&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/org/apache/wiki/web/TestContainer.java
(original)
+++ incubator/jspwiki/trunk/tests/org/apache/wiki/web/TestContainer.java Mon
Sep 10 19:47:19 2012
@@ -23,31 +23,39 @@ package org.apache.wiki.web;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
+import java.util.Hashtable;
import java.util.Map;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
+import org.apache.wiki.auth.Users;
+import org.eclipse.jetty.jndi.InitialContextFactory;
+import org.eclipse.jetty.jndi.NamingContext;
+import org.eclipse.jetty.plus.jndi.Resource;
+import org.eclipse.jetty.security.ConstraintSecurityHandler;
+import org.eclipse.jetty.security.HashLoginService;
+import org.eclipse.jetty.security.SecurityHandler;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.bio.SocketConnector;
+import org.eclipse.jetty.server.handler.*;
+import org.eclipse.jetty.util.security.Password;
+import org.eclipse.jetty.webapp.WebAppContext;
import org.hsqldb.jdbc.jdbcDataSource;
-import org.mortbay.http.*;
-import org.mortbay.http.handler.SecurityHandler;
-import org.mortbay.jetty.plus.DefaultDataSourceService;
-import org.mortbay.jetty.plus.Server;
-import org.mortbay.jetty.servlet.WebApplicationContext;
-import org.mortbay.jndi.ContextFactory;
-import org.mortbay.jndi.InitialContextFactory;
-import org.mortbay.jndi.NamingContext;
-import org.mortbay.jndi.Util;
-import org.mortbay.util.Password;
-import org.apache.wiki.auth.Users;
/**
* Lightweight wrapper that starts and stops an embedded Jetty server on a
* hard-coded port {@link #HTTP_PORT}. The server can be shut down by sending a
- * request to the shutdown port, which is hard-coded to {@link #SHUTDOWN_PORT}.
+ * request containing the hard-coded string {@link #SHUTDOWN_CMD}.
*/
public class TestContainer
{
@@ -58,25 +66,18 @@ public class TestContainer
*/
public static final int HTTP_PORT = 10024;
- /**
- * High port that listens for shutdown requests.
- */
- public static final int SHUTDOWN_PORT = 19041;
+ public static final String SHUTDOWN_CMD = "/GO_AWAY";
public static final String INITIAL_CONTEXT_FACTORY =
"java.naming.factory.initial";
-
- // Minimum and maximum number of jetty threads
- public static final int MIN_JETTY_THREADS = 1;
-
- public static final int MAX_JETTY_THREADS = 1024;
-
- public static final int DEFAULT_JETTY_THREADS = 512;
-
- /** Number of jetty threads for the server. */
- private static int jettyThreads = DEFAULT_JETTY_THREADS;
+ public static final String INITIAL_CONTEXT_FACTORY_JETTY =
"org.eclipse.jetty.jndi.InitialContextFactory";
private static final Logger log = Logger.getLogger( TestContainer.class );
+
+ private static Resource userDB = null;
+ private static Resource groupDB = null;
+ private static ContextHandlerCollection handlerCollection = new
ContextHandlerCollection();
+
/**
* Starts up a test server for a particular web application on the
specified
* port (or default if no port was specified).
@@ -101,14 +102,12 @@ public class TestContainer
{
String context = app.getKey();
String path = app.getValue();
- log.info( "Adding context " + context + " at path " + path );
+ log.error( "Adding context " + context + " at path " + path );
container.addWebApp( context, path );
}
- // Create the DataSource service
- DefaultDataSourceService dss = new DefaultDataSourceService();
- dss.setName( "DataSourceService" );
-
+ handlerCollection.addHandler( new DefaultHandler() );
+
// Create the connection pool
jdbcDataSource cpds = new jdbcDataSource();
cpds.setDatabase( "jdbc:hsqldb:hsql://localhost/jspwiki" );
@@ -117,31 +116,42 @@ public class TestContainer
cpds.setPassword( null );
// Configure and bind DataSource to JNDI for user database
- dss.addDataSource( "jdbc/UserDatabase", cpds );
- container.server.addService( dss );
- dss.getDataSource( "jdbc/UserDatabase" );
+ userDB = new Resource( "jdbc/UserDatabase", cpds );
+ log.error( "Configured datasource " + userDB);
// Configure and bind DataSource to JNDI for group database
- dss.addDataSource( "jdbc/GroupDatabase", cpds );
- container.server.addService( dss );
- dss.getDataSource( "jdbc/GroupDatabase" );
-
- System.out.println( "Configured datasources." );
+ groupDB = new Resource( "jdbc/GroupDatabase", cpds );
+ log.error( "Configured datasource " + groupDB);
+
// Start the server
try
{
- System.out.println( "Starting up test container." );
+ log.error( "Starting up test container." );
+ container.server.setHandler( handlerCollection );
+ Handler[] currentHandlers = container.server.getHandlers();
+ log.error( "dumping current handlers" );
+ for( Handler handler : currentHandlers )
+ {
+ if( handler instanceof HandlerCollection )
+ {
+ Handler[] collection = ((HandlerCollection)
handler).getHandlers();
+ for( Handler h : collection )
+ {
+ log.error( "handler: " + h );
+ }
+ }
+ }
container.start();
}
catch( Throwable t )
{
+ // userDB.unbindENC();
+ // groupDB.unbindENC();
t.printStackTrace();
- System.err.println( t.getMessage() );
+ log.error( t.getMessage() );
System.exit( 1 );
}
- System.out.println( "Started." );
-
}
private static Map<String, String> extractApps( String[] args )
@@ -195,11 +205,12 @@ public class TestContainer
String contextFactoryClass = System.getProperty(
INITIAL_CONTEXT_FACTORY );
if ( contextFactoryClass == null )
{
- System.setProperty( INITIAL_CONTEXT_FACTORY,
"org.mortbay.jndi.InitialContextFactory" );
- ContextFactory.setNameParser( new
InitialContextFactory.DefaultParser() );
- log.info( "No JNDI context factory found; using
org.mortbay.jndi.InitialContextFactory." );
+ System.setProperty( INITIAL_CONTEXT_FACTORY,
INITIAL_CONTEXT_FACTORY_JETTY );
+// ContextFactory.setNameParser( new
InitialContextFactory.DefaultParser() );
+ log.error( "No JNDI context factory found; using
org.eclipse.jndi.InitialContextFactory." );
+ contextFactoryClass = INITIAL_CONTEXT_FACTORY_JETTY;
}
- log.info( "Initialized JNDI with context factory class=" +
contextFactoryClass + "." );
+ log.error( "Initialized JNDI with context factory class=" +
contextFactoryClass + "." );
// Bind the "java:comp" namespace if not bound already
Context initCtx = new InitialContext();
@@ -209,67 +220,56 @@ public class TestContainer
}
catch ( NameNotFoundException e )
{
- Util.bind( initCtx, "java:comp", new NamingContext() );
- NamingContext compCtx = (NamingContext) initCtx.lookup(
"java:comp" );
- compCtx.setNameParser( new InitialContextFactory.DefaultParser() );
- log.info( "No JNDI java:comp namespace found; creating it," );
- // Context envCtx = compCtx.createSubcontext( "env" );
- // System.out.println( envCtx );
+ initCtx.bind( "java:comp", new NamingContext(new Hashtable<String,
Object>(), "java:comp", null, new InitialContextFactory.DefaultParser()) );
+ log.error( "No JNDI java:comp namespace found; creating it," );
}
log.info( "Initialized JNDI java:comp namespace.=" +
contextFactoryClass );
// Initialize new Jetty server
log.info( "Creating new test container." );
- System.setProperty( "org.mortbay.xml.XmlParser.NotValidating", "true"
);
+ System.setProperty( "org.eclipse.xml.XmlParser.NotValidating", "true"
);
server = new Server();
server.setStopAtShutdown( true );
// Create HTTP listener
- SocketListener listener = new SocketListener();
- listener.setHost( "localhost" );
- listener.setMaxIdleTimeMs( 60000 );
- listener.setMaxThreads( jettyThreads );
- listener.setPort( HTTP_PORT );
- server.addListener( listener );
- log.info( "...added HTTP listener for port " + HTTP_PORT );
-
- // Create shutdown listener
- listener = new SocketListener();
- listener.setHost( "localhost" );
- listener.setMaxThreads( jettyThreads );
- listener.setPort( SHUTDOWN_PORT );
- listener.setHttpHandler( new ShutdownHandler() );
- server.addListener( listener );
- log.info( "...added shutdown listener for port " + SHUTDOWN_PORT );
-
- // Set the default users and roles for the realm (note that realm name
*must* match web.xml <realm-name>
- HashUserRealm realm = new HashUserRealm( "JSPWikiRealm" );
- realm.put( Users.ADMIN, new Password( Users.ADMIN_PASS ) );
- realm.addUserToRole( Users.ADMIN, "Authenticated" );
- realm.addUserToRole( Users.ADMIN, "Admin" );
- realm.put( Users.JANNE, new Password( Users.JANNE_PASS ) );
- realm.addUserToRole( Users.JANNE, "Authenticated" );
- server.addRealm( realm );
- }
+ SocketConnector connector = new SocketConnector();
+ connector.setHost( "localhost" );
+ connector.setPort( HTTP_PORT );
+ connector.setMaxIdleTime( 60000 );
+
+ server.setConnectors( new Connector[] {connector} );
+ log.info( "added HTTP listener for port " + HTTP_PORT );
+
+ // add the shutdown handler
+ ContextHandler shutDownContextHandler = new
ContextHandler(SHUTDOWN_CMD);
+ shutDownContextHandler.setHandler( new ShutdownHandler());
+ handlerCollection.addHandler( shutDownContextHandler );
+ }
/**
* Configures a test web application
*
* @param m_context the name of the web m_context; must start with "/"
* @param path the file path for the WAR file, or expanded WAR directory
- * @return the configured web application
* @throws IOException
*/
- public WebApplicationContext addWebApp( String context, String path )
throws IOException
+ public void addWebApp( String context, String path ) throws IOException
{
- WebApplicationContext webapp = server.addWebApplication( context, path
);
- log.info( "Adding test webapp " + context + " for path " + path );
+ // Set the default users and roles for the realm (note that realm name
*must* match web.xml <realm-name>
+ HashLoginService loginService = new HashLoginService( "JSPWikiRealm" );
+ loginService.putUser( Users.ADMIN, new Password(Users.ADMIN_PASS), new
String[] {"Authenticated", "Admin"} );
+ loginService.putUser( Users.JANNE, new Password(Users.JANNE_PASS), new
String[] {"Authenticated"} );
+
+ WebAppContext webAppContext = new WebAppContext(path, context);
+
+ // Add a security handler.
+ SecurityHandler csh = new ConstraintSecurityHandler();
+ csh.setLoginService( loginService );
+ webAppContext.setSecurityHandler( csh );
- // Add a security handler for any constraints enabled by web.xml
- SecurityHandler sh = new SecurityHandler();
- webapp.addHandler( sh );
+ log.error( "Adding webapp " + context + " for path " + path );
+ handlerCollection.addHandler( webAppContext );
- return webapp;
}
/**
@@ -277,8 +277,9 @@ public class TestContainer
*/
public void start() throws Exception
{
- System.setProperty( "org.mortbay.http.HttpRequest.maxFormContentSize",
"0" );
+ System.setProperty( "org.eclipse.http.HttpRequest.maxFormContentSize",
"0" );
server.start();
+ log.error("jetty server started");
}
/**
@@ -289,88 +290,34 @@ public class TestContainer
try
{
server.stop();
+ log.error("jetty server stopped");
}
- catch( InterruptedException ex )
+ catch( Exception ex )
{
throw new RuntimeException( ex );
}
}
-
+
+
+
/**
- * HTTP Handler that shuts down the Jetty server if a request is received
on
- * the shutdown port..
+ * Handler that shuts down the Jetty server if a request is received
containing the shutdown string {@link TestContainer#SHUTDOWN_CMD} .
*/
- public static final class ShutdownHandler implements HttpHandler
- {
- private static final long serialVersionUID = -7785141243907081919L;
-
- private HttpContext m_context;
-
- /**
- * Returns the HttpContext used to initialize this handler.
- */
- public HttpContext getHttpContext()
- {
- return m_context;
- }
-
- /**
- * No-op method that always returns a generic description of the
- * shutdown handler.
- */
- public String getName()
- {
- return "Shutdown HTTP handler.";
- }
-
- /**
- * Intercepts the HTTP request and shuts down the server instantly.
- */
- public void handle( String arg0, String arg1, HttpRequest arg2,
HttpResponse arg3 ) throws HttpException, IOException
- {
- System.exit(0);
-// System.err.println( "Shutdown request detected." );
-// try
-// {
-// m_server.stop( false );
-// }
-// catch( InterruptedException e )
-// {
-// e.printStackTrace();
-// throw new HttpException(
HttpResponse.__500_Internal_Server_Error, e.getMessage() );
-// }
- }
- /**
- * No-op method that sets a reference to the HttpContext supplied to
the
- * initialize method.
- */
- public void initialize( HttpContext context )
- {
- m_context = context;
- }
-
- /**
- * No-op method that always returns <code>true</code>.
- */
- public boolean isStarted()
- {
- return true;
- }
-
- /**
- * No-op method that does nothing.
- */
- public void start() throws Exception
- {
- }
+ public static final class ShutdownHandler extends AbstractHandler
+ {
- /**
- * No-op method that does nothing.
- */
- public void stop() throws InterruptedException
+ public void handle( String target, Request baseRequest,
HttpServletRequest request, HttpServletResponse response )
+
throws IOException,
+
ServletException
{
+ if( request.getRequestURI().indexOf( SHUTDOWN_CMD ) != -1 )
+ {
+ log.error( "stop cmd received, shutting down server" );
+ System.exit( 0 );
+ } else {
+ log.error("ignoring request " + request.getRequestURI());
+ }
}
}
-
}