From fc667718090d3c446a03fa5127727f4e8cbc19ed Mon Sep 17 00:00:00 2001 From: Johann Werner Date: Sat, 26 May 2012 10:54:51 +0200 Subject: [PATCH] replace usage of constant string 'wosid' by WOApplication.application().sessionIdKey() --- .../Ajax/AjaxExample/Sources/PushExample.java | 4 +- .../AjaxFileUpload.wo/AjaxFileUpload.wod | 2 +- .../er/ajax/AjaxFileUploadRequestHandler.java | 11 +-- .../er/ajax/AjaxFlexibleFileUpload.java | 11 +-- .../er/ajax/json/JSONRequestHandler.java | 17 ++-- .../json/client/AjaxStatelessJSONClient.java | 4 +- .../AjaxUpdaterForm.wo/AjaxUpdaterForm.wod | 2 +- .../MTAjaxFileUpload.wo/MTAjaxFileUpload.wod | 2 +- .../ERAttachmentRequestHandler.java | 12 +-- .../Sources/er/extensions/ERXExtensions.java | 53 +++++++++--- .../ERXComponentActionRedirector.java | 5 +- .../appserver/ERXDelayedRequestHandler.java | 11 +-- .../er/extensions/appserver/ERXRequest.java | 21 +++-- .../er/extensions/appserver/ERXWOContext.java | 80 +++++++++---------- .../ERXRestRequestHandler.java | 13 ++- .../rest/routes/components/ERXRouteURL.java | 4 +- .../er/imadaptor/InstantMessengerAdaptor.java | 12 +-- .../Sources/er/erxtest/DirectAction.java | 18 ++--- 18 files changed, 165 insertions(+), 117 deletions(-) diff --git a/Examples/Ajax/AjaxExample/Sources/PushExample.java b/Examples/Ajax/AjaxExample/Sources/PushExample.java index 1900fae7c3d..ffcbf5a0d51 100644 --- a/Examples/Ajax/AjaxExample/Sources/PushExample.java +++ b/Examples/Ajax/AjaxExample/Sources/PushExample.java @@ -3,6 +3,7 @@ import java.util.Set; import com.webobjects.appserver.WOActionResults; +import com.webobjects.appserver.WOApplication; import com.webobjects.appserver.WOComponent; import com.webobjects.appserver.WOContext; import com.webobjects.appserver.WOResponse; @@ -20,7 +21,8 @@ public PushExample(WOContext context) { } public String url() { - return context().urlWithRequestHandlerKey(AjaxPushRequestHandler.AjaxCometRequestHandlerKey, "test", "wosid=" + session().sessionID()); + return context().urlWithRequestHandlerKey(AjaxPushRequestHandler.AjaxCometRequestHandlerKey, "test", + WOApplication.application().sessionIdKey() + "=" + session().sessionID()); } @Override diff --git a/Frameworks/Ajax/Ajax/Components/AjaxFileUpload.wo/AjaxFileUpload.wod b/Frameworks/Ajax/Ajax/Components/AjaxFileUpload.wo/AjaxFileUpload.wod index 57655261ea1..d504784558b 100644 --- a/Frameworks/Ajax/Ajax/Components/AjaxFileUpload.wo/AjaxFileUpload.wod +++ b/Frameworks/Ajax/Ajax/Components/AjaxFileUpload.wo/AjaxFileUpload.wod @@ -25,7 +25,7 @@ HiddenID : WOGenericElement { HiddenWOSID : WOGenericElement { elementName = "input"; type = "hidden"; - name = "wosid"; + name = application.sessionIdKey; value = session.sessionID; } diff --git a/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxFileUploadRequestHandler.java b/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxFileUploadRequestHandler.java index b60c187ebc3..46e42cb7b55 100644 --- a/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxFileUploadRequestHandler.java +++ b/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxFileUploadRequestHandler.java @@ -62,7 +62,8 @@ public WOResponse handleRequest(WORequest request) { int streamLength = -1; try { - String wosid = request.cookieValueForKey("wosid"); + String sessionIdKey = WOApplication.application().sessionIdKey(); + String sessionId = request.cookieValueForKey(sessionIdKey); WOMultipartIterator multipartIterator = request.multipartIterator(); if (multipartIterator == null) { response.appendContentString("Already Consumed!"); @@ -71,8 +72,8 @@ public WOResponse handleRequest(WORequest request) { WOMultipartIterator.WOFormData formData = null; while ((formData = multipartIterator.nextFormData()) != null) { String name = formData.name(); - if ("wosid".equals(name)) { - wosid = formData.formValue(); + if (sessionIdKey.equals(name)) { + sessionId = formData.formValue(); } else if ("id".equals(name)) { uploadIdentifier = formData.formValue(); @@ -84,10 +85,10 @@ else if (formData.isFileUpload()) { break; } } - context._setRequestSessionID(wosid); + context._setRequestSessionID(sessionId); WOSession session = null; if (context._requestSessionID() != null) { - session = WOApplication.application().restoreSessionWithID(wosid, context); + session = WOApplication.application().restoreSessionWithID(sessionId, context); } File tempFile = File.createTempFile("AjaxFileUpload", ".tmp", _tempFileFolder); tempFile.deleteOnExit(); diff --git a/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxFlexibleFileUpload.java b/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxFlexibleFileUpload.java index 702ceabbbe9..b60df0bf781 100644 --- a/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxFlexibleFileUpload.java +++ b/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxFlexibleFileUpload.java @@ -3,6 +3,7 @@ import org.apache.log4j.Logger; import com.webobjects.appserver.WOActionResults; +import com.webobjects.appserver.WOApplication; import com.webobjects.appserver.WOContext; import com.webobjects.appserver.WOResponse; import com.webobjects.foundation.NSArray; @@ -77,7 +78,6 @@ public class AjaxFlexibleFileUpload extends AjaxFileUpload { public static interface Keys { public static final String name = "name"; - public static final String wosid = "wosid"; public static final String selectFileLabel = "selectFileLabel"; public static final String cancelLabel = "cancelLabel"; public static final String clearLabel = "clearLabel"; @@ -150,12 +150,13 @@ public String ajaxUploadScript() { } /** - * Builds the array of required additional AjaxUpload data items (wosid, id). + * Builds the array of required additional AjaxUpload data items (sessionIdKey, id). * - * @return array of required additional AjaxUpload data items (wosid, id). + * @return array of required additional AjaxUpload data items (sessionIdKey, id). */ protected NSArray _ajaxUploadData() { - NSMutableArray _data = new NSMutableArray("wosid:'" + this.session().sessionID() + "'"); + NSMutableArray _data = new NSMutableArray(WOApplication.application().sessionIdKey() + + ":'" + this.session().sessionID() + "'"); _data.addObject("id:'" + id() + "'"); @@ -507,7 +508,7 @@ public String uploadName() { * @return url sent to the iframe to cancel */ public String cancelUrl() { - NSDictionary queryParams = new NSDictionary(Boolean.FALSE, Keys.wosid); + NSDictionary queryParams = new NSDictionary(Boolean.FALSE, WOApplication.application().sessionIdKey()); String url = ERXWOContext._directActionURL(context(), "ERXDirectAction/closeHTTPSession", queryParams, ERXRequest.isRequestSecure(context().request())); if (log.isDebugEnabled()) log.debug("URL: " + url); return url; diff --git a/Frameworks/Ajax/Ajax/Sources/er/ajax/json/JSONRequestHandler.java b/Frameworks/Ajax/Ajax/Sources/er/ajax/json/JSONRequestHandler.java index 1b705d88e27..67de1173aa2 100644 --- a/Frameworks/Ajax/Ajax/Sources/er/ajax/json/JSONRequestHandler.java +++ b/Frameworks/Ajax/Ajax/Sources/er/ajax/json/JSONRequestHandler.java @@ -196,19 +196,20 @@ public WOResponse handleRequest(WORequest request) { try { String inputString = request.contentString(); JSONObject input = new JSONObject(inputString); - String wosid = request.cookieValueForKey("wosid"); - if (wosid == null) { + String sessionIdKey = WOApplication.application().sessionIdKey(); + String sessionId = request.cookieValueForKey(sessionIdKey); + if (sessionId == null) { ERXMutableURL url = new ERXMutableURL(); url.setQueryParameters(request.queryString()); - wosid = url.queryParameter("wosid"); - if (wosid == null && input.has("wosid")) { - wosid = input.getString("wosid"); + sessionId = url.queryParameter(sessionIdKey); + if (sessionId == null && input.has(sessionIdKey)) { + sessionId = input.getString(sessionIdKey); } } - context._setRequestSessionID(wosid); + context._setRequestSessionID(sessionId); WOSession session = null; if (context._requestSessionID() != null) { - session = WOApplication.application().restoreSessionWithID(wosid, context); + session = WOApplication.application().restoreSessionWithID(sessionId, context); } if (session != null) { session.awake(); @@ -276,7 +277,7 @@ public WOResponse handleRequest(WORequest request) { if (context._session() != null) { WOSession contextSession = context._session(); // If this is a new session, then we have to force it to be a cookie session - if (wosid == null) { + if (sessionId == null) { boolean storesIDsInCookies = contextSession.storesIDsInCookies(); try { contextSession.setStoresIDsInCookies(true); diff --git a/Frameworks/Ajax/Ajax/Sources/er/ajax/json/client/AjaxStatelessJSONClient.java b/Frameworks/Ajax/Ajax/Sources/er/ajax/json/client/AjaxStatelessJSONClient.java index 72401f34022..00d2371d17a 100644 --- a/Frameworks/Ajax/Ajax/Sources/er/ajax/json/client/AjaxStatelessJSONClient.java +++ b/Frameworks/Ajax/Ajax/Sources/er/ajax/json/client/AjaxStatelessJSONClient.java @@ -1,5 +1,6 @@ package er.ajax.json.client; +import com.webobjects.appserver.WOApplication; import com.webobjects.appserver.WOContext; import com.webobjects.appserver.WOResponse; @@ -57,7 +58,8 @@ public void appendToResponse(WOResponse woresponse, WOContext wocontext) { String queryString = null; if (wocontext.request().sessionID() != null && wocontext.session().storesIDsInURLs()) { - queryString = "wosid=" + wocontext.request().sessionID(); + String sessionIdKey = WOApplication.application().sessionIdKey(); + queryString = sessionIdKey + "=" + wocontext.request().sessionID(); } String componentName = jsonComponent(); diff --git a/Frameworks/Ajax/ERPrototaculous/Components/AjaxUpdaterForm.wo/AjaxUpdaterForm.wod b/Frameworks/Ajax/ERPrototaculous/Components/AjaxUpdaterForm.wo/AjaxUpdaterForm.wod index 42888e8cb03..0db6377c6a1 100644 --- a/Frameworks/Ajax/ERPrototaculous/Components/AjaxUpdaterForm.wo/AjaxUpdaterForm.wod +++ b/Frameworks/Ajax/ERPrototaculous/Components/AjaxUpdaterForm.wo/AjaxUpdaterForm.wod @@ -17,7 +17,7 @@ Contents: WOComponentContent { WOSID: WOHiddenField { value = session.sessionID; - name = "wosid"; + name = application.sessionIdKey; } FID: WOGenericElement { diff --git a/Frameworks/Ajax/MooTools/Components/Nonlocalized.lproj/MTAjaxFileUpload.wo/MTAjaxFileUpload.wod b/Frameworks/Ajax/MooTools/Components/Nonlocalized.lproj/MTAjaxFileUpload.wo/MTAjaxFileUpload.wod index 42290ec1571..2d2dd291ce3 100644 --- a/Frameworks/Ajax/MooTools/Components/Nonlocalized.lproj/MTAjaxFileUpload.wo/MTAjaxFileUpload.wod +++ b/Frameworks/Ajax/MooTools/Components/Nonlocalized.lproj/MTAjaxFileUpload.wo/MTAjaxFileUpload.wod @@ -26,7 +26,7 @@ HiddenID : WOGenericElement { HiddenWOSID : WOGenericElement { elementName = "input"; type = "hidden"; - name = "wosid"; + name = application.sessionIdKey; value = session.sessionID; } diff --git a/Frameworks/BusinessLogic/ERAttachment/Sources/er/attachment/ERAttachmentRequestHandler.java b/Frameworks/BusinessLogic/ERAttachment/Sources/er/attachment/ERAttachmentRequestHandler.java index 02502bc199c..a9a60b96ff5 100644 --- a/Frameworks/BusinessLogic/ERAttachment/Sources/er/attachment/ERAttachmentRequestHandler.java +++ b/Frameworks/BusinessLogic/ERAttachment/Sources/er/attachment/ERAttachmentRequestHandler.java @@ -77,14 +77,14 @@ public WOResponse handleRequest(WORequest request) { WOContext context = application.createContextForRequest(request); WOResponse response = application.createResponseInContext(context); - String wosid = (String) request.formValueForKey("wosid"); - if (wosid == null) { - wosid = request.cookieValueForKey("wosid"); + String sessionIdKey = WOApplication.application().sessionIdKey(); + String sessionId = (String) request.formValueForKey(sessionIdKey); + if (sessionId == null) { + sessionId = request.cookieValueForKey(sessionIdKey); } - context._setRequestSessionID(wosid); - WOSession session = null; + context._setRequestSessionID(sessionId); if (context._requestSessionID() != null) { - session = WOApplication.application().restoreSessionWithID(wosid, context); + WOApplication.application().restoreSessionWithID(sessionId, context); } try { ERXDynamicURL url = new ERXDynamicURL(request._uriDecomposed()); diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/ERXExtensions.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/ERXExtensions.java index dec1c71918d..0d4110111c0 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/ERXExtensions.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/ERXExtensions.java @@ -9,6 +9,7 @@ import java.io.File; import java.io.IOException; import java.lang.reflect.Method; +import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.util.Arrays; @@ -21,6 +22,7 @@ import org.apache.log4j.Logger; +import com.webobjects.appserver.WOApplication; import com.webobjects.appserver.WOSession; import com.webobjects.eoaccess.EOAttribute; import com.webobjects.eoaccess.EODatabase; @@ -76,6 +78,7 @@ import er.extensions.foundation.ERXArrayUtilities; import er.extensions.foundation.ERXConfigurationManager; import er.extensions.foundation.ERXFileUtilities; +import er.extensions.foundation.ERXMutableURL; import er.extensions.foundation.ERXPatcher; import er.extensions.foundation.ERXProperties; import er.extensions.foundation.ERXRuntimeUtilities; @@ -1091,20 +1094,46 @@ public static void addRandomizeDirectActionURL(StringBuffer daURL) { daURL.append(r); } } + /** - * Adds the session ID (wosid) for a given session to a given url. - * @param url to add wosid form value to. - * @return url with the addition of wosid form value + * Adds the session ID for a given session to a given URL. + * @param url URL string to add session ID form value to. + * @param session session object + * @return URL with the addition of session ID form value + * @deprecated use {@link #addSessionIdFormValue(String, WOSession)} */ - // FIXME: Should check to see if the wosid form value has already been set. - public static String addWosidFormValue(String url, WOSession s) { - String result= url; - if (result!=null && s!=null) { - result += ( result.indexOf("?") == -1 ? "?" : "&" ) + "wosid=" + s.sessionID(); - } else { - _log.warn("not adding sid: url="+url+" session="+s); - } - return result; + @Deprecated + public static String addWosidFormValue(String url, WOSession session) { + return addSessionIdFormValue(url, session); + } + + /** + * Adds the session ID for a given session to a given URL. + * + * @param urlString + * URL string to add session ID form value to + * @param session + * session object + * @return URL with the addition of session ID form value + */ + public static String addSessionIdFormValue(String urlString, WOSession session) { + if (urlString == null || session == null) { + _log.warn("not adding session ID: url=" + (urlString != null ? urlString : "") + " session=" + (session != null ? session : "")); + return urlString; + } + String sessionIdKey = WOApplication.application().sessionIdKey(); + try { + ERXMutableURL url = new ERXMutableURL(urlString); + if (!url.containsQueryParameter(sessionIdKey)) { + url.setQueryParameter(sessionIdKey, session.sessionID()); + } + return url.toExternalForm(); + } + catch (MalformedURLException e) { + _log.error("invalid URL string: " + urlString, e); + } + + return urlString; } /** diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXComponentActionRedirector.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXComponentActionRedirector.java index 8f0b9bbf1db..94df7a67e91 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXComponentActionRedirector.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXComponentActionRedirector.java @@ -222,8 +222,9 @@ public ERXComponentActionRedirector(Restorable r) { url = r.urlForCurrentState(); if(context.session().storesIDsInURLs()) { String argsChar = url.indexOf("?") >= 0? "&" : "?"; - if(url.indexOf("wosid=") < 0) { - url = url + argsChar + "wosid=" +sessionID; + String sessionIdKey = WOApplication.application().sessionIdKey(); + if(url.indexOf(sessionIdKey + "=") < 0) { + url = url + argsChar + sessionIdKey + "=" +sessionID; argsChar = "&"; } if(url.indexOf("wocid=") < 0) { diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXDelayedRequestHandler.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXDelayedRequestHandler.java index 21af3df99b9..37781a77d9c 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXDelayedRequestHandler.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXDelayedRequestHandler.java @@ -306,7 +306,7 @@ protected WOResponse handle(WORequest request, DelayedRequest delayedRequest, St String args = "id=" + id; String sessionID = request.sessionID(); if (sessionID != null) { - args += "&wosid=" + sessionID; + args += "&" + WOApplication.application().sessionIdKey() + "=" + sessionID; } args += "&__start=" + delayedRequest.start().getTime(); args += "&__time=" + System.currentTimeMillis(); @@ -366,14 +366,15 @@ protected WOResponse createErrorResponse(WORequest request) { * and you probably shouldn't do it either. The default implementation * redirect to the entry. * - * @param request + * @param request the request object + * @return 302 response */ protected WOResponse createStoppedResponse(WORequest request) { - final ERXApplication app = ERXApplication.erxApplication(); - String args = (request.sessionID() != null ? "wosid=" + request.sessionID() : ""); + String sessionIdKey = WOApplication.application().sessionIdKey(); + String args = (request.sessionID() != null ? sessionIdKey + "=" + request.sessionID() : ""); String url = request.applicationURLPrefix() + "?" + args; - WOResponse result = new WOResponse(); + ERXResponse result = new ERXResponse(); result.setHeader(url, "location"); result.setStatus(302); return result; diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXRequest.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXRequest.java index d2a14340848..260eb9e076f 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXRequest.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXRequest.java @@ -417,6 +417,8 @@ public NSDictionary cookieValues() { * content even if the request is supposed to be streaming and thus * very large. Will now return false if the request * handler is streaming. + * + * @return true if the session ID can be obtained from the form values or a cookie. */ @Override public boolean isSessionIDInRequest() { @@ -424,9 +426,8 @@ public boolean isSessionIDInRequest() { if (app.isStreamingRequestHandlerKey(requestHandlerKey())) { return false; - } else { - return super.isSessionIDInRequest(); } + return super.isSessionIDInRequest(); } @@ -435,10 +436,14 @@ public boolean isSessionIDInRequest() { * content even if the request is supposed to be streaming and thus * very large. Will now look for the session ID only in the cookie * values. + * + * @param inCookiesFirst + * define if session ID should be searched first in cookie */ @Override protected String _getSessionIDFromValuesOrCookie(boolean inCookiesFirst) { ERXApplication app = (ERXApplication)WOApplication.application(); + String sessionIdKey = WOApplication.application().sessionIdKey(); boolean wis = WOApplication.application().streamActionRequestHandlerKey().equals(requestHandlerKey()); boolean alternateStreaming = app.isStreamingRequestHandlerKey(requestHandlerKey()); @@ -446,16 +451,16 @@ protected String _getSessionIDFromValuesOrCookie(boolean inCookiesFirst) { String sessionID = null; if(inCookiesFirst) { - sessionID = cookieValueForKey("wosid"); + sessionID = cookieValueForKey(sessionIdKey); if(sessionID == null && !streaming) { - sessionID = stringFormValueForKey("wosid"); + sessionID = stringFormValueForKey(sessionIdKey); } } else { if(!streaming) { - sessionID = stringFormValueForKey("wosid"); + sessionID = stringFormValueForKey(sessionIdKey); } if(sessionID == null) { - sessionID = cookieValueForKey("wosid"); + sessionID = cookieValueForKey(sessionIdKey); } } return sessionID; @@ -464,6 +469,10 @@ protected String _getSessionIDFromValuesOrCookie(boolean inCookiesFirst) { /** * Utility method to set credentials for basic authorization. * + * @param userName + * the user name + * @param password + * the password */ public void setCredentials(String userName, String password) { String up = userName + ":" + password; diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXWOContext.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXWOContext.java index 66cb2cd4004..80e30264b06 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXWOContext.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXWOContext.java @@ -55,7 +55,9 @@ public void applicationDidHandleRequest(NSNotification n) { } /** - * Returns the existing session if any is given in the form values or url. + * Returns the existing session if any is given in the form values or URL. + * + * @return session for this request or null */ public WOSession existingSession() { String sessionID = _requestSessionID(); @@ -75,9 +77,6 @@ public boolean hasSession() { return existingSession() != null; } - /** - * Public constructor - */ public static NSMutableDictionary contextDictionary() { if (observer == null) { synchronized (ERXWOContext.class) { @@ -256,23 +255,23 @@ public String _urlWithRequestHandlerKey(String requestHandlerKey, String request /** * Returns a complete URL for the specified action. Works like * {@link WOContext#directActionURLForActionNamed} but has one extra - * parameter to specify whether or not to include the current Session ID - * (wosid) in the URL. Convenient if you embed the link for the direct - * action into an email message and don't want to keep the Session ID in it. + * parameter to specify whether or not to include the current session ID + * in the URL. Convenient if you embed the link for the direct + * action into an email message and don't want to keep the session ID in it. *

* actionName can be either an action -- "ActionName" -- or * an action on a class -- "ActionClass/ActionName". You can also specify * queryDict to be an NSDictionary which contains form values * as key/value pairs. includeSessionID indicates if you want - * to include the Session ID (wosid) in the URL. + * to include the session ID in the URL. * * @param actionName * String action name * @param queryDict * NSDictionary containing query key/value pairs * @param includeSessionID - * true: to include the Session ID (if has one),
- * false: not to include the Session ID + * true: to include the session ID (if has one),
+ * false: not to include the session ID * @return a String containing the URL for the specified action * @see WODirectAction */ @@ -285,23 +284,24 @@ public String directActionURLForActionNamed(String actionName, NSDictionary quer } /** - * Removes Session ID (wosid) query key/value pair from the given URL + * Removes session ID query key/value pair from the given URL * string. * * @param url * String URL - * @return a String with the Session ID removed + * @return a String with the session ID removed */ public static String stripSessionIDFromURL(String url) { if (url == null) return null; + String sessionIdKey = WOApplication.application().sessionIdKey(); int len = 1; - int startpos = url.indexOf("?wosid"); + int startpos = url.indexOf("?" + sessionIdKey); if (startpos < 0) { - startpos = url.indexOf("&wosid"); + startpos = url.indexOf("&" + sessionIdKey); } if (startpos < 0) { - startpos = url.indexOf("&wosid"); + startpos = url.indexOf("&" + sessionIdKey); len = 5; } @@ -513,9 +513,9 @@ public static String _directActionURL(WOContext context, String actionName, NSDi * @param directActionName * the direct action name * @param secure - * true = https, false = http, null = same as request + * true = https, false = http, null = same as request * @param includeSessionID - * if false, removes wosid from query parameters + * if false, removes session ID from query parameters * @return the constructed direct action URL */ public static String directActionUrl(WOContext context, String directActionName, Boolean secure, boolean includeSessionID) { @@ -530,13 +530,13 @@ public static String directActionUrl(WOContext context, String directActionName, * @param directActionName * the direct action name * @param key - * the query parameter key to add (or null to skip) + * the query parameter key to add (or null to skip) * @param value - * the query parameter value to add (or null to skip) + * the query parameter value to add (or null to skip) * @param secure - * true = https, false = http, null = same as request + * true = https, false = http, null = same as request * @param includeSessionID - * if false, removes wosid from query parameters + * if false, removes session ID from query parameters * @return the constructed direct action URL */ public static String directActionUrl(WOContext context, String directActionName, String key, String value, Boolean secure, boolean includeSessionID) { @@ -551,11 +551,11 @@ public static String directActionUrl(WOContext context, String directActionName, * @param directActionName * the direct action name * @param queryParameters - * the query parameters to append (or null) + * the query parameters to append (or null) * @param secure - * true = https, false = http, null = same as request + * true = https, false = http, null = same as request * @param includeSessionID - * if false, removes wosid from query parameters + * if false, removes session ID from query parameters * @return the constructed direct action URL */ public static String directActionUrl(WOContext context, String directActionName, NSDictionary queryParameters, Boolean secure, boolean includeSessionID) { @@ -568,21 +568,21 @@ public static String directActionUrl(WOContext context, String directActionName, * @param context * the context to generate the URL within * @param host - * the host name for the URL (or null for default) + * the host name for the URL (or null for default) * @param port - * the port number of the URL (or null for default) + * the port number of the URL (or null for default) * @param path - * the custom path prefix (or null for none) + * the custom path prefix (or null for none) * @param directActionName * the direct action name * @param key - * the query parameter key to add (or null to skip) + * the query parameter key to add (or null to skip) * @param value - * the query parameter value to add (or null to skip) + * the query parameter value to add (or null to skip) * @param secure - * true = https, false = http, null = same as request + * true = https, false = http, null = same as request * @param includeSessionID - * if false, removes wosid from query parameters + * if false, removes session ID from query parameters * @return the constructed direct action URL */ public static String directActionUrl(WOContext context, String host, Integer port, String path, String directActionName, String key, Object value, Boolean secure, boolean includeSessionID) { @@ -599,19 +599,19 @@ public static String directActionUrl(WOContext context, String host, Integer por * @param context * the context to generate the URL within * @param host - * the host name for the URL (or null for default) + * the host name for the URL (or null for default) * @param port - * the port number of the URL (or null for default) + * the port number of the URL (or null for default) * @param path - * the custom path prefix (or null for none) + * the custom path prefix (or null for none) * @param directActionName * the direct action name * @param queryParameters - * the query parameters to append (or null) + * the query parameters to append (or null) * @param secure - * true = https, false = http, null = same as request + * true = https, false = http, null = same as request * @param includeSessionID - * if false, removes wosid from query parameters + * if false, removes session ID from query parameters * @return the constructed direct action URL */ public static String directActionUrl(WOContext context, String host, Integer port, String path, String directActionName, NSDictionary queryParameters, Boolean secure, boolean includeSessionID) { @@ -638,7 +638,7 @@ public static String directActionUrl(WOContext context, String host, Integer por if (!customPath) { mu.setURL(ERXWOContext._directActionURL(context, directActionName, queryParameters, secureBool)); if (!includeSessionID) { - mu.removeQueryParameter("wosid"); + mu.removeQueryParameter(WOApplication.application().sessionIdKey()); } } else { @@ -652,7 +652,7 @@ public static String directActionUrl(WOContext context, String host, Integer por mu.setPath(path + directActionName); mu.setQueryParameters(queryParameters); if (includeSessionID && context.session().storesIDsInURLs()) { - mu.setQueryParameter("wosid", context.session().sessionID()); + mu.setQueryParameter(WOApplication.application().sessionIdKey(), context.session().sessionID()); } } @@ -692,7 +692,7 @@ public String safeElementID() { /** * Workaround for missing componentActionUrl(String) in 5.3. * @param context - * @return ajax action url + * @return ajax action URL */ public static String ajaxActionUrl(WOContext context) { String url = context.componentActionURL().replaceFirst( "/" + WOApplication.application().componentRequestHandlerKey() + "/", "/" +ERXApplication.erAjaxRequestHandlerKey() + "/"); diff --git a/Frameworks/EOF/ERRest/Sources/er/rest/entityDelegates/ERXRestRequestHandler.java b/Frameworks/EOF/ERRest/Sources/er/rest/entityDelegates/ERXRestRequestHandler.java index 88026d57001..f3f71449e59 100644 --- a/Frameworks/EOF/ERRest/Sources/er/rest/entityDelegates/ERXRestRequestHandler.java +++ b/Frameworks/EOF/ERRest/Sources/er/rest/entityDelegates/ERXRestRequestHandler.java @@ -389,7 +389,7 @@ protected EOEditingContext newEditingContext() { } /** - * Handle the incoming REST request. REST requests can have session ids associated with them as cookies or wosid + * Handle the incoming REST request. REST requests can have session ids associated with them as cookies or sessionIdKey * query string parameters. Right now rendering type is not supported, but ultimately the file extension of the * request will determine which renderer is used to render the response. * @@ -411,15 +411,12 @@ public WOResponse handleRequest(WORequest request) { path = path.substring(0, dotIndex); } - String wosid = null; - // if (wosid == null) { - wosid = request.cookieValueForKey("wosid"); - // } - woContext._setRequestSessionID(wosid); + String sessionId = request.cookieValueForKey(WOApplication.application().sessionIdKey()); + woContext._setRequestSessionID(sessionId); WOSession session = null; if (woContext._requestSessionID() != null) { - session = WOApplication.application().restoreSessionWithID(wosid, woContext); + session = WOApplication.application().restoreSessionWithID(sessionId, woContext); } if (session != null) { session.awake(); @@ -428,7 +425,7 @@ public WOResponse handleRequest(WORequest request) { if (woContext._session() != null) { WOSession contextSession = woContext._session(); // If this is a new session, then we have to force it to be a cookie session - if (wosid == null) { + if (sessionId == null) { boolean storesIDsInCookies = contextSession.storesIDsInCookies(); try { contextSession.setStoresIDsInCookies(true); diff --git a/Frameworks/EOF/ERRest/Sources/er/rest/routes/components/ERXRouteURL.java b/Frameworks/EOF/ERRest/Sources/er/rest/routes/components/ERXRouteURL.java index 39137a80f76..6fbd59d17e8 100644 --- a/Frameworks/EOF/ERRest/Sources/er/rest/routes/components/ERXRouteURL.java +++ b/Frameworks/EOF/ERRest/Sources/er/rest/routes/components/ERXRouteURL.java @@ -1,5 +1,6 @@ package er.rest.routes.components; +import com.webobjects.appserver.WOApplication; import com.webobjects.appserver.WOContext; import com.webobjects.eocontrol.EOEditingContext; import com.webobjects.foundation.NSArray; @@ -70,7 +71,8 @@ public String linkURL() { Object value = valueForBinding(bindingKey); String key = bindingKey.substring(1); if (value != null) { - if ("wosid".equals(key) && (Boolean.FALSE.equals(value) || "false".equals(value))) { + String sessionIdKey = WOApplication.application().sessionIdKey(); + if (sessionIdKey.equals(key) && (Boolean.FALSE.equals(value) || "false".equals(value))) { includeSessionID = false; } else { diff --git a/Frameworks/WOAdaptors/ERIMAdaptor/Sources/er/imadaptor/InstantMessengerAdaptor.java b/Frameworks/WOAdaptors/ERIMAdaptor/Sources/er/imadaptor/InstantMessengerAdaptor.java index cf3149914df..9385e2521d0 100644 --- a/Frameworks/WOAdaptors/ERIMAdaptor/Sources/er/imadaptor/InstantMessengerAdaptor.java +++ b/Frameworks/WOAdaptors/ERIMAdaptor/Sources/er/imadaptor/InstantMessengerAdaptor.java @@ -210,7 +210,7 @@ public void registerForEvents() { Iterator instantMessengerIter = _instantMessengers.entrySet().iterator(); while (instantMessengerIter.hasNext()) { Map.Entry instantMessengerEntry = (Map.Entry) instantMessengerIter.next(); - String screenName = (String) instantMessengerEntry.getKey(); + // String screenName = (String) instantMessengerEntry.getKey(); InstantMessengerConnection connection = (InstantMessengerConnection) instantMessengerEntry.getValue(); connection.connect(this); } @@ -226,7 +226,7 @@ public void unregisterForEvents() { Iterator instantMessengerIter = _instantMessengers.entrySet().iterator(); while (instantMessengerIter.hasNext()) { Map.Entry instantMessengerEntry = (Map.Entry) instantMessengerIter.next(); - String screenName = (String) instantMessengerEntry.getKey(); + // String screenName = (String) instantMessengerEntry.getKey(); InstantMessengerConnection connection = (InstantMessengerConnection) instantMessengerEntry.getValue(); connection.disconnect(); instantMessengerIter.remove(); @@ -253,7 +253,6 @@ public synchronized void messageReceived(IInstantMessenger instantMessenger, Str Conversation conversation = _instantMessengerConnectionNamed(screenName).conversationForBuddyNamed(buddyName, _conversationTimeout); String requestUrl = conversation.requestUrl(); if (requestUrl == null) { - String webserverConnectUrl = _application.webserverConnectURL(); String cgiAdaptorURL = _application.cgiAdaptorURL(); WODynamicURL imConversationUrl = new WODynamicURL(); @@ -291,7 +290,10 @@ public synchronized void messageReceived(IInstantMessenger instantMessenger, Str uri.append(WOURLEncoder.encode(rawMessage)); String sessionID = conversation.sessionID(); if (sessionID != null) { - uri.append("&wosid=" + sessionID); + uri.append("&"); + uri.append(WOApplication.application().sessionIdKey()); + uri.append("="); + uri.append(sessionID); } NSMutableDictionary headers = new NSMutableDictionary(); @@ -385,7 +387,7 @@ protected void removeExpiredConversations() { Iterator instantMessengerIter = _instantMessengers.entrySet().iterator(); while (instantMessengerIter.hasNext()) { Map.Entry instantMessengerEntry = (Map.Entry) instantMessengerIter.next(); - String screenName = (String) instantMessengerEntry.getKey(); + // String screenName = (String) instantMessengerEntry.getKey(); InstantMessengerConnection connection = (InstantMessengerConnection) instantMessengerEntry.getValue(); connection.removeExpiredConversations(_conversationTimeout); } diff --git a/Tests/ERXTest/Sources/er/erxtest/DirectAction.java b/Tests/ERXTest/Sources/er/erxtest/DirectAction.java index 0a0353ed0af..99ef47c8cc8 100644 --- a/Tests/ERXTest/Sources/er/erxtest/DirectAction.java +++ b/Tests/ERXTest/Sources/er/erxtest/DirectAction.java @@ -1,5 +1,4 @@ package er.erxtest; -// Generated by the WOLips Templateengine Plug-in at Jan 24, 2007 2:11:22 AM import java.io.IOException; import java.io.InputStream; @@ -7,6 +6,7 @@ import java.net.URL; import com.webobjects.appserver.WOActionResults; +import com.webobjects.appserver.WOApplication; import com.webobjects.appserver.WODirectAction; import com.webobjects.appserver.WORequest; import com.webobjects.foundation.NSDictionary; @@ -26,24 +26,24 @@ public WOActionResults defaultAction() { return pageWithName(Main.class.getName()); } - @SuppressWarnings("deprecation") -protected String urlForDirectActionNamed(String directActionName, String sessionID, NSDictionary parameters) { - context()._generateCompleteURLs(); + protected String urlForDirectActionNamed(String directActionName, String sessionID, NSDictionary parameters) { + context().generateCompleteURLs(); String url = context().directActionURLForActionNamed(directActionName, parameters); - context()._generateRelativeURLs(); + context().generateRelativeURLs(); + String sessionIdKey = WOApplication.application().sessionIdKey(); if (sessionID != null) { - int wosidIndex = url.indexOf("wosid="); - if (wosidIndex == -1) { + int sessionIdIndex = url.indexOf(sessionIdKey + "="); + if (sessionIdIndex == -1) { if (url.indexOf("?") == -1) { url += "?"; } else { url += "&"; } - url += "wosid=" + sessionID; + url += sessionIdKey + "=" + sessionID; } else { - url = url.replace("wosid=[^&]+", "wosid=" + sessionID); + url = url.replace(sessionIdKey + "=[^&]+", sessionIdKey + "=" + sessionID); } } return url;