Author: remy.maucherat(a)jboss.com
Date: 2010-05-31 08:08:39 -0400 (Mon, 31 May 2010)
New Revision: 1478
Modified:
trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
trunk/java/org/apache/catalina/connector/Request.java
trunk/java/org/apache/catalina/connector/Response.java
trunk/java/org/apache/catalina/deploy/SessionCookie.java
trunk/java/org/apache/catalina/realm/RealmBase.java
trunk/java/org/apache/tomcat/util/buf/ByteChunk.java
Log:
- Add session path parameter configuration.
- Done by delaying parsing until after mapping, without any performance impact.
Modified: trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
===================================================================
--- trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2010-05-21 15:11:17 UTC
(rev 1477)
+++ trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2010-05-31 12:08:39 UTC
(rev 1478)
@@ -128,13 +128,6 @@
/**
- * The match string for identifying a session ID parameter.
- */
- private static final String match =
- ";" + Globals.SESSION_PARAMETER_NAME + "=";
-
-
- /**
* The string manager for this package.
*/
protected StringManager sm =
@@ -457,9 +450,6 @@
req.serverName().setString(proxyName);
}
- // Parse session Id
- parseSessionId(req, request);
-
// URI decoding
MessageBytes decodedURI = req.decodedURI();
decodedURI.duplicate(req.requestURI());
@@ -574,7 +564,10 @@
}
// Discard session id if SessionTrackingMode.URL is disabled
- if
(!request.getServletContext().getEffectiveSessionTrackingModes().contains(SessionTrackingMode.URL))
{
+ if
(request.getServletContext().getEffectiveSessionTrackingModes().contains(SessionTrackingMode.URL))
{
+ // Parse session Id
+ parseSessionId(req, request);
+ } else {
request.setRequestedSessionId(null);
request.setRequestedSessionURL(false);
}
@@ -587,7 +580,7 @@
if (request.isRequestedSessionIdFromURL()) {
// This is not optimal, but as this is not very common, it
// shouldn't matter
- redirectPath = redirectPath + ";" +
Globals.SESSION_PARAMETER_NAME + "="
+ redirectPath = redirectPath +
request.getContext().getSessionCookie().getPathParameterName()
+ request.getRequestedSessionId();
}
if (query != null) {
@@ -614,7 +607,8 @@
protected void parseSessionId(org.apache.coyote.Request req, Request request) {
ByteChunk uriBC = req.requestURI().getByteChunk();
- int semicolon = uriBC.indexOf(match, 0, match.length(), 0);
+ String pathParameterName =
request.getContext().getSessionCookie().getPathParameterName();
+ int semicolon = uriBC.indexOf(pathParameterName, 0, pathParameterName.length(),
0);
if (semicolon > 0) {
@@ -622,7 +616,7 @@
int start = uriBC.getStart();
int end = uriBC.getEnd();
- int sessionIdStart = semicolon + match.length();
+ int sessionIdStart = semicolon + pathParameterName.length();
int semicolon2 = uriBC.indexOf(';', sessionIdStart);
if (semicolon2 >= 0) {
request.setRequestedSessionId
@@ -663,9 +657,6 @@
return;
String cookieName = request.getContext().getSessionCookie().getName();
- if (cookieName == null) {
- cookieName = Globals.SESSION_COOKIE_NAME;
- }
for (int i = 0; i < count; i++) {
ServerCookie scookie = serverCookies.getCookie(i);
if (scookie.getName().equals(cookieName)) {
Modified: trunk/java/org/apache/catalina/connector/Request.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Request.java 2010-05-21 15:11:17 UTC (rev
1477)
+++ trunk/java/org/apache/catalina/connector/Request.java 2010-05-31 12:08:39 UTC (rev
1478)
@@ -1752,11 +1752,7 @@
return;
if (response != null) {
- String cookieName = context.getSessionCookie().getName();
- if (cookieName == null) {
- cookieName = Globals.SESSION_COOKIE_NAME;
- }
- Cookie cookie = new Cookie(cookieName, newSessionId);
+ Cookie cookie = new Cookie(context.getSessionCookie().getName(),
newSessionId);
configureSessionCookie(cookie);
response.addCookieInternal(cookie);
}
@@ -2594,11 +2590,7 @@
// If there was no cookie with the current session id, add a cookie to the
response
if ( (session != null) && context.getCookies()
&& !(isRequestedSessionIdFromCookie() &&
(session.getIdInternal().equals(getRequestedSessionId()))) ) {
- String cookieName = context.getSessionCookie().getName();
- if (cookieName == null) {
- cookieName = Globals.SESSION_COOKIE_NAME;
- }
- Cookie cookie = new Cookie(cookieName, session.getIdInternal());
+ Cookie cookie = new Cookie(context.getSessionCookie().getName(),
session.getIdInternal());
configureSessionCookie(cookie);
response.addCookieInternal(cookie);
}
Modified: trunk/java/org/apache/catalina/connector/Response.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Response.java 2010-05-21 15:11:17 UTC (rev
1477)
+++ trunk/java/org/apache/catalina/connector/Response.java 2010-05-31 12:08:39 UTC (rev
1478)
@@ -1513,7 +1513,7 @@
String file = url.getFile();
if ((file == null) || !file.startsWith(contextPath))
return (false);
- String tok = ";" + Globals.SESSION_PARAMETER_NAME + "=" +
session.getIdInternal();
+ String tok = request.getContext().getSessionCookie().getPathParameterName() +
session.getIdInternal();
if (file.indexOf(tok, contextPath.length()) >= 0)
return (false);
}
@@ -1649,9 +1649,7 @@
}
StringBuilder sb = new StringBuilder(path);
if( sb.length() > 0 ) { // jsessionid can't be first.
- sb.append(";");
- sb.append(Globals.SESSION_PARAMETER_NAME);
- sb.append("=");
+ sb.append(request.getContext().getSessionCookie().getPathParameterName());
sb.append(sessionId);
}
sb.append(anchor);
Modified: trunk/java/org/apache/catalina/deploy/SessionCookie.java
===================================================================
--- trunk/java/org/apache/catalina/deploy/SessionCookie.java 2010-05-21 15:11:17 UTC (rev
1477)
+++ trunk/java/org/apache/catalina/deploy/SessionCookie.java 2010-05-31 12:08:39 UTC (rev
1478)
@@ -21,6 +21,8 @@
import javax.servlet.SessionCookieConfig;
+import org.apache.catalina.Globals;
+
public class SessionCookie implements SessionCookieConfig, Serializable {
protected String domain = null;
@@ -29,7 +31,8 @@
protected boolean httpOnly = false;
protected boolean secure = false;
protected int maxAge = -1;
- protected String name = null;
+ protected String name = Globals.SESSION_COOKIE_NAME;
+ protected String pathParameterName = ";" + Globals.SESSION_PARAMETER_NAME +
"=";
public SessionCookie() {
}
@@ -87,7 +90,14 @@
}
public void setName(String name) {
- this.name = name;
+ if (name != null) {
+ this.name = name;
+ pathParameterName = ";" + name + "=";
+ }
}
+ public String getPathParameterName() {
+ return pathParameterName;
+ }
+
}
Modified: trunk/java/org/apache/catalina/realm/RealmBase.java
===================================================================
--- trunk/java/org/apache/catalina/realm/RealmBase.java 2010-05-21 15:11:17 UTC (rev
1477)
+++ trunk/java/org/apache/catalina/realm/RealmBase.java 2010-05-31 12:08:39 UTC (rev
1478)
@@ -960,9 +960,7 @@
String requestedSessionId = request.getRequestedSessionId();
if ((requestedSessionId != null) &&
request.isRequestedSessionIdFromURL()) {
- file.append(";");
- file.append(Globals.SESSION_PARAMETER_NAME);
- file.append("=");
+ file.append(request.getContext().getSessionCookie().getPathParameterName());
file.append(requestedSessionId);
}
String queryString = request.getQueryString();
Modified: trunk/java/org/apache/tomcat/util/buf/ByteChunk.java
===================================================================
--- trunk/java/org/apache/tomcat/util/buf/ByteChunk.java 2010-05-21 15:11:17 UTC (rev
1477)
+++ trunk/java/org/apache/tomcat/util/buf/ByteChunk.java 2010-05-31 12:08:39 UTC (rev
1478)
@@ -824,6 +824,86 @@
/**
+ * Returns the first instance of the given byte in the byte array between
+ * the specified start and end.
+ *
+ * @param bytes The byte array to search
+ * @param start The point to start searching from in the byte array
+ * @param end The point to stop searching in the byte array
+ * @param b The byte to search for
+ * @return The position of the first instance of the byte or -1 if the
+ * byte is not found.
+ */
+ public static int findByte(byte bytes[], int start, int end, byte b) {
+ int offset = start;
+ while (offset < end) {
+ if (bytes[offset] == b) {
+ return offset;
+ }
+ offset++;
+ }
+ return -1;
+ }
+
+ /**
+ * Returns the first instance of any of the given bytes in the byte array
+ * between the specified start and end.
+ *
+ * @param bytes The byte array to search
+ * @param start The point to start searching from in the byte array
+ * @param end The point to stop searching in the byte array
+ * @param b The array of bytes to search for
+ * @return The position of the first instance of the byte or -1 if the
+ * byte is not found.
+ */
+ public static int findBytes(byte bytes[], int start, int end, byte b[]) {
+ int blen = b.length;
+ int offset = start;
+ while (offset < end) {
+ for (int i = 0; i < blen; i++)
+ if (bytes[offset] == b[i]) {
+ return offset;
+ }
+ offset++;
+ }
+ return -1;
+ }
+
+ /**
+ * Returns the first instance of any byte that is not one of the given bytes
+ * in the byte array between the specified start and end.
+ *
+ * @param bytes The byte array to search
+ * @param start The point to start searching from in the byte array
+ * @param end The point to stop searching in the byte array
+ * @param c The list of bytes to search for
+ * @return The position of the first instance a byte that is not
+ * in the list of bytes to search for or -1 if no such byte
+ * is found.
+ */
+ public static int findNotBytes(byte bytes[], int start, int end, byte b[]) {
+ int blen = b.length;
+ int offset = start;
+ boolean found;
+
+ while (offset < end) {
+ found = true;
+ for (int i = 0; i < blen; i++) {
+ if (bytes[offset] == b[i]) {
+ found=false;
+ break;
+ }
+ }
+ if (found) {
+ return offset;
+ }
+ offset++;
+ }
+ return -1;
+ }
+
+
+ /**
* Convert specified String to a byte array. This ONLY WORKS for ascii, UTF chars
will be truncated.
*
* @param value to convert to byte array