epugh 2004/05/25 14:20:42
Modified: src/java/org/apache/turbine Turbine.java
src/java/org/apache/turbine/util TurbineConfig.java
xdocs changes.xml
src/test/org/apache/turbine/test BaseTestCase.java
xdocs/howto migrate-from-2_2-howto.xml
Added: src/test/org/apache/turbine TurbineTest.java
Log:
Refactored Turbine's initialization of ServerData to not require a RunData object
first.
Revision Changes Path
1.49 +14 -47 jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java
Index: Turbine.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/Turbine.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- Turbine.java 7 May 2004 21:53:09 -0000 1.48
+++ Turbine.java 25 May 2004 21:20:41 -0000 1.49
@@ -526,32 +526,6 @@
}
/**
- * Initializes the services which need <code>RunData</code> to
- * initialize themselves (post startup).
- *
- * @param data The first <code>GET</code> request.
- */
- public final void init(RunData data)
- {
- synchronized (Turbine.class)
- {
- if (firstDoGet)
- {
- // All we want to do here is save some servlet
- // information so that services and processes
- // that don't have direct access to a RunData
- // object can still know something about
- // the servlet environment.
- saveServletInfo(data);
-
- // Mark that we're done.
- firstDoGet = false;
- log.info("Turbine: first Request successful");
- }
- }
- }
-
- /**
* Return the current configuration with all keys included
*
* @return a Configuration Object
@@ -722,7 +696,19 @@
// themselves.
if (firstDoGet)
{
- init(data);
+ synchronized (Turbine.class)
+ {
+
+ // Store the context path for tools like ContentURI and
+ // the UIManager that use webapp context path information
+ // for constructing URLs.
+ serverData = new ServerData(req);
+
+ // Mark that we're done.
+ firstDoGet = false;
+ log.info("Turbine: first Request successful");
+ }
+
}
// Stages of Pipeline implementation execution
@@ -930,25 +916,6 @@
log.error(reallyScrewedNow.getMessage(), reallyScrewedNow);
}
- }
-
- /**
- * Save some information about this servlet so that
- * it can be utilized by object instances that do not
- * have direct access to RunData.
- *
- * @param data
- */
- public static synchronized void saveServletInfo(RunData data)
- {
- // Store the context path for tools like ContentURI and
- // the UIManager that use webapp context path information
- // for constructing URLs.
-
- //
- // Bundle all the information above up into a convenient structure
- //
- serverData = (ServerData) data.getServerData().clone();
}
/**
1.1 jakarta-turbine-2/src/test/org/apache/turbine/TurbineTest.java
Index: TurbineTest.java
===================================================================
package org.apache.turbine;
/*
* ==================================================================== The
* Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The end-user documentation included with the redistribution, if any,
* must include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if and
* wherever such third-party acknowledgments normally appear.
* 4. The names "Apache" and "Apache Software Foundation" and "Apache Turbine"
* must not be used to endorse or promote products derived from this software
* without prior written permission. For written permission, please contact
* [EMAIL PROTECTED]
* 5. Products derived from this software may not be called "Apache", "Apache
* Turbine", nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*/
import java.io.File;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import org.apache.turbine.test.BaseTestCase;
import org.apache.turbine.test.EnhancedMockHttpServletRequest;
import org.apache.turbine.test.EnhancedMockHttpServletResponse;
import org.apache.turbine.util.TurbineConfig;
import org.apache.turbine.util.TurbineXmlConfig;
import com.mockobjects.servlet.MockHttpServletRequest;
/**
* This testcase verifies that TurbineConfig can be used to startup Turbine in
* a non servlet environment properly.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Eric Pugh </a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Courcoux </a>
* @version $Id: TurbineTest.java,v 1.1 2004/05/25 21:20:41 epugh Exp $
*/
public class TurbineTest extends BaseTestCase {
public TurbineTest(String name) throws Exception {
super(name);
}
public void testTurbineAndFirstGet() throws Exception {
TurbineConfig tc =
new TurbineConfig(
".",
"/conf/test/CompleteTurbineResources.properties");
tc.initialize();
ServletConfig config = (ServletConfig) tc;
ServletContext context = config.getServletContext();
assertNotNull(Turbine.getDefaultServerData());
assertEquals("",Turbine.getServerName());
assertEquals("80",Turbine.getServerPort());
assertEquals("",Turbine.getScriptName());
Turbine t = tc.getTurbine();
assertEquals("80",t.getServerPort());
MockHttpServletRequest request = getMockRequest();
EnhancedMockHttpServletResponse resp = new EnhancedMockHttpServletResponse();
t.doGet(request,resp);
assertEquals("8080",Turbine.getServerPort());
}
}
1.17 +10 -11
jakarta-turbine-2/src/java/org/apache/turbine/util/TurbineConfig.java
Index: TurbineConfig.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/TurbineConfig.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- TurbineConfig.java 9 Jun 2003 12:07:28 -0000 1.16
+++ TurbineConfig.java 25 May 2004 21:20:41 -0000 1.17
@@ -210,28 +210,27 @@
}
/**
- * Initialization requiring a HTTP <code>GET</code> request.
+ * Shutdown the Turbine System, lifecycle style
+ *
*/
- public void init(RunData data)
+ public void dispose()
{
if (turbine != null)
{
- turbine.init(data);
+ turbine.destroy();
}
}
/**
- * Shutdown the Turbine System, lifecycle style
+ * Returns a reference to the Turbine servlet that was initialized.
*
+ * @return a ServletContext reference
*/
- public void dispose()
+ public Turbine getTurbine()
{
- if (turbine != null)
- {
- turbine.destroy();
- }
+ return turbine;
}
-
+
/**
* Returns a reference to the object cast onto ServletContext type.
*
1.88 +6 -1 jakarta-turbine-2/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/xdocs/changes.xml,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -r1.87 -r1.88
--- changes.xml 13 May 2004 11:17:22 -0000 1.87
+++ changes.xml 25 May 2004 21:20:41 -0000 1.88
@@ -102,7 +102,8 @@
<ul>
<li>
Fixed problem in Intake with the "remove" method in IntakeTool that is
- triggered by a "removeAll".</br>
+ triggered by a "removeAll".
+ <br/>
When there is more than one instance of a group and a "removeAll" is
done the "remove" method is called for each of the instances of the
group. If a mutiply instantiated group is the last one to be removed,
@@ -184,6 +185,10 @@
<subsection name="Other changes">
<p>
<ul>
+ <li>
+ Refactored how Turbine sets up it's ServerData object. Removed the use
+ of RunData from the process.
+ </li>
<li>
Removed dependency on deprecated Log4jFactory in favor of Log4jLogger.
</li>
1.5 +25 -1
jakarta-turbine-2/src/test/org/apache/turbine/test/BaseTestCase.java
Index: BaseTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/test/org/apache/turbine/test/BaseTestCase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BaseTestCase.java 18 Feb 2004 11:55:20 -0000 1.4
+++ BaseTestCase.java 25 May 2004 21:20:42 -0000 1.5
@@ -58,6 +58,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Properties;
+import java.util.Vector;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
@@ -67,10 +68,13 @@
import org.apache.log4j.PropertyConfigurator;
import org.apache.turbine.Turbine;
+import org.apache.turbine.om.security.User;
import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.services.rundata.RunDataService;
import org.apache.turbine.util.RunData;
+import com.mockobjects.servlet.MockHttpServletRequest;
+
/**
* Base functionality to be extended by all Apache Turbine test cases. Test
* case implementations are used to automate testing via JUnit.
@@ -112,6 +116,26 @@
RunDataService.SERVICE_NAME);
RunData runData = rds.getRunData(request, response, config);
return runData;
+ }
+
+ protected MockHttpServletRequest getMockRequest(){
+ EnhancedMockHttpServletRequest request = new
EnhancedMockHttpServletRequest();
+ EnhancedMockHttpSession session = new EnhancedMockHttpSession();
+ session.setupGetAttribute(User.SESSION_KEY, null);
+ request.setupServerName("bob");
+ request.setupGetProtocol("http");
+ request.setupScheme("scheme");
+ request.setupPathInfo("damn");
+ request.setupGetServletPath("damn2");
+ request.setupGetContextPath("wow");
+ request.setupGetContentType("html/text");
+ request.setupAddHeader("Content-type", "html/text");
+ request.setupAddHeader("Accept-Language", "en-US");
+ Vector v = new Vector();
+ request.setupGetParameterNames(v.elements());
+ request.setSession(session);
+ return request;
+
}
}
1.9 +1 -1 jakarta-turbine-2/xdocs/howto/migrate-from-2_2-howto.xml
Index: migrate-from-2_2-howto.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/xdocs/howto/migrate-from-2_2-howto.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- migrate-from-2_2-howto.xml 29 Apr 2004 10:26:59 -0000 1.8
+++ migrate-from-2_2-howto.xml 25 May 2004 21:20:42 -0000 1.9
@@ -254,7 +254,7 @@
Security Service</a> for information on extending TurbineUser in Turbine
2.3 - this is now much easier than it was in previous releases. You
may also want to refer to
- <a href="http://nagoya.apache.org/eyebrowse/[EMAIL PROTECTED]&msgNo=15077">
+ <a href="http://nagoya.apache.org/eyebrowse/[EMAIL PROTECTED]&msgNo=15077">
this message from the mail archive</a> - the quoted text from Henning is
great and Wei points to a couple of additional messages that may also
prove useful.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]