[mapguide-commits] r7118 - in trunk/Tools/Maestro: MaestroAPITests OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.MaestroAPI.Http OSGeo.MapGuide.MaestroAPI.Native
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Tue Oct 16 03:47:59 PDT 2012
Author: jng
Date: 2012-10-16 03:47:59 -0700 (Tue, 16 Oct 2012)
New Revision: 7118
Modified:
trunk/Tools/Maestro/MaestroAPITests/HttpConnectionTests.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/RequestBuilder.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/MgServerConnectionBase.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Strings.Designer.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Strings.resx
Log:
#2019: Support creating http connection instances with an existing session id instead of username/password. Such connections will have session auto-recovery disabled as it is not possible without knowing what the original username/password is. Attempts to enable auto-recovery for such connections will throw an InvalidOperationException
Modified: trunk/Tools/Maestro/MaestroAPITests/HttpConnectionTests.cs
===================================================================
--- trunk/Tools/Maestro/MaestroAPITests/HttpConnectionTests.cs 2012-10-16 06:32:52 UTC (rev 7117)
+++ trunk/Tools/Maestro/MaestroAPITests/HttpConnectionTests.cs 2012-10-16 10:47:59 UTC (rev 7118)
@@ -348,5 +348,29 @@
ResourceDataType.File,
resSvc.GetResourceData(source, dataName));
}
+
+ [Test]
+ public void TestCreateFromExistingSession()
+ {
+ var conn = ConnectionUtil.CreateTestHttpConnection();
+ var conn2 = ConnectionProviderRegistry.CreateConnection("Maestro.Http",
+ HttpServerConnection.PARAM_SESSION, conn.SessionID,
+ HttpServerConnection.PARAM_URL, conn.GetCustomProperty(HttpServerConnection.PROP_BASE_URL).ToString(),
+ HttpServerConnection.PARAM_UNTESTED, "true");
+
+ //This connection cannot restart sessions, and cannot be set to restart sessions
+ Assert.False(conn2.AutoRestartSession);
+ Assert.Throws<InvalidOperationException>(() => { conn2.AutoRestartSession = true; });
+
+ //Exercise an API to check the minimum parameters are met
+ try
+ {
+ var result = conn2.ResourceService.GetRepositoryResources();
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.ToString());
+ }
+ }
}
}
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/MgServerConnectionBase.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/MgServerConnectionBase.cs 2012-10-16 06:32:52 UTC (rev 7117)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/MgServerConnectionBase.cs 2012-10-16 10:47:59 UTC (rev 7118)
@@ -76,6 +76,7 @@
{
m_username = null;
m_password = null;
+ _canAutoRestartSession = true;
}
#region Session Management
@@ -86,10 +87,27 @@
virtual public bool AutoRestartSession
{
get { return m_autoRestartSession; }
- set { m_autoRestartSession = value; }
+ set
+ {
+ if (value && !_canAutoRestartSession)
+ throw new InvalidOperationException(Strings.ErrorConnectionCannotAutoRestartSession);
+ m_autoRestartSession = value;
+ }
}
+ protected bool _canAutoRestartSession;
+
/// <summary>
+ /// Indicates this connection cannot use session recovery, normally due to the fact the connection was initialized
+ /// with just a session id.
+ /// </summary>
+ protected void DisableAutoSessionRecovery()
+ {
+ this.AutoRestartSession = false;
+ _canAutoRestartSession = false;
+ }
+
+ /// <summary>
/// Determines if an exception is a "Session Expired" exception.
/// </summary>
/// <param name="ex">The exception to evaluate</param>
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Strings.Designer.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Strings.Designer.cs 2012-10-16 06:32:52 UTC (rev 7117)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Strings.Designer.cs 2012-10-16 10:47:59 UTC (rev 7118)
@@ -693,6 +693,15 @@
}
/// <summary>
+ /// Looks up a localized string similar to This connection cannot auto-restart sessions. Most likely because this connection was just initialized with a session id and not with the credentials required to rebuild a new session.
+ /// </summary>
+ public static string ErrorConnectionCannotAutoRestartSession {
+ get {
+ return ResourceManager.GetString("ErrorConnectionCannotAutoRestartSession", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Could not determine symbol type.
/// </summary>
public static string ErrorCouldNotDetermineSymbolType {
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Strings.resx
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Strings.resx 2012-10-16 06:32:52 UTC (rev 7117)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Strings.resx 2012-10-16 10:47:59 UTC (rev 7118)
@@ -3342,4 +3342,7 @@
<data name="PickTxt" xml:space="preserve">
<value>Text Files</value>
</data>
+ <data name="ErrorConnectionCannotAutoRestartSession" xml:space="preserve">
+ <value>This connection cannot auto-restart sessions. Most likely because this connection was just initialized with a session id and not with the credentials required to rebuild a new session</value>
+ </data>
</root>
\ No newline at end of file
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs 2012-10-16 06:32:52 UTC (rev 7117)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs 2012-10-16 10:47:59 UTC (rev 7118)
@@ -143,12 +143,13 @@
private void InitConnection(Uri hosturl, string sessionid, string locale, bool allowUntestedVersion, string geoRestUrl, string geoRestConfigPath)
{
+ DisableAutoSessionRecovery();
if (!string.IsNullOrEmpty(geoRestUrl))
{
_geoRestConn = new GeoRestConnection(geoRestUrl, geoRestConfigPath);
}
- m_reqBuilder = new RequestBuilder(hosturl, locale, sessionid);
+ m_reqBuilder = new RequestBuilder(hosturl, locale, sessionid, true);
string req = m_reqBuilder.GetSiteVersion();
SiteVersion sv = null;
try
@@ -168,7 +169,7 @@
if (!tmp.EndsWith("/"))
tmp += "/";
hosturl = new Uri(tmp + "mapagent/mapagent.fcgi");
- m_reqBuilder = new RequestBuilder(hosturl, locale, sessionid);
+ m_reqBuilder = new RequestBuilder(hosturl, locale, sessionid, true);
req = m_reqBuilder.GetSiteVersion();
sv = (SiteVersion)DeserializeObject(typeof(SiteVersion), OpenRead(req));
ok = true;
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/RequestBuilder.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/RequestBuilder.cs 2012-10-16 06:32:52 UTC (rev 7117)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Http/RequestBuilder.cs 2012-10-16 10:47:59 UTC (rev 7118)
@@ -36,19 +36,27 @@
private string m_sessionID = null;
private string m_locale = null;
- internal RequestBuilder(Uri hosturi, string locale, string sessionid)
+ internal RequestBuilder(Uri hosturi, string locale, string sessionid, bool bIncludeSessionIdInRequests)
{
m_hosturi = hosturi.AbsoluteUri;
m_locale = locale;
m_sessionID = sessionid;
m_userAgent += " v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
+ this.IncludeSessionIdInRequestParams = bIncludeSessionIdInRequests;
}
internal RequestBuilder(Uri hosturi, string locale)
- : this (hosturi, locale, null)
+ : this (hosturi, locale, null, false)
{
}
+ /// <summary>
+ /// Indicates if the session id should be included as the SESSION request parameter. This needs to be set to true if
+ /// the HTTP connection was initialized with only a session id, otherwise it can be set to false if the connection
+ /// was initialized with a username/password as requests use the already established authenticated credentials.
+ /// </summary>
+ internal bool IncludeSessionIdInRequestParams { get; private set; }
+
internal string Locale { get { return m_locale; } }
internal string CreateSession()
@@ -205,16 +213,24 @@
set { m_sessionID = value; }
}
+ private string EncodeParameters(NameValueCollection param, bool bAddSessionId)
+ {
+ if (bAddSessionId && this.IncludeSessionIdInRequestParams && param["SESSION"] == null)
+ param["SESSION"] = m_sessionID;
+
+ System.Text.StringBuilder sb = new System.Text.StringBuilder();
+ foreach (string s in param.Keys)
+ {
+ sb.Append(EncodeParameter(s, param[s]));
+ sb.Append("&");
+ }
+
+ return sb.ToString(0, sb.Length - 1);
+ }
+
private string EncodeParameters(NameValueCollection param)
{
- System.Text.StringBuilder sb = new System.Text.StringBuilder();
- foreach(string s in param.Keys)
- {
- sb.Append(EncodeParameter(s, param[s]));
- sb.Append("&");
- }
-
- return sb.ToString(0, sb.Length - 1);
+ return EncodeParameters(param, true);
}
private string EncodeParameter(string name, string value)
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs 2012-10-16 06:32:52 UTC (rev 7117)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs 2012-10-16 10:47:59 UTC (rev 7118)
@@ -125,6 +125,7 @@
m_con = new MgSiteConnection();
m_con.Open(mgui);
m_sessionId = sessionid;
+ DisableAutoSessionRecovery();
}
private void InitConnection(string configFile, string username, string password, string locale)
More information about the mapguide-commits
mailing list