vgritsenko 2002/10/28 20:49:52 Modified: . changes.xml src/java/org/apache/cocoon/components/request MaybeUploadRequestFactoryImpl.java RequestFactory.java src/java/org/apache/cocoon/environment/http HttpEnvironment.java HttpRequest.java src/java/org/apache/cocoon/servlet CocoonServlet.java Log: Remove the static factory variable in RequestFactory, and instead pass it to the HttpRequest via the environment. Revision Changes Path 1.274 +6 -2 xml-cocoon2/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/changes.xml,v retrieving revision 1.273 retrieving revision 1.274 diff -u -r1.273 -r1.274 --- changes.xml 28 Oct 2002 15:48:27 -0000 1.273 +++ changes.xml 29 Oct 2002 04:49:52 -0000 1.274 @@ -40,7 +40,11 @@ </devs> <release version="@version@" date="@date@"> - <action dev="TC type="update"> + <action dev="VG" type="fix" fixes-bug="13643" due-to="Leo Sutic" due-to-email="[EMAIL PROTECTED]"> + Remove the static factory variable in RequestFactory, and instead + pass it to the HttpRequest via the environment. + </action> + <action dev="TC" type="update"> Renamed the AbstractMethodAction into AbstractMultiAction and moved it from scratchpad into the maintrunk. Using it helps reducing the amount of custom actions for a webapp. 1.4 +3 -3 xml-cocoon2/src/java/org/apache/cocoon/components/request/MaybeUploadRequestFactoryImpl.java Index: MaybeUploadRequestFactoryImpl.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/request/MaybeUploadRequestFactoryImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MaybeUploadRequestFactoryImpl.java 28 Jun 2002 08:22:56 -0000 1.3 +++ MaybeUploadRequestFactoryImpl.java 29 Oct 2002 04:49:52 -0000 1.4 @@ -59,14 +59,13 @@ import java.util.Vector; /** - * * Extends the {@link RequestFactory} class * * @author <a href="mailto:dims@;apache.org">Davanum Srinivas</a> * @version CVS $Id$ */ - public final class MaybeUploadRequestFactoryImpl extends RequestFactory { + /** * Return a wrapped request object */ @@ -94,6 +93,7 @@ oldInterval = session.getMaxInactiveInterval(); session.setMaxInactiveInterval( -1 ); } + req = new MaybeUploadRequestWrapperEx(request, saveUploadedFilesToDisk, uploadDirectory, 1.2 +14 -12 xml-cocoon2/src/java/org/apache/cocoon/components/request/RequestFactory.java Index: RequestFactory.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/request/RequestFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- RequestFactory.java 24 Feb 2002 11:10:58 -0000 1.1 +++ RequestFactory.java 29 Oct 2002 04:49:52 -0000 1.2 @@ -62,27 +62,28 @@ * @author <a href="mailto:dims@;yahoo.com">Davanum Srinivas</a> * @version CVS $Id$ */ -public abstract class RequestFactory - implements Component { +public abstract class RequestFactory implements Component { - static private RequestFactory factory; - - public static synchronized RequestFactory getRequestFactory(String className) { - if(factory != null) - return factory; + public static RequestFactory getRequestFactory(String className) { + RequestFactory factory = null; try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class clazz = loader.loadClass(className); factory = (RequestFactory)clazz.newInstance(); - } catch (Throwable t){} + } catch (Throwable t) { + // FIXME (VG): Is it Ok to ignore all exceptions? + } if(factory == null) { try { Class clazz = Class.forName(className); factory = (RequestFactory)clazz.newInstance(); - } catch (Throwable t){} + } catch (Throwable t) { + // FIXME (VG): Is it Ok to ignore all exceptions? + } } - if(factory == null) + if (factory == null) { factory = new SimpleRequestFactoryImpl(); + } return factory; } @@ -95,8 +96,9 @@ boolean allowOverwrite, boolean silentlyRename, int maxUploadSize); + /** * Implementation of the get method */ public abstract Object get(HttpServletRequest request, String name); -} \ No newline at end of file +} 1.18 +6 -4 xml-cocoon2/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java Index: HttpEnvironment.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- HttpEnvironment.java 24 Sep 2002 08:44:23 -0000 1.17 +++ HttpEnvironment.java 29 Oct 2002 04:49:52 -0000 1.18 @@ -51,6 +51,7 @@ package org.apache.cocoon.environment.http; import org.apache.cocoon.Constants; +import org.apache.cocoon.components.request.RequestFactory; import org.apache.cocoon.environment.AbstractEnvironment; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Redirector; @@ -102,14 +103,15 @@ ServletContext servletContext, HttpContext context, String containerEncoding, - String defaultFormEncoding) + String defaultFormEncoding, + RequestFactory requestFactory) throws MalformedURLException, IOException { super(uri, req.getParameter(Constants.VIEW_PARAM), rootURL, extractAction(req)); - this.request = new HttpRequest (req, this); + this.request = new HttpRequest(req, this, requestFactory); this.request.setCharacterEncoding(defaultFormEncoding); this.request.setContainerEncoding(containerEncoding); - this.response = new HttpResponse (res); + this.response = new HttpResponse(res); this.webcontext = context; this.outputStream = response.getOutputStream(); this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT, this.request); 1.9 +7 -4 xml-cocoon2/src/java/org/apache/cocoon/environment/http/HttpRequest.java Index: HttpRequest.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/http/HttpRequest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- HttpRequest.java 4 Jun 2002 09:27:21 -0000 1.8 +++ HttpRequest.java 29 Oct 2002 04:49:52 -0000 1.9 @@ -83,20 +83,23 @@ /** The default form encoding of the servlet container */ private String container_encoding = null; + + private final RequestFactory requestFactory; /** * Creates a HttpServletRequest based on a real HttpServletRequest object */ - protected HttpRequest (HttpServletRequest req, HttpEnvironment env) { - super (); + protected HttpRequest(HttpServletRequest req, HttpEnvironment env, RequestFactory requestFactory) { + super(); this.req = req; this.env = env; + this.requestFactory = requestFactory; } /* The HttpServletRequest interface methods */ public Object get(String name) { - return RequestFactory.getRequestFactory(null).get(this.req, name); + return requestFactory.get(this.req, name); } public String getAuthType() { 1.42 +19 -15 xml-cocoon2/src/java/org/apache/cocoon/servlet/CocoonServlet.java Index: CocoonServlet.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/servlet/CocoonServlet.java,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- CocoonServlet.java 22 Oct 2002 04:01:58 -0000 1.41 +++ CocoonServlet.java 29 Oct 2002 04:49:52 -0000 1.42 @@ -203,6 +203,12 @@ */ protected URL servletContextURL; + + /** + * The requestFactory to use for incoming HTTP requests. + */ + protected RequestFactory requestFactory; + /** * Initialize this <code>CocoonServlet</code> instance. You will * notice that I have broken the init into sub methods to make it @@ -426,13 +432,14 @@ } } - requestFactoryClass = conf.getInitParameter("request-factory"); + this.requestFactoryClass = conf.getInitParameter("request-factory"); if (requestFactoryClass == null) { - requestFactoryClass = "org.apache.cocoon.components.request.MaybeUploadRequestFactoryImpl"; + requestFactoryClass = "org.apache.cocoon.components.request.MultipartRequestFactoryImpl"; if (log.isDebugEnabled()) { log.debug("request-factory was not set - defaulting to " + requestFactoryClass); } } + this.requestFactory = RequestFactory.getRequestFactory(requestFactoryClass); this.containerEncoding = conf.getInitParameter("container-encoding"); if (containerEncoding == null) { @@ -611,7 +618,7 @@ Manifest mf = new Manifest(manifestURL.openStream()); Attributes attr = mf.getMainAttributes(); - String libValue = (String)attr.getValue("Cocoon-Libs"); + String libValue = attr.getValue("Cocoon-Libs"); if (libValue == null) { this.log.fatalError("Unable to get 'Cocoon-Libs' attribute from the Manifest"); return null; @@ -749,11 +756,8 @@ * be as restrictive (Priority.FATAL_ERROR and above) or as liberal * (Priority.DEBUG and above) as you want that get routed to the * file. - * - * @throws ServletException */ - private void initLogger() - throws ServletException { + private void initLogger() { String logLevel = getInitParameter("log-level"); if (logLevel == null) { logLevel = "INFO"; @@ -944,7 +948,7 @@ // This is more scalable long start = System.currentTimeMillis(); res.addHeader("X-Cocoon-Version", Constants.VERSION); - HttpServletRequest request = RequestFactory.getRequestFactory(requestFactoryClass).getServletRequest(req, + HttpServletRequest request = requestFactory.getServletRequest(req, CocoonServlet.SAVE_UPLOADED_FILES_TO_DISK, this.uploadDir, CocoonServlet.ALLOW_OVERWRITE, @@ -1018,7 +1022,7 @@ uri = uri.substring(1); } - Environment env = this.getEnvironment(URLDecoder.decode(uri), request, res); + Environment env = getEnvironment(URLDecoder.decode(uri), request, res); // Initialize a fresh log context containing the object model : it // will be used by the CocoonLogFormatter @@ -1166,8 +1170,8 @@ * Create the environment for the request */ protected Environment getEnvironment(String uri, - HttpServletRequest req, - HttpServletResponse res) + HttpServletRequest req, + HttpServletResponse res) throws Exception { HttpEnvironment env; @@ -1182,7 +1186,8 @@ this.servletContext, (HttpContext)this.appContext.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT), this.containerEncoding, - formEncoding); + formEncoding, + this.requestFactory); env.enableLogging(new LogKitLogger(this.log)); return env; } @@ -1329,8 +1334,7 @@ return instrumentManager; } - private String processTime(long time) throws IOException { - + private String processTime(long time) { StringBuffer out = new StringBuffer(PROCESSED_BY); if (time <= SECOND) { out.append(time);
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]