You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/01/11 21:43:04 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util RequestUtil.java
costin 00/01/11 12:43:04
Modified: src/share/org/apache/tomcat/context
DefaultContextSetter.java
src/share/org/apache/tomcat/core Constants.java Context.java
HttpServletRequestFacade.java Request.java
RequestDispatcherImpl.java Response.java
ServletConfigImpl.java ServletContextFacade.java
src/share/org/apache/tomcat/util RequestUtil.java
Log:
Moved code out of facade into the real classes.
It was added to fix various problems, but it's against the design of
facade ( IMHO).
Revision Changes Path
1.3 +1 -4 jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultContextSetter.java
Index: DefaultContextSetter.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultContextSetter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultContextSetter.java 2000/01/11 02:06:53 1.2
+++ DefaultContextSetter.java 2000/01/11 20:43:02 1.3
@@ -83,10 +83,7 @@
// sets: engineHeader, requestSecurityProvider, workDir, sessionManager, classPath, libPath
public int handleContextInit(Context ctx) {
setEngineHeader( ctx );
- if( ctx.getRequestSecurityProvider() == null )
- ctx.setRequestSecurityProvider(DefaultRequestSecurityProvider.
- getInstance());
-
+
if( ctx.getWorkDir() == null)
setWorkDir(ctx);
1.13 +2 -7 jakarta-tomcat/src/share/org/apache/tomcat/core/Constants.java
Index: Constants.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Constants.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Constants.java 2000/01/10 19:13:36 1.12
+++ Constants.java 2000/01/11 20:43:02 1.13
@@ -89,6 +89,8 @@
public static final int RequestURIMatchRecursion = 5;
public static final String WORK_DIR = "work";
+ public static final String LOCALE_DEFAULT="en";
+
public static class Context {
public static final String WebInfDir = "WEB-INF";
public static final String WARInfDir = "META-INF";
@@ -145,10 +147,6 @@
"org.apache.tomcat.servlet.resolved";
}
- public static class Locale {
- public static final String Default = "en";
- }
-
public static class ContentType {
public static final String Default = "text/plain";
public static final String HTML = "text/html";
@@ -159,7 +157,4 @@
public static final String Default = "8859_1";
}
- public static class Header {
- public static final String AcceptLanguage = "Accept-Language";
- }
}
1.25 +156 -4 jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java
Index: Context.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- Context.java 2000/01/11 03:02:13 1.24
+++ Context.java 2000/01/11 20:43:02 1.25
@@ -229,8 +229,164 @@
return this.rsProvider;
}
+ public URL getResource(String path) throws MalformedURLException {
+ URL url = null;
+ if (path == null) {
+ String msg = sm.getString("scfacade.getresource.npe");
+ throw new NullPointerException(msg);
+ } else if (! path.equals("") &&
+ ! path.startsWith("/")) {
+ String msg = sm.getString("scfacade.getresource.iae", path);
+
+ throw new IllegalArgumentException(msg);
+ }
+
+ // XXX
+ // this could use a once over - after war perhaps
+ URL docBase = getDocumentBase();
+
+ Request lr = new Request();
+ lr.setLookupPath( path );
+ lr.setContext( this );
+ getContextManager().internalRequestParsing(lr);
+
+ String mappedPath = path;
+
+ if (lr != null &&
+ lr.getMappedPath() != null &&
+ lr.getMappedPath().trim().length() > 0) {
+ mappedPath = lr.getMappedPath();
+ }
+
+ if (path.equals("")) {
+ url = docBase;
+ } else if (docBase.getProtocol().equalsIgnoreCase("war")) {
+ if (isWARExpanded()) {
+ File f = new File(getWARDir().toString());
+ String absPath = f.getAbsolutePath();
+
+ // take care of File.getAbsolutePath() troubles
+ // on jdk1.1.x/win
+
+ absPath = FileUtil.patch(absPath);
+
+ if (! absPath.startsWith("/")) {
+ absPath = "/" + absPath;
+ }
+
+ url = new URL("file://localhost" + absPath + "/" +
+ mappedPath);
+ } else {
+ String documentBase = getDocumentBase().toString();
+
+ if (documentBase.endsWith("/")) {
+ documentBase = documentBase.substring(0,
+ documentBase.length() - 1);
+ }
+
+ url = new URL(documentBase + "!" + mappedPath);
+ }
+ } else {
+ url = new URL(docBase.getProtocol(), docBase.getHost(),
+ docBase.getPort(), docBase.getFile() + mappedPath);
+ }
+
+ return url;
+ }
+
+ Context getContext(String path) {
+ if (! path.startsWith("/")) {
+ String msg = sm.getString("sfcacade.context.iae", path);
+ throw new IllegalArgumentException(msg);
+ }
+ return server.getContextByPath(path);
+ }
+
+ public void log(String msg, Throwable t) {
+ System.err.println(msg);
+ t.printStackTrace(System.err);
+ }
+
+ void log(String msg) {
+ // Can't get this anymore - Harish. A stop-gap arrangement.
+ // context.getLogModule().log(msg);
+
+ System.err.println(msg);
+ }
+
+
+ String getRealPath( String path) {
+ String realPath = null;
+
+ int i = -1;
+
+ // norm path
+ while ((i = path.indexOf('\\')) > -1) {
+ String a = path.substring(0, i);
+ String b = "";
+
+ if (i < path.length() - 1) {
+ b = path.substring(i + 1);
+ }
+
+ path = a + "/" + b;
+ }
+
+ try {
+ URL url = getResource(path);
+
+ if (url != null) {
+ if (url.getProtocol().equalsIgnoreCase("war")) {
+ if (isWARExpanded()) {
+ String spec = url.getFile();
+
+ if (spec.startsWith("/")) {
+ spec = spec.substring(1);
+ }
+
+ int separator = spec.indexOf('!');
+ URL warURL = null;
+
+ if (separator > -1) {
+ warURL = new URL(spec.substring(0, separator++));
+ }
+
+ if (warURL.getProtocol().equalsIgnoreCase("file")) {
+ String s = getWorkDir() +"/" +
+ Constants.Context.WARExpandDir + path;
+ File f = new File(s);
+ String absPath = f.getAbsolutePath();
+
+ // take care of File.getAbsolutePath()
+ // troubles on jdk1.1.x/win
+
+ realPath = FileUtil.patch(absPath);
+ } else if (url.getProtocol().equalsIgnoreCase("http")) {
+ // XXX
+ // need to support http docBase'd context
+ }
+ } else {
+ realPath = url.toString();
+ }
+ } else if (url.getProtocol().equalsIgnoreCase("http")) {
+ // XXX
+ // need to support http docBase'd context
+ } else if (url.getProtocol().equalsIgnoreCase("file")) {
+ // take care of File.getAbsolutePath() troubles on
+ // jdk1.1.x/win
+
+ realPath = FileUtil.patch(url.getFile());
+ }
+
+ }
+ } catch (Exception e) {
+ }
+
+ return realPath;
+ }
+
public File getWARDir() {
return this.warDir;
}
@@ -271,7 +427,6 @@
* <BR> b.postInvoke(...)
* <BR> a.postInvoke(...)
*/
-
public void addInitInterceptor(LifecycleInterceptor interceptor) {
initInterceptors.addElement(interceptor);
}
@@ -291,7 +446,6 @@
* <BR> b.postInvoke(...)
* <BR> a.postInvoke(...)
*/
-
public void addDestroyInterceptor(LifecycleInterceptor interceptor) {
destroyInterceptors.addElement(interceptor);
}
@@ -311,7 +465,6 @@
* <BR> b.postInvoke(...)
* <BR> a.postInvoke(...)
*/
-
public void addServiceInterceptor(ServiceInterceptor interceptor) {
serviceInterceptors.addElement(interceptor);
}
@@ -336,7 +489,6 @@
* <p>This method may only be called once and must be called
* before any requests are handled by this context.
*/
-
public synchronized void init() {
if (this.initialized) {
String msg = sm.getString("context.init.alreadyinit");
1.5 +23 -214 jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletRequestFacade.java
Index: HttpServletRequestFacade.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletRequestFacade.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- HttpServletRequestFacade.java 2000/01/07 19:14:11 1.4
+++ HttpServletRequestFacade.java 2000/01/11 20:43:02 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletRequestFacade.java,v 1.4 2000/01/07 19:14:11 costin Exp $
- * $Revision: 1.4 $
- * $Date: 2000/01/07 19:14:11 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletRequestFacade.java,v 1.5 2000/01/11 20:43:02 costin Exp $
+ * $Revision: 1.5 $
+ * $Date: 2000/01/11 20:43:02 $
*
* ====================================================================
*
@@ -80,21 +80,23 @@
* @author James Todd [gonzo@eng.sun.com]
* @author Harish Prabandham
*/
+public class HttpServletRequestFacade implements HttpServletRequest {
-public class HttpServletRequestFacade
-implements HttpServletRequest {
-
- private StringManager sm =
- StringManager.getManager(Constants.Package);
+ private StringManager sm = StringManager.getManager(Constants.Package);
private Request request;
+
private boolean usingStream = false;
private boolean usingReader = false;
-
+
public Request getRealRequest() {
+ // XXX In JDK1.2, call a security class to see if the code has
+ // the right permission !!!
return request;
}
public HttpServletRequestFacade(Request request) {
+ // XXX In JDK1.2, call a security class to see if the code has
+ // the right permission !!!
this.request = request;
}
@@ -132,14 +134,6 @@
public Cookie[] getCookies() {
return request.getCookies();
- // Vector cookies = request.getCookies();
- // Cookie[] cookieArray = new Cookie[cookies.size()];
-
- // for (int i = 0; i < cookies.size(); i ++) {
- // cookieArray[i] = (Cookie)cookies.elementAt(i);
- // }
-
- // return cookieArray;
}
public long getDateHeader(String name) {
@@ -161,12 +155,10 @@
public ServletInputStream getInputStream() throws IOException {
if (usingReader) {
String msg = sm.getString("reqfac.getinstream.ise");
-
throw new IllegalStateException(msg);
}
usingStream = true;
-
return request.getInputStream();
}
@@ -200,30 +192,7 @@
}
public String getPathTranslated() {
- String pathTranslated = null;
- String pathInfo = getPathInfo();
-
- if (pathInfo != null) {
- if (pathInfo.equals("")) {
- pathInfo = "/";
- }
-
- try {
- URL url =
- request.getContext().getFacade().getResource(pathInfo);
-
- if (url != null &&
- url.getProtocol().equals("file")) {
- pathTranslated = FileUtil.patch(url.getFile());
- }
- } catch (MalformedURLException e) {
- }
- }
-
- // XXX
- // resolve this against the context
-
- return pathTranslated;
+ return request.getPathTranslated();
}
public String getProtocol() {
@@ -235,15 +204,7 @@
}
public String getRemoteUser() {
- // Using the Servlet 2.2 semantics ...
- // return request.getRemoteUser();
- java.security.Principal p = getUserPrincipal();
-
- if (p != null) {
- return p.getName();
- }
-
- return null;
+ return request.getRemoteUser();
}
public String getScheme() {
@@ -266,20 +227,13 @@
return request.getSession(create);
}
- // XXX XXX is it used ?? (costin)
- // public ServerSession getServerSession(boolean create) {
- // return request.getServerSession(create);
- // }
-
public BufferedReader getReader() throws IOException {
if (usingStream) {
String msg = sm.getString("reqfac.getreader.ise");
-
throw new IllegalStateException(msg);
}
usingReader = true;
-
return request.getReader();
}
@@ -299,52 +253,12 @@
return request.getRequestURI();
}
- private Context getContext() {
- return getRealRequest().getContext();
- }
-
public RequestDispatcher getRequestDispatcher(String path) {
- if (path == null) {
- String msg = sm.getString("hsrf.dispatcher.iae", path);
-
- throw new IllegalArgumentException(msg);
- }
-
- if (! path.startsWith("/")) {
- String lookupPath = request.getLookupPath();
-
- // Cut off the last slash and everything beyond
- int index = lookupPath.lastIndexOf("/");
- lookupPath = lookupPath.substring(0, index);
-
- // Deal with .. by chopping dirs off the lookup path
- while (path.startsWith("../")) {
- if (lookupPath.length() > 0) {
- index = lookupPath.lastIndexOf("/");
- lookupPath = lookupPath.substring(0, index);
- }
- else {
- // More ..'s than dirs, return null
- return null;
- }
-
- index = path.indexOf("../") + 3;
- path = path.substring(index);
- }
-
- path = lookupPath + "/" + path;
- }
-
- RequestDispatcher requestDispatcher =
- getContext().getFacade().getRequestDispatcher(path);
-
- return requestDispatcher;
+ return request.getRequestDispatcher(path);
}
public boolean isSecure() {
- Context ctx = getContext();
-
- return ctx.getRequestSecurityProvider().isSecure(ctx, this);
+ return request.isSecure();
}
public Locale getLocale() {
@@ -352,25 +266,19 @@
}
public Enumeration getLocales() {
- String acceptLanguage = getHeader(Constants.Header.AcceptLanguage);
-
- return getLocales(acceptLanguage);
+ return RequestUtil.getLocales(this);
}
public String getContextPath() {
- return getContext().getPath();
+ return request.getContext().getPath();
}
public boolean isUserInRole(String role) {
- Context ctx = getContext();
-
- return ctx.getRequestSecurityProvider().isUserInRole(ctx, this, role);
+ return request.isUserInRole(role);
}
public Principal getUserPrincipal() {
- Context ctx = getContext();
-
- return ctx.getRequestSecurityProvider().getUserPrincipal(ctx, this);
+ return request.getUserPrincipal();
}
public String getServletPath() {
@@ -380,126 +288,27 @@
/**
* @deprecated
*/
-
public String getRealPath(String name) {
- return request.getContext().getFacade().getRealPath(name);
+ return request.getContext().getRealPath(name);
}
public boolean isRequestedSessionIdValid() {
- // so here we just assume that if we have a session it's,
- // all good, else not.
- HttpSession session = (HttpSession)getSession(false);
-
- if (session != null) {
- return true;
- } else {
- return false;
- }
+ return request.isRequestedSessionIdValid();
}
public boolean isRequestedSessionIdFromCookie() {
- // XXX
- // yes, this is always true for now as cookies
- // are all we use....
- return true;
+ return request.isRequestedSessionIdFromCookie();
}
/**
* @deprecated
*/
-
public boolean isRequestedSessionIdFromUrl() {
return isRequestedSessionIdFromURL();
}
public boolean isRequestedSessionIdFromURL() {
- // XXX
- return false;
+ return request.isRequestedSessionIdFromURL();
}
- private Enumeration getLocales(String acceptLanguage) {
- // Short circuit with an empty enumeration if null header
- if (acceptLanguage == null) {
- Vector def = new Vector();
- def.addElement(Locale.getDefault());
- return def.elements();
- }
-
- Hashtable languages = new Hashtable();
-
- StringTokenizer languageTokenizer =
- new StringTokenizer(acceptLanguage, ",");
-
- while (languageTokenizer.hasMoreTokens()) {
- String language = languageTokenizer.nextToken().trim();
- int qValueIndex = language.indexOf(';');
- int qIndex = language.indexOf('q');
- int equalIndex = language.indexOf('=');
- Double qValue = new Double(1);
-
- if (qValueIndex > -1 &&
- qValueIndex < qIndex &&
- qIndex < equalIndex) {
- String qValueStr = language.substring(qValueIndex + 1);
-
- language = language.substring(0, qValueIndex);
- qValueStr = qValueStr.trim().toLowerCase();
- qValueIndex = qValueStr.indexOf('=');
- qValue = new Double(0);
-
- if (qValueStr.startsWith("q") &&
- qValueIndex > -1) {
- qValueStr = qValueStr.substring(qValueIndex + 1);
-
- try {
- qValue = new Double(qValueStr.trim());
- } catch (NumberFormatException nfe) {
- }
- }
- }
-
- // XXX
- // may need to handle "*" at some point in time
-
- if (! language.equals("*")) {
- String key = qValue.toString();
- Vector v = (Vector)((languages.containsKey(key)) ?
- languages.get(key) : new Vector());
-
- v.addElement(language);
- languages.put(key, v);
- }
- }
-
- if (languages.size() == 0) {
- Vector v = new Vector();
-
- v.addElement(Constants.Locale.Default);
- languages.put("1.0", v);
- }
-
- Vector l = new Vector();
- Enumeration e = languages.keys();
-
- while (e.hasMoreElements()) {
- String key = (String)e.nextElement();
- Vector v = (Vector)languages.get(key);
- Enumeration le = v.elements();
-
- while (le.hasMoreElements()) {
- String language = (String)le.nextElement();
- String country = "";
- int countryIndex = language.indexOf("-");
-
- if (countryIndex > -1) {
- country = language.substring(countryIndex + 1).trim();
- language = language.substring(0, countryIndex).trim();
- }
-
- l.addElement(new Locale(language, country));
- }
- }
-
- return l.elements();
- }
}
1.16 +123 -38 jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java
Index: Request.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Request.java 2000/01/09 22:32:42 1.15
+++ Request.java 2000/01/11 20:43:02 1.16
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v 1.15 2000/01/09 22:32:42 costin Exp $
- * $Revision: 1.15 $
- * $Date: 2000/01/09 22:32:42 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v 1.16 2000/01/11 20:43:02 costin Exp $
+ * $Revision: 1.16 $
+ * $Date: 2000/01/11 20:43:02 $
*
* ====================================================================
*
@@ -67,6 +67,7 @@
import org.apache.tomcat.util.*;
import java.io.*;
import java.net.*;
+import java.security.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
@@ -117,6 +118,8 @@
// Session
// set by interceptors - the session id
protected String reqSessionId;
+ boolean sessionIdFromCookie=true;
+ boolean sessionIdFromURL=false;
// cache- avoid calling SessionManager for each getSession()
protected HttpSession serverSession;
@@ -290,14 +293,108 @@
// can be null!! -
return contentType;
}
+
+ String getPathTranslated() {
+ String pathTranslated = null;
+ String pathInfo = getPathInfo();
+
+ if (pathInfo != null) {
+ if (pathInfo.equals("")) {
+ pathInfo = "/";
+ }
+
+ try {
+ URL url =
+ context.getResource(pathInfo);
+
+ if (url != null &&
+ url.getProtocol().equals("file")) {
+ pathTranslated = FileUtil.patch(url.getFile());
+ }
+ } catch (MalformedURLException e) {
+ }
+ }
+
+ // XXX
+ // resolve this against the context
+ return pathTranslated;
+ }
+
public String getPathInfo() {
return pathInfo;
}
+
+ String getRemoteUser() {
+ // Using the Servlet 2.2 semantics ...
+ // return request.getRemoteUser();
+ java.security.Principal p = getUserPrincipal();
+
+ if (p != null) {
+ return p.getName();
+ }
+
+ return null;
+
+ //return remoteUser;
+ }
+
+ boolean isSecure() {
+ if( context.getRequestSecurityProvider() == null )
+ return false;
+ return context.getRequestSecurityProvider().isSecure(context, getFacade());
+ }
+
+ RequestDispatcher getRequestDispatcher(String path) {
+ if (path == null) {
+ String msg = sm.getString("hsrf.dispatcher.iae", path);
+ throw new IllegalArgumentException(msg);
+ }
+
+ if (! path.startsWith("/")) {
+ String lookupPath = getLookupPath();
+
+ // Cut off the last slash and everything beyond
+ int index = lookupPath.lastIndexOf("/");
+ lookupPath = lookupPath.substring(0, index);
+
+ // Deal with .. by chopping dirs off the lookup path
+ while (path.startsWith("../")) {
+ if (lookupPath.length() > 0) {
+ index = lookupPath.lastIndexOf("/");
+ lookupPath = lookupPath.substring(0, index);
+ }
+ else {
+ // More ..'s than dirs, return null
+ return null;
+ }
+
+ index = path.indexOf("../") + 3;
+ path = path.substring(index);
+ }
+
+ path = lookupPath + "/" + path;
+ }
+
+ RequestDispatcher requestDispatcher =
+ context.getFacade().getRequestDispatcher(path);
+
+ return requestDispatcher;
+ }
+
+
+
+ Principal getUserPrincipal() {
+ if( context.getRequestSecurityProvider() == null )
+ return null;
+ return context.getRequestSecurityProvider().getUserPrincipal(context, getFacade());
+ }
- public String getRemoteUser() {
- return remoteUser;
+ boolean isUserInRole(String role) {
+ if( context.getRequestSecurityProvider() == null )
+ return false;
+ return context.getRequestSecurityProvider().isUserInRole(context, getFacade(), role);
}
@@ -335,6 +432,15 @@
public Response getResponse() {
return response;
}
+
+ boolean isRequestedSessionIdFromCookie() {
+ return sessionIdFromCookie;
+ }
+
+ boolean isRequestedSessionIdFromURL() {
+ return sessionIdFromURL;
+ }
+
public void setContext(Context context) {
this.context = context;
@@ -437,6 +543,18 @@
return serverSession;
}
+ boolean isRequestedSessionIdValid() {
+ // so here we just assume that if we have a session it's,
+ // all good, else not.
+ HttpSession session = (HttpSession)getSession(false);
+
+ if (session != null) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
// -------------------- LookupResult
public String getResolvedServlet() {
return resolvedServlet;
@@ -552,39 +670,6 @@
// this.scheme = scheme;
// }
-
- /**
- * Adds a query string to the existing set of parameters.
- * The additional parameters represented by the query string will be
- * merged with the existing parameters.
- * Used by the RequestDispatcherImpl to add query string parameters
- * to the request.
- *
- * @param inQueryString URLEncoded parameters to add
- */
- public void addQueryString(String inQueryString) {
- // if query string is null, do nothing
- if ((inQueryString == null) || (inQueryString.trim().length() <= 0))
- return;
-
- // add query string to existing string
- if ((queryString == null) || (queryString.trim().length() <= 0))
- queryString = inQueryString;
- else
- queryString = inQueryString + "&" + queryString;
-
- // process parameters
- Hashtable newParameters = null;
- try {
- newParameters = HttpUtils.parseQueryString(queryString);
- } catch (Throwable e) {
- return;
- }
-
- // merge new parameters with existing parameters
- if (newParameters != null)
- parameters = RequestUtil.mergeParameters(newParameters, parameters);
- }
/**
* Replaces the query string without processing the parameters.
1.7 +28 -3 jakarta-tomcat/src/share/org/apache/tomcat/core/RequestDispatcherImpl.java
Index: RequestDispatcherImpl.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestDispatcherImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- RequestDispatcherImpl.java 2000/01/08 15:09:26 1.6
+++ RequestDispatcherImpl.java 2000/01/11 20:43:02 1.7
@@ -90,7 +90,8 @@
}
public void forward(ServletRequest request, ServletResponse response)
- throws ServletException, IOException {
+ throws ServletException, IOException
+ {
HttpServletRequestFacade reqFacade =
(HttpServletRequestFacade)request;
HttpServletResponseFacade resFacade =
@@ -100,12 +101,10 @@
if (realResponse.isStarted()) {
String msg = sm.getString("rdi.forward.ise");
-
throw new IllegalStateException(msg);
}
// Pre-pend the context name to give appearance of real request
-
urlPath = context.getPath() + urlPath;
// XXX Need to clean up - what's the diff between the lookupResult
@@ -258,4 +257,30 @@
boolean isValid() {
return (this.lookupResult != null);
}
+
+ /**
+ * Adds a query string to the existing set of parameters.
+ * The additional parameters represented by the query string will be
+ * merged with the existing parameters.
+ * Used by the RequestDispatcherImpl to add query string parameters
+ * to the request.
+ *
+ * @param inQueryString URLEncoded parameters to add
+ */
+ public void addQueryString(Request req, String inQueryString) {
+ // if query string is null, do nothing
+ if ((inQueryString == null) || (inQueryString.trim().length() <= 0))
+ return;
+
+ String queryString=req.getQueryString();
+ // add query string to existing string
+ if ((queryString == null) || (queryString.trim().length() <= 0))
+ queryString = inQueryString;
+ else
+ queryString = inQueryString + "&" + queryString;
+
+ req.setQueryString( queryString );
+ }
+
+
}
1.9 +6 -6 jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java
Index: Response.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Response.java 2000/01/11 02:06:54 1.8
+++ Response.java 2000/01/11 20:43:02 1.9
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v 1.8 2000/01/11 02:06:54 costin Exp $
- * $Revision: 1.8 $
- * $Date: 2000/01/11 02:06:54 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v 1.9 2000/01/11 20:43:02 costin Exp $
+ * $Revision: 1.9 $
+ * $Date: 2000/01/11 20:43:02 $
*
* ====================================================================
*
@@ -91,7 +91,7 @@
protected String characterEncoding = Constants.CharacterEncoding.Default;
protected int contentLength = -1;
protected int status = 200;
- private Locale locale = new Locale(Constants.Locale.Default, "");
+ private Locale locale = new Locale(Constants.LOCALE_DEFAULT, "");
protected MimeHeaders headers = new MimeHeaders();
protected BufferedServletOutputStream out;
@@ -160,7 +160,7 @@
userCookies.removeAllElements();
systemCookies.removeAllElements();
contentType = Constants.ContentType.Default;
- locale = new Locale(Constants.Locale.Default, "");
+ locale = new Locale(Constants.LOCALE_DEFAULT, "");
characterEncoding = Constants.CharacterEncoding.Default;
contentLength = -1;
status = 200;
@@ -298,7 +298,7 @@
//
userCookies.removeAllElements(); // keep system (session) cookies
contentType = Constants.ContentType.Default;
- locale = new Locale(Constants.Locale.Default, "");
+ locale = new Locale(Constants.LOCALE_DEFAULT, "");
characterEncoding = Constants.CharacterEncoding.Default;
contentLength = -1;
status = 200;
1.2 +5 -5 jakarta-tomcat/src/share/org/apache/tomcat/core/ServletConfigImpl.java
Index: ServletConfigImpl.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletConfigImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServletConfigImpl.java 1999/10/09 00:30:20 1.1
+++ ServletConfigImpl.java 2000/01/11 20:43:02 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletConfigImpl.java,v 1.1 1999/10/09 00:30:20 duncan Exp $
- * $Revision: 1.1 $
- * $Date: 1999/10/09 00:30:20 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletConfigImpl.java,v 1.2 2000/01/11 20:43:02 costin Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/01/11 20:43:02 $
*
* ====================================================================
*
@@ -120,11 +120,11 @@
return (servletName != null) ? servletName : servletClassName;
}
- public void setServletName(String servletName) {
+ void setServletName(String servletName) {
this.servletName = servletName;
}
- public void setServletClassName(String servletClassName) {
+ void setServletClassName(String servletClassName) {
this.servletClassName = servletClassName;
}
}
1.12 +10 -181 jakarta-tomcat/src/share/org/apache/tomcat/core/ServletContextFacade.java
Index: ServletContextFacade.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletContextFacade.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ServletContextFacade.java 2000/01/10 22:35:31 1.11
+++ ServletContextFacade.java 2000/01/11 20:43:03 1.12
@@ -77,12 +77,8 @@
* @author James Todd [gonzo@eng.sun.com]
* @author Harish Prabandham
*/
-
-public class ServletContextFacade
-implements ServletContext {
-
- private StringManager sm =
- StringManager.getManager(Constants.Package);
+public class ServletContextFacade implements ServletContext {
+ private StringManager sm = StringManager.getManager("org.apache.tomcat.core");
private ContextManager contextM;
private Context context;
@@ -95,13 +91,12 @@
* The one package level hole through the facade for use by
* the default servlet and invoker servlet
*/
-
public Context getRealContext() {
+ // XXX call security !
return context;
}
public Object getAttribute(String name) {
- Object o = context.getAttribute(name);
return context.getAttribute(name);
}
@@ -118,21 +113,7 @@
}
public ServletContext getContext(String path) {
-
- // XXX
- // we need to check to see if the servlet should have
- // this sort of visibility into the inner workings of
- // the server. For now, we aren't running secure, so
- // it's no big deal, but later on, we'll want to throttle
- // access to contexts through this method
-
- if (! path.startsWith("/")) {
- String msg = sm.getString("sfcacade.context.iae", path);
-
- throw new IllegalArgumentException(msg);
- }
-
- return contextM.getContextByPath(path).getFacade();
+ return context.getContext(path).getFacade();
}
public int getMajorVersion() {
@@ -148,149 +129,24 @@
}
public String getRealPath(String path) {
- String realPath = null;
-
- path = normPath(path);
-
- try {
- URL url = getResource(path);
-
- if (url != null) {
- if (url.getProtocol().equalsIgnoreCase("war")) {
- if (context.isWARExpanded()) {
- String spec = url.getFile();
-
- if (spec.startsWith("/")) {
- spec = spec.substring(1);
- }
-
- int separator = spec.indexOf('!');
- URL warURL = null;
-
- if (separator > -1) {
- warURL = new URL(spec.substring(0, separator++));
- }
-
- if (warURL.getProtocol().equalsIgnoreCase("file")) {
- String s = context.getWorkDir() +"/" +
- Constants.Context.WARExpandDir + path;
- File f = new File(s);
- String absPath = f.getAbsolutePath();
-
- // take care of File.getAbsolutePath()
- // troubles on jdk1.1.x/win
-
- realPath = FileUtil.patch(absPath);
- } else if (url.getProtocol().equalsIgnoreCase("http")) {
- // XXX
- // need to support http docBase'd context
- }
- } else {
- realPath = url.toString();
- }
- } else if (url.getProtocol().equalsIgnoreCase("http")) {
- // XXX
- // need to support http docBase'd context
- } else if (url.getProtocol().equalsIgnoreCase("file")) {
- // take care of File.getAbsolutePath() troubles on
- // jdk1.1.x/win
-
- realPath = FileUtil.patch(url.getFile());
- }
-
- }
- } catch (Exception e) {
- }
-
- return realPath;
+ return context.getRealPath( path );
}
public InputStream getResourceAsStream(String path) {
InputStream is = null;
-
try {
URL url = getResource(path);
URLConnection con = url.openConnection();
-
con.connect();
-
is = con.getInputStream();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
-
return is;
}
-
- public URL getResource(String path)
- throws MalformedURLException {
- URL url = null;
-
- if (path == null) {
- String msg = sm.getString("scfacade.getresource.npe");
- throw new NullPointerException(msg);
- } else if (! path.equals("") &&
- ! path.startsWith("/")) {
- String msg = sm.getString("scfacade.getresource.iae", path);
-
- throw new IllegalArgumentException(msg);
- }
-
- // XXX
- // this could use a once over - after war perhaps
-
-
-
- URL docBase = context.getDocumentBase();
-
- Request lr = new Request();
- lr.setLookupPath( path );
- lr.setContext( getRealContext() );
- getRealContext().getContextManager().internalRequestParsing(lr);
-
- String mappedPath = path;
-
- if (lr != null &&
- lr.getMappedPath() != null &&
- lr.getMappedPath().trim().length() > 0) {
- mappedPath = lr.getMappedPath();
- }
-
- if (path.equals("")) {
- url = docBase;
- } else if (docBase.getProtocol().equalsIgnoreCase("war")) {
- if (context.isWARExpanded()) {
- File f = new File(context.getWARDir().toString());
- String absPath = f.getAbsolutePath();
-
- // take care of File.getAbsolutePath() troubles
- // on jdk1.1.x/win
-
- absPath = FileUtil.patch(absPath);
-
- if (! absPath.startsWith("/")) {
- absPath = "/" + absPath;
- }
-
- url = new URL("file://localhost" + absPath + "/" +
- mappedPath);
- } else {
- String documentBase = context.getDocumentBase().toString();
-
- if (documentBase.endsWith("/")) {
- documentBase = documentBase.substring(0,
- documentBase.length() - 1);
- }
-
- url = new URL(documentBase + "!" + mappedPath);
- }
- } else {
- url = new URL(docBase.getProtocol(), docBase.getHost(),
- docBase.getPort(), docBase.getFile() + mappedPath);
- }
-
- return url;
+ public URL getResource(String path) throws MalformedURLException {
+ return context.getResource( path );
}
public RequestDispatcher getRequestDispatcher(String path) {
@@ -312,7 +168,6 @@
public RequestDispatcher getNamedDispatcher(String name) {
if (name == null) {
String msg = sm.getString("scfacade.dispatcher.iae2", name);
-
throw new IllegalArgumentException(msg);
}
@@ -329,10 +184,7 @@
}
public void log(String msg) {
- // Can't get this anymore - Harish. A stop-gap arrangement.
- // context.getLogModule().log(msg);
-
- System.err.println(msg);
+ context.log( msg );
}
public String getInitParameter(String name) {
@@ -344,11 +196,7 @@
}
public void log(String msg, Throwable t) {
- // Can't get this anymore - Harish. A stop-gap arrangement.
- // context.getLogModule().log(msg, t);
-
- System.err.println(msg);
- t.printStackTrace(System.err);
+ context.log(msg, t);
}
/**
@@ -356,7 +204,6 @@
* @deprecated This method is deprecated in the
* javax.servlet.ServletContext interface
*/
-
public void log(Exception e, String msg) {
log(msg, e);
}
@@ -366,17 +213,16 @@
* @deprecated This method is deprecated in the
* javax.servlet.ServletContext interface
*/
-
public Servlet getServlet(String name) throws ServletException {
return null;
}
+
/**
* This method has been deprecated in the public api and always
* return an empty enumeration.
*
* @deprecated
*/
-
public Enumeration getServlets() {
// silly hack to get an empty enumeration
Vector v = new Vector();
@@ -389,27 +235,10 @@
*
* @deprecated
*/
-
public Enumeration getServletNames() {
// silly hack to get an empty enumeration
Vector v = new Vector();
return v.elements();
}
- private String normPath(String path) {
- int i = -1;
-
- while ((i = path.indexOf('\\')) > -1) {
- String a = path.substring(0, i);
- String b = "";
-
- if (i < path.length() - 1) {
- b = path.substring(i + 1);
- }
-
- path = a + "/" + b;
- }
-
- return path;
- }
}
1.4 +87 -0 jakarta-tomcat/src/share/org/apache/tomcat/util/RequestUtil.java
Index: RequestUtil.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/RequestUtil.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RequestUtil.java 2000/01/08 21:31:41 1.3
+++ RequestUtil.java 2000/01/11 20:43:04 1.4
@@ -351,4 +351,91 @@
return encoding;
}
+ public static Enumeration getLocales(HttpServletRequest req) {
+ String acceptLanguage = req.getHeader("Accept-Language");
+ // Short circuit with an empty enumeration if null header
+ if (acceptLanguage == null) {
+ Vector def = new Vector();
+ def.addElement(Locale.getDefault());
+ return def.elements();
+ }
+
+ Hashtable languages = new Hashtable();
+
+ StringTokenizer languageTokenizer =
+ new StringTokenizer(acceptLanguage, ",");
+
+ while (languageTokenizer.hasMoreTokens()) {
+ String language = languageTokenizer.nextToken().trim();
+ int qValueIndex = language.indexOf(';');
+ int qIndex = language.indexOf('q');
+ int equalIndex = language.indexOf('=');
+ Double qValue = new Double(1);
+
+ if (qValueIndex > -1 &&
+ qValueIndex < qIndex &&
+ qIndex < equalIndex) {
+ String qValueStr = language.substring(qValueIndex + 1);
+
+ language = language.substring(0, qValueIndex);
+ qValueStr = qValueStr.trim().toLowerCase();
+ qValueIndex = qValueStr.indexOf('=');
+ qValue = new Double(0);
+
+ if (qValueStr.startsWith("q") &&
+ qValueIndex > -1) {
+ qValueStr = qValueStr.substring(qValueIndex + 1);
+
+ try {
+ qValue = new Double(qValueStr.trim());
+ } catch (NumberFormatException nfe) {
+ }
+ }
+ }
+
+ // XXX
+ // may need to handle "*" at some point in time
+
+ if (! language.equals("*")) {
+ String key = qValue.toString();
+ Vector v = (Vector)((languages.containsKey(key)) ?
+ languages.get(key) : new Vector());
+
+ v.addElement(language);
+ languages.put(key, v);
+ }
+ }
+
+ if (languages.size() == 0) {
+ Vector v = new Vector();
+
+ v.addElement(org.apache.tomcat.core.Constants.LOCALE_DEFAULT);
+ languages.put("1.0", v);
+ }
+
+ Vector l = new Vector();
+ Enumeration e = languages.keys();
+
+ while (e.hasMoreElements()) {
+ String key = (String)e.nextElement();
+ Vector v = (Vector)languages.get(key);
+ Enumeration le = v.elements();
+
+ while (le.hasMoreElements()) {
+ String language = (String)le.nextElement();
+ String country = "";
+ int countryIndex = language.indexOf("-");
+
+ if (countryIndex > -1) {
+ country = language.substring(countryIndex + 1).trim();
+ language = language.substring(0, countryIndex).trim();
+ }
+
+ l.addElement(new Locale(language, country));
+ }
+ }
+
+ return l.elements();
+ }
+
}