bloritsch 01/02/22 06:03:50
Modified: src/org/apache/cocoon/environment/http Tag: xml-cocoon2
HttpRequest22.java HttpRequest23.java
src/org/apache/cocoon/servlet Tag: xml-cocoon2
CocoonServlet.java
Added: . Tag: xml-cocoon2 LICENSE.maybeupload
lib Tag: xml-cocoon2 maybeupload.jar
Log:
Update to allow seamless integration with handling
multipart/form-data forms.
Revision Changes Path
No revision
No revision
1.1.2.1 +43 -0 xml-cocoon/Attic/LICENSE.maybeupload
No revision
No revision
1.1.2.1 +364 -0 xml-cocoon/lib/Attic/maybeupload.jar
<<Binary file>>
No revision
No revision
1.1.2.4 +39 -10
xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpRequest22.java
Index: HttpRequest22.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpRequest22.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- HttpRequest22.java 2001/01/12 15:31:29 1.1.2.3
+++ HttpRequest22.java 2001/02/22 14:03:46 1.1.2.4
@@ -12,6 +12,7 @@
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Locale;
+import java.util.Vector;
import javax.servlet.ServletInputStream;
import javax.servlet.RequestDispatcher;
@@ -20,10 +21,12 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
+import uk.co.weft.maybeupload.MaybeUploadRequestWrapper;
+
/**
*
* Implements the [EMAIL PROTECTED] javax.servlet.http.HttpServletRequest}
interface
- * to provide request information for HTTP servlets.
+ * to provide request information for HTTP servlets.
*/
public class HttpRequest implements HttpServletRequest {
@@ -45,24 +48,50 @@
/* The HttpServletRequest interface methods */
+ public Object get(String name) {
+ if (this.req instanceof MaybeUploadRequestWrapper) {
+ return ((MaybeUploadRequestWrapper) this.req).get(name);
+ } else {
+ String[] values = this.getParameterValues(name);
+
+ if (values == null) return null;
+
+ if (values.length == 1) {
+ return values[0];
+ }
+
+ if (values.length > 1) {
+ Vector vect = new Vector(values.length);
+
+ for (int i = 0; i < values.length; i++) {
+ vect.add(values[i]);
+ }
+
+ return vect;
+ }
+ }
+
+ return null;
+ }
+
public String getAuthType() {
return this.req.getAuthType();
}
public Cookie[] getCookies() {
return this.req.getCookies();
- }
+ }
public long getDateHeader(String name) {
return this.req.getDateHeader(name);
}
public String getHeader(String name) {
- return this.req.getHeader(name);
+ return this.req.getHeader(name);
}
public Enumeration getHeaders(String name) {
- return this.req.getHeaders(name);
+ return this.req.getHeaders(name);
}
public Enumeration getHeaderNames() {
@@ -76,7 +105,7 @@
public String getMethod() {
return this.req.getMethod();
}
-
+
public String getPathInfo() {
return this.req.getPathInfo();
}
@@ -132,7 +161,7 @@
public boolean isRequestedSessionIdFromCookie() {
return this.req.isRequestedSessionIdFromCookie();
}
-
+
public boolean isRequestedSessionIdFromURL() {
return this.req.isRequestedSessionIdFromURL();
}
@@ -169,13 +198,13 @@
}
public ServletInputStream getInputStream() throws IOException {
- return this.req.getInputStream();
+ return this.req.getInputStream();
}
public String getParameter(String name) {
return this.req.getParameter(name);
}
-
+
public Enumeration getParameterNames() {
return this.req.getParameterNames();
}
@@ -183,7 +212,7 @@
public String[] getParameterValues(String name) {
return this.req.getParameterValues(name);
}
-
+
public String getProtocol() {
return this.req.getProtocol();
}
@@ -203,7 +232,7 @@
public BufferedReader getReader() throws IOException {
return this.req.getReader();
}
-
+
public String getRemoteAddr() {
return this.req.getRemoteAddr();
}
1.1.2.3 +33 -11
xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpRequest23.java
Index: HttpRequest23.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpRequest23.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- HttpRequest23.java 2000/12/30 21:38:33 1.1.2.2
+++ HttpRequest23.java 2001/02/22 14:03:47 1.1.2.3
@@ -7,20 +7,12 @@
*****************************************************************************/
package org.apache.cocoon.environment.http;
-//import java.io.BufferedReader;
-//import java.io.IOException;
-//import java.io.UnsupportedEncodingException;
-//import java.util.Enumeration;
-//import java.util.Locale;
-//import java.util.StringBuffer;
+import java.util.Vector;
-//import javax.servlet.ServletInputStream;
-//import javax.servlet.RequestDispatcher;
-
-//import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
-//import javax.servlet.http.HttpSession;
+
+import uk.co.weft.maybeupload.MaybeUploadRequestWrapper;
/**
*
@@ -33,15 +25,45 @@
/** The HttpEnvironment object */
private HttpEnvironment env = null;
+ /** The HttpServletRequest object */
+ private HttpServletRequest req = null;
+
/**
* Creates a HttpServletRequest based on a real HttpServletRequest object
*/
protected HttpRequest (HttpServletRequest req, HttpEnvironment env) {
super (req);
this.env = env;
+ this.req = req;
}
/* The HttpServletRequest interface methods */
+
+ public Object get(String name) {
+ if (this.req instanceof MaybeUploadRequestWrapper) {
+ return ((MaybeUploadRequestWrapper) this.req).get(name);
+ } else {
+ String[] values = this.getParameterValues(name);
+
+ if (values == null) return null;
+
+ if (values.length == 1) {
+ return values[0];
+ }
+
+ if (values.length > 1) {
+ Vector vect = new Vector(values.length);
+
+ for (int i = 0; i < values.length; i++) {
+ vect.add(values[i]);
+ }
+
+ return vect;
+ }
+ }
+
+ return null;
+ }
public String getRequestURI() {
return this.env.getURI();
No revision
No revision
1.1.4.65 +50 -18
xml-cocoon/src/org/apache/cocoon/servlet/Attic/CocoonServlet.java
Index: CocoonServlet.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/servlet/Attic/CocoonServlet.java,v
retrieving revision 1.1.4.64
retrieving revision 1.1.4.65
diff -u -r1.1.4.64 -r1.1.4.65
--- CocoonServlet.java 2001/02/22 13:34:34 1.1.4.64
+++ CocoonServlet.java 2001/02/22 14:03:48 1.1.4.65
@@ -52,6 +52,8 @@
import org.apache.log.output.FileOutputLogTarget;
import org.apache.log.LogTarget;
+import uk.co.weft.maybeupload.MaybeUploadRequestWrapper;
+
/**
* This is the entry point for Cocoon execution as an HTTP Servlet.
*
@@ -60,7 +62,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> Aisa
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @version CVS $Revision: 1.1.4.64 $ $Date: 2001/02/22 13:34:34 $
+ * @version CVS $Revision: 1.1.4.65 $ $Date: 2001/02/22 14:03:48 $
*/
public class CocoonServlet extends HttpServlet {
@@ -76,6 +78,10 @@
protected Exception exception;
protected DefaultContext appContext = new DefaultContext();
+ private static final boolean ALLOW_OVERWRITE = false;
+ private static final boolean SILENTLY_RENAME = true;
+ private File uploadDir;
+
/**
* Initialize this <code>CocoonServlet</code> instance. You will
* notice that I have broken the init into sub methods to make it
@@ -106,8 +112,10 @@
this.forceLoad(conf.getInitParameter("load-class"));
- this.appContext.put(Constants.CONTEXT_WORK_DIR,
- context.getAttribute("javax.servlet.context.tempdir"));
+ File workDir = (File)
context.getAttribute("javax.servlet.context.tempdir");
+ this.appContext.put(Constants.CONTEXT_WORK_DIR, workDir);
+ this.uploadDir = IOUtils.createFile(workDir, "image-dir" +
File.separator);
+ this.uploadDir.mkdirs();
this.appContext.put(Constants.CONTEXT_CONFIG_URL,
this.getConfigFile(conf.getInitParameter("configurations"),
context));
@@ -236,6 +244,29 @@
}
}
+ private HttpServletRequest getServletRequest(HttpServletRequest request)
{
+ HttpServletRequest req = request;
+ String contentType = req.getContentType();
+
+ if (contentType == null) {
+ contentType = "application/x-www-form-urlencoded";
+ }
+
+ if (contentType.startsWith("multipart/form-data")) {
+ try {
+ req = new MaybeUploadRequestWrapper(request,
+ this.uploadDir,
+
CocoonServlet.ALLOW_OVERWRITE,
+
CocoonServlet.SILENTLY_RENAME);
+ } catch (Exception e) {
+ log.warn("Could not create MaybeUploadRequestWrapper", e);
+ req = request;
+ }
+ }
+
+ return req;
+ }
+
/**
* Handle the "force-load" parameter. This overcomes limits in
* many classpath issues. One of the more notorious ones is a
@@ -278,8 +309,9 @@
// This is more scalable
long start = new Date().getTime();
+ HttpServletRequest request = this.getServletRequest(req);
- Cocoon cocoon = getCocoon(req.getPathInfo(),
req.getParameter(Constants.RELOAD_PARAM));
+ Cocoon cocoon = getCocoon(request.getPathInfo(),
request.getParameter(Constants.RELOAD_PARAM));
// Check if cocoon was initialized
if (this.cocoon == null) {
@@ -291,16 +323,16 @@
n.setSource("Cocoon servlet");
n.setMessage("Internal servlet error");
n.setDescription("Cocoon was not initialized.");
- n.addExtraDescription("request-uri", req.getRequestURI());
- Notifier.notify(n, req, res);
+ n.addExtraDescription("request-uri", request.getRequestURI());
+ Notifier.notify(n, request, res);
return;
}
// We got it... Process the request
- String uri = req.getServletPath();
+ String uri = request.getServletPath();
if (uri == null) uri = "";
- String pathInfo = req.getPathInfo();
+ String pathInfo = request.getPathInfo();
if (pathInfo != null) uri += pathInfo;
if (uri.length() == 0) {
@@ -310,7 +342,7 @@
"".charAt(0)
else process URI normally
*/
- String prefix = req.getRequestURI();
+ String prefix = request.getRequestURI();
if (prefix == null) prefix = "";
@@ -323,7 +355,7 @@
uri = uri.substring(1);
}
- Environment env = this.getEnvironment(uri, req, res);
+ Environment env = this.getEnvironment(uri, request, res);
if (!this.cocoon.process(env)) {
@@ -337,11 +369,11 @@
n.setSource("Cocoon servlet");
n.setMessage("Resource not found");
n.setDescription("The requested URI \""
- + req.getRequestURI()
+ + request.getRequestURI()
+ "\" was not found.");
- n.addExtraDescription("request-uri", req.getRequestURI());
+ n.addExtraDescription("request-uri",
request.getRequestURI());
n.addExtraDescription("path-info", uri);
- Notifier.notify(n, req, res);
+ Notifier.notify(n, request, res);
}
} catch (ResourceNotFoundException rse) {
log.warn("The resource was not found", rse);
@@ -353,11 +385,11 @@
n.setSource("Cocoon servlet");
n.setMessage("Resource not found");
n.setDescription("The requested URI \""
- + req.getRequestURI()
+ + request.getRequestURI()
+ "\" was not found.");
- n.addExtraDescription("request-uri", req.getRequestURI());
+ n.addExtraDescription("request-uri", request.getRequestURI());
n.addExtraDescription("path-info", uri);
- Notifier.notify(n, req, res);
+ Notifier.notify(n, request, res);
} catch (Exception e) {
log.error("Problem with servlet", e);
//res.setStatus(res.SC_INTERNAL_SERVER_ERROR);
@@ -365,9 +397,9 @@
n.setType("internal-server-error");
n.setTitle("Internal server error");
n.setSource("Cocoon servlet");
- n.addExtraDescription("request-uri", req.getRequestURI());
+ n.addExtraDescription("request-uri", request.getRequestURI());
n.addExtraDescription("path-info", uri);
- Notifier.notify(n, req, res);
+ Notifier.notify(n, request, res);
}
ServletOutputStream out = res.getOutputStream();
@@ -376,7 +408,7 @@
String timeString = processTime(end - start);
log.info("'" + uri + "' " + timeString);
- String showTime = req.getParameter(Constants.SHOWTIME_PARAM);
+ String showTime = request.getParameter(Constants.SHOWTIME_PARAM);
if ((showTime != null) && !showTime.equalsIgnoreCase("no")) {
boolean hide = showTime.equalsIgnoreCase("hide");