[mapguide-commits] r10270 - in branches/4.0/MgDev: UnitTest/WebTier/MapAgent/MapAgentForms Web/src/HttpHandler Web/src/WebTestRunner

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Nov 5 23:47:47 PST 2026


Author: jng
Date: 2026-11-05 23:47:46 -0800 (Thu, 05 Nov 2026)
New Revision: 10270

Added:
   branches/4.0/MgDev/Web/src/WebTestRunner/HttpParameterTest.cpp
Removed:
   branches/4.0/MgDev/UnitTest/WebTier/MapAgent/MapAgentForms/executesqlqueryform.html
Modified:
   branches/4.0/MgDev/UnitTest/WebTier/MapAgent/MapAgentForms/featureserviceapi.html
   branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoBinaryOperation.cpp
   branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoBoundary.cpp
   branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoBuffer.cpp
   branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoConvexHull.cpp
   branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoSimplify.cpp
   branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoTessellate.cpp
   branches/4.0/MgDev/Web/src/HttpHandler/HttpGetLongTransactions.cpp
   branches/4.0/MgDev/Web/src/HttpHandler/HttpGetMapImage.cpp
   branches/4.0/MgDev/Web/src/HttpHandler/HttpGetSpatialContexts.cpp
   branches/4.0/MgDev/Web/src/HttpHandler/ReaderByteSourceImpl.cpp
   branches/4.0/MgDev/Web/src/WebTestRunner/CMakeLists.txt
   branches/4.0/MgDev/Web/src/WebTestRunner/WebTestRunner.vcxproj
   branches/4.0/MgDev/Web/src/WebTestRunner/WebTestRunner.vcxproj.filters
Log:
Fix MapAgent parameter handling and the PropertySet JSON conversion

- Match FORMAT case-insensitively in the GEO.* operations and reject a value that is not WKT or
  GEOJSON. Six handlers read FORMAT (Boundary, BinaryOperation, Buffer, ConvexHull, Simplify,
  Tessellate); four of them never checked it, so both "FORMAT=wkt" and "FORMAT=BOGUS" produced a
  200 with an empty body, and the two that did check compared against upper case only.
- Require FORMAT for GETMAPIMAGE. Without it the request reached the rendering service with an
  empty format and failed there; it is now rejected by the agent.
- Treat a missing ACTIVEONLY as false for GETSPATIALCONTEXTS and GETLONGTRANSACTIONS. The parameter
  is optional, but an empty value fell into the range check and threw MgInvalidArgumentException.
- Fix the non-clean JSON of SELECTAGGREGATES. MgReaderByteSourceImpl reused one buffer for the
  header and then for the first record, and CurrentToStringUtf8 appends rather than replaces, so
  the converter was handed a document with two root elements and kept only the first: the record
  came out as a second copy of the property definitions
  ("Properties":[{"PropertyDefinitions":...}]) instead of the row's property collection. This is
  visible whenever the header and the first record are emitted by the same Read() call, which is
  what a small result set does.
- Remove the ExecuteSqlQuery form and its link from the map agent forms. Support for the operation
  has been removed.

Add WebTestRunner/HttpParameterTest.cpp ([HttpHandler]) covering the four handler fixes. It
bootstraps the Sheboygan sample package from MG_TEST_DATA_PATH when the Library does not have it,
which also lets the WFS and WMS cases in OgcTest succeed: they reference Library://Samples/Sheboygan
and nothing previously put it in the repository.

Fixes #2900

Deleted: branches/4.0/MgDev/UnitTest/WebTier/MapAgent/MapAgentForms/executesqlqueryform.html
===================================================================
--- branches/4.0/MgDev/UnitTest/WebTier/MapAgent/MapAgentForms/executesqlqueryform.html	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/UnitTest/WebTier/MapAgent/MapAgentForms/executesqlqueryform.html	2026-11-06 07:47:46 UTC (rev 10270)
@@ -1,34 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<html>
-    <head>
-        <title></title>
-        <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
-        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
-        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-        <script type="text/javascript" src="setactiontarget.js" >
-        </script>
-    </head>
-    <body>
-        <form name="input" action="" method="get" ID="Form1">
-        <b>Operation:</b>
-        <input type="text" name="OPERATION" value="EXECUTESQLQUERY" size="50" ID="Text1">
-        <p> Version:
-        <input type="text" name="VERSION" value="1.0.0" size="10" ID="Text2">
-        <p> Locale:
-        <input type="text" name="LOCALE" value="en" size="10" ID="Text4">
-        <p> Client Agent:
-        <input type="text" name="CLIENTAGENT" value="MapGuide Developer" size="100">
-        <p> Resource ID:
-        <input type="text" name="RESOURCEID" value="Library://Test/Features/Parcel.DrawingSource" size="100" ID="Text5">
-        <p> Sql Statement:
-        <input type="text" name="SQL" value="" size="100" ID="Text6">
-        <p> Format:
-		<select name="FORMAT">
-		<option value="text/xml">text/xml</option>
-		<option value="application/json">application/json</option>
-		</select>
-        <p>
-        <input type="submit" value="Submit" onclick="SetActionTarget()"> <input type="reset">
-        </form>
-    </body>
-</html>

Modified: branches/4.0/MgDev/UnitTest/WebTier/MapAgent/MapAgentForms/featureserviceapi.html
===================================================================
--- branches/4.0/MgDev/UnitTest/WebTier/MapAgent/MapAgentForms/featureserviceapi.html	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/UnitTest/WebTier/MapAgent/MapAgentForms/featureserviceapi.html	2026-11-06 07:47:46 UTC (rev 10270)
@@ -21,8 +21,6 @@
                 <A href="selectfeaturesform.html" target="showform">SelectFeatures</A>
             <LI>
                 <A href="selectaggregatesform.html" target="showform">SelectAggregates</A>
-            <LI>
-                <A href="executesqlqueryform.html" target="showform">ExecuteSqlQuery</A>
                 <P></P>
             <LI>
                 <A href="getspatialcontextsform.html" target="showform">GetSpatialContexts</A>

Modified: branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoBinaryOperation.cpp
===================================================================
--- branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoBinaryOperation.cpp	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoBinaryOperation.cpp	2026-11-06 07:47:46 UTC (rev 10270)
@@ -28,7 +28,9 @@
     m_geomWKT_A = params->GetParameterValue(MgHttpResourceStrings::reqGeoA);
     m_geomWKT_B = params->GetParameterValue(MgHttpResourceStrings::reqGeoB);
     m_operator = params->GetParameterValue(MgHttpResourceStrings::reqGeoOperator);
-    m_format = params->GetParameterValue(MgHttpResourceStrings::reqGeoFormat);
+    // FORMAT is matched case-insensitively, so normalise it once here: the checks in Execute
+    // and the comparisons against the supported values then behave the same for any casing.
+    m_format = MgUtil::ToUpper(params->GetParameterValue(MgHttpResourceStrings::reqGeoFormat));
     m_coordinateSystem = params->GetParameterValue(MgHttpResourceStrings::reqGeoCoordinateSystem);
     m_transformTo = params->GetParameterValue(MgHttpResourceStrings::reqGeoTransformTo);
     m_precision = -1;
@@ -54,6 +56,16 @@
     // Check common parameters
     ValidateCommonParameters();
 
+    if (m_format != L"WKT" && m_format != L"GEOJSON")
+    {
+        MgStringCollection arguments;
+        arguments.Add(MgHttpResourceStrings::reqGeoFormat);
+        arguments.Add(m_format);
+
+        throw new MgException(MgExceptionCodes::MgInvalidArgumentException, L"MgHttpGeoBinaryOperation.Execute",
+            __LINE__, __WFILE__, &arguments, L"MgInvalidValueOutsideRange", NULL);
+    }
+
     Ptr<MgWktReaderWriter> wktRw = new MgWktReaderWriter();
     Ptr<MgGeometry> geomA = wktRw->Read(m_geomWKT_A);
     Ptr<MgGeometry> geomB = wktRw->Read(m_geomWKT_B);

Modified: branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoBoundary.cpp
===================================================================
--- branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoBoundary.cpp	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoBoundary.cpp	2026-11-06 07:47:46 UTC (rev 10270)
@@ -25,7 +25,9 @@
     InitializeCommonParameters(hRequest);
     Ptr<MgHttpRequestParam> params = hRequest->GetRequestParam();
     m_geomWKT = params->GetParameterValue(MgHttpResourceStrings::reqFeatGeometry);
-    m_format = params->GetParameterValue(MgHttpResourceStrings::reqGeoFormat);
+    // FORMAT is matched case-insensitively, so normalise it once here: the checks in Execute
+    // and the comparisons against the supported values then behave the same for any casing.
+    m_format = MgUtil::ToUpper(params->GetParameterValue(MgHttpResourceStrings::reqGeoFormat));
     m_coordinateSystem = params->GetParameterValue(MgHttpResourceStrings::reqGeoCoordinateSystem);
     m_transformTo = params->GetParameterValue(MgHttpResourceStrings::reqGeoTransformTo);
     m_precision = -1;
@@ -51,6 +53,16 @@
     // Check common parameters
     ValidateCommonParameters();
 
+    if (m_format != L"WKT" && m_format != L"GEOJSON")
+    {
+        MgStringCollection arguments;
+        arguments.Add(MgHttpResourceStrings::reqGeoFormat);
+        arguments.Add(m_format);
+
+        throw new MgException(MgExceptionCodes::MgInvalidArgumentException, L"MgHttpGeoBoundary.Execute",
+            __LINE__, __WFILE__, &arguments, L"MgInvalidValueOutsideRange", NULL);
+    }
+
     if (m_geomWKT.empty())
     {
         MgStringCollection arguments;

Modified: branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoBuffer.cpp
===================================================================
--- branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoBuffer.cpp	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoBuffer.cpp	2026-11-06 07:47:46 UTC (rev 10270)
@@ -28,7 +28,9 @@
     m_geomWKT = params->GetParameterValue(MgHttpResourceStrings::reqFeatGeometry);
     m_units = params->GetParameterValue(MgHttpResourceStrings::reqGeoBufferUnits);
     m_distance = MgUtil::StringToDouble(params->GetParameterValue(MgHttpResourceStrings::reqGeoBufferDistance));
-    m_format = params->GetParameterValue(MgHttpResourceStrings::reqGeoFormat);
+    // FORMAT is matched case-insensitively, so normalise it once here: the checks in Execute
+    // and the comparisons against the supported values then behave the same for any casing.
+    m_format = MgUtil::ToUpper(params->GetParameterValue(MgHttpResourceStrings::reqGeoFormat));
     m_coordinateSystem = params->GetParameterValue(MgHttpResourceStrings::reqGeoCoordinateSystem);
     m_transformTo = params->GetParameterValue(MgHttpResourceStrings::reqGeoTransformTo);
     m_precision = -1;

Modified: branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoConvexHull.cpp
===================================================================
--- branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoConvexHull.cpp	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoConvexHull.cpp	2026-11-06 07:47:46 UTC (rev 10270)
@@ -25,7 +25,9 @@
     InitializeCommonParameters(hRequest);
     Ptr<MgHttpRequestParam> params = hRequest->GetRequestParam();
     m_geomWKT = params->GetParameterValue(MgHttpResourceStrings::reqFeatGeometry);
-    m_format = params->GetParameterValue(MgHttpResourceStrings::reqGeoFormat);
+    // FORMAT is matched case-insensitively, so normalise it once here: the checks in Execute
+    // and the comparisons against the supported values then behave the same for any casing.
+    m_format = MgUtil::ToUpper(params->GetParameterValue(MgHttpResourceStrings::reqGeoFormat));
     m_coordinateSystem = params->GetParameterValue(MgHttpResourceStrings::reqGeoCoordinateSystem);
     m_transformTo = params->GetParameterValue(MgHttpResourceStrings::reqGeoTransformTo);
     m_precision = -1;
@@ -51,6 +53,16 @@
     // Check common parameters
     ValidateCommonParameters();
 
+    if (m_format != L"WKT" && m_format != L"GEOJSON")
+    {
+        MgStringCollection arguments;
+        arguments.Add(MgHttpResourceStrings::reqGeoFormat);
+        arguments.Add(m_format);
+
+        throw new MgException(MgExceptionCodes::MgInvalidArgumentException, L"MgHttpGeoConvexHull.Execute",
+            __LINE__, __WFILE__, &arguments, L"MgInvalidValueOutsideRange", NULL);
+    }
+
     if (m_geomWKT.empty())
     {
         MgStringCollection arguments;

Modified: branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoSimplify.cpp
===================================================================
--- branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoSimplify.cpp	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoSimplify.cpp	2026-11-06 07:47:46 UTC (rev 10270)
@@ -27,7 +27,9 @@
     m_geomWKT = params->GetParameterValue(MgHttpResourceStrings::reqFeatGeometry);
     m_algorithm = MgUtil::StringToInt32(params->GetParameterValue(MgHttpResourceStrings::reqGeoAlgorithm));
     m_tolerance = MgUtil::StringToDouble(params->GetParameterValue(MgHttpResourceStrings::reqGeoTolerance));
-    m_format = params->GetParameterValue(MgHttpResourceStrings::reqGeoFormat);
+    // FORMAT is matched case-insensitively, so normalise it once here: the checks in Execute
+    // and the comparisons against the supported values then behave the same for any casing.
+    m_format = MgUtil::ToUpper(params->GetParameterValue(MgHttpResourceStrings::reqGeoFormat));
     m_coordinateSystem = params->GetParameterValue(MgHttpResourceStrings::reqGeoCoordinateSystem);
     m_transformTo = params->GetParameterValue(MgHttpResourceStrings::reqGeoTransformTo);
     m_precision = -1;

Modified: branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoTessellate.cpp
===================================================================
--- branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoTessellate.cpp	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/Web/src/HttpHandler/HttpGeoTessellate.cpp	2026-11-06 07:47:46 UTC (rev 10270)
@@ -25,7 +25,9 @@
     InitializeCommonParameters(hRequest);
     Ptr<MgHttpRequestParam> params = hRequest->GetRequestParam();
     m_geomWKT = params->GetParameterValue(MgHttpResourceStrings::reqFeatGeometry);
-    m_format = params->GetParameterValue(MgHttpResourceStrings::reqGeoFormat);
+    // FORMAT is matched case-insensitively, so normalise it once here: the checks in Execute
+    // and the comparisons against the supported values then behave the same for any casing.
+    m_format = MgUtil::ToUpper(params->GetParameterValue(MgHttpResourceStrings::reqGeoFormat));
     m_coordinateSystem = params->GetParameterValue(MgHttpResourceStrings::reqGeoCoordinateSystem);
     m_transformTo = params->GetParameterValue(MgHttpResourceStrings::reqGeoTransformTo);
     m_precision = -1;
@@ -51,6 +53,16 @@
     // Check common parameters
     ValidateCommonParameters();
 
+    if (m_format != L"WKT" && m_format != L"GEOJSON")
+    {
+        MgStringCollection arguments;
+        arguments.Add(MgHttpResourceStrings::reqGeoFormat);
+        arguments.Add(m_format);
+
+        throw new MgException(MgExceptionCodes::MgInvalidArgumentException, L"MgHttpGeoTessellate.Execute",
+            __LINE__, __WFILE__, &arguments, L"MgInvalidValueOutsideRange", NULL);
+    }
+
     if (m_geomWKT.empty())
     {
         MgStringCollection arguments;

Modified: branches/4.0/MgDev/Web/src/HttpHandler/HttpGetLongTransactions.cpp
===================================================================
--- branches/4.0/MgDev/Web/src/HttpHandler/HttpGetLongTransactions.cpp	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/Web/src/HttpHandler/HttpGetLongTransactions.cpp	2026-11-06 07:47:46 UTC (rev 10270)
@@ -40,10 +40,11 @@
 
     MG_HTTP_HANDLER_TRY()
 
-    if (activeOnly == L"1")
+    // ACTIVEONLY is optional: leaving it out means "all long transactions"
+    if (activeOnly.empty() || activeOnly == L"0")
+        m_activeOnly = false;
+    else if (activeOnly == L"1")
         m_activeOnly = true;
-    else if (activeOnly == L"0")
-        m_activeOnly = false;
     else if (activeOnly.empty())
         m_activeOnly = false;
     else

Modified: branches/4.0/MgDev/Web/src/HttpHandler/HttpGetMapImage.cpp
===================================================================
--- branches/4.0/MgDev/Web/src/HttpHandler/HttpGetMapImage.cpp	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/Web/src/HttpHandler/HttpGetMapImage.cpp	2026-11-06 07:47:46 UTC (rev 10270)
@@ -79,6 +79,18 @@
     // Check common parameters
     ValidateCommonParameters();
 
+    // FORMAT is required: without it the request used to reach the rendering service with an
+    // empty format and fail there
+    if (m_mapFormat.empty())
+    {
+        MgStringCollection arguments;
+        arguments.Add(MgHttpResourceStrings::reqRenderingFormat);
+        arguments.Add(MgResources::BlankArgument);
+
+        throw new MgException(MgExceptionCodes::MgInvalidArgumentException, L"MgHttpGetMapImage.Execute",
+            __LINE__, __WFILE__, &arguments, L"MgStringEmpty", NULL);
+    }
+
     STRING sessionId = m_userInfo->GetMgSessionId();
 
     Ptr<MgResourceService> resourceService = dynamic_cast<MgResourceService*>(CreateService(MgServiceType::ResourceService));

Modified: branches/4.0/MgDev/Web/src/HttpHandler/HttpGetSpatialContexts.cpp
===================================================================
--- branches/4.0/MgDev/Web/src/HttpHandler/HttpGetSpatialContexts.cpp	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/Web/src/HttpHandler/HttpGetSpatialContexts.cpp	2026-11-06 07:47:46 UTC (rev 10270)
@@ -40,10 +40,11 @@
 
     MG_HTTP_HANDLER_TRY()
 
-    if (activeOnly == L"1")
+    // ACTIVEONLY is optional: leaving it out means "all spatial contexts"
+    if (activeOnly.empty() || activeOnly == L"0")
+        m_activeOnly = false;
+    else if (activeOnly == L"1")
         m_activeOnly = true;
-    else if (activeOnly == L"0")
-        m_activeOnly = false;
     else
     {
         MgStringCollection arguments;

Modified: branches/4.0/MgDev/Web/src/HttpHandler/ReaderByteSourceImpl.cpp
===================================================================
--- branches/4.0/MgDev/Web/src/HttpHandler/ReaderByteSourceImpl.cpp	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/Web/src/HttpHandler/ReaderByteSourceImpl.cpp	2026-11-06 07:47:46 UTC (rev 10270)
@@ -222,6 +222,12 @@
                 }
                 else
                 {
+                    // buf also holds the header XML when the header and the first record are
+                    // emitted by the same Read() call, and CurrentToStringUtf8 appends rather
+                    // than replaces. Left as it is, the converter is handed a document with two
+                    // root elements and keeps only the first, so the record came out as a copy
+                    // of the property definitions.
+                    buf.clear();
                     m_reader->CurrentToStringUtf8(buf, m_xform);
                     //The body is a valid full XML element, so no need for gymnastics like its
                     //surrounding elements

Modified: branches/4.0/MgDev/Web/src/WebTestRunner/CMakeLists.txt
===================================================================
--- branches/4.0/MgDev/Web/src/WebTestRunner/CMakeLists.txt	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/Web/src/WebTestRunner/CMakeLists.txt	2026-11-06 07:47:46 UTC (rev 10270)
@@ -19,6 +19,7 @@
 
 set(MgWebTestRunner_SRCS
     GeoJsonTest.cpp
+    HttpParameterTest.cpp
     main.cpp
     OgcTest.cpp
     TestListener.cpp

Added: branches/4.0/MgDev/Web/src/WebTestRunner/HttpParameterTest.cpp
===================================================================
--- branches/4.0/MgDev/Web/src/WebTestRunner/HttpParameterTest.cpp	                        (rev 0)
+++ branches/4.0/MgDev/Web/src/WebTestRunner/HttpParameterTest.cpp	2026-11-06 07:47:46 UTC (rev 10270)
@@ -0,0 +1,250 @@
+//
+//  Copyright (C) 2004-2026 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#include "catch.hpp"
+
+#include "MapGuideCommon.h"
+#include "HttpHandler.h"
+
+#include <cstdlib>
+#include <initializer_list>
+#include <string>
+#include <utility>
+
+// Coverage for the request-handling rules that used to be enforced inconsistently:
+//
+//   GEO.*          FORMAT is matched case-insensitively, and an unsupported value is rejected
+//                  instead of producing an empty response
+//   GETMAPIMAGE    FORMAT is required, so a request without it is rejected by the agent rather
+//                  than reaching the rendering service
+//   GETSPATIALCONTEXTS  ACTIVEONLY is optional and defaults to false
+//   SELECTAGGREGATES    a non-clean JSON response converts the record's property collection
+//                  rather than repeating the header's property definitions
+//
+// The suite already assumes a live site and the Sheboygan sample data (see main.cpp), and every
+// handler opens a site connection while the common parameters are set up, so all of these cases
+// report and return when nothing is reachable.
+
+namespace
+{
+    /// Runs a request through the web tier and returns its result. Handlers report failures by
+    /// filling in the result instead of letting the exception escape Execute(), so the callers
+    /// assert on the status code and payload.
+    Ptr<MgHttpResult> RunRequest(std::initializer_list<std::pair<STRING, STRING>> parameters)
+    {
+        Ptr<MgHttpRequest> req = new MgHttpRequest(L"");
+        Ptr<MgHttpRequestParam> param = req->GetRequestParam();
+
+        for (std::initializer_list<std::pair<STRING, STRING>>::const_iterator it = parameters.begin();
+             it != parameters.end(); ++it)
+        {
+            param->AddParameter(it->first, it->second);
+        }
+
+        Ptr<MgHttpResponse> resp = req->Execute();
+        return resp->GetResult();
+    }
+
+    /// Opens a site connection as Administrator. Returns false when no server answers.
+    bool TryConnect(Ptr<MgSiteConnection>& conn, STRING& sessionId)
+    {
+        try
+        {
+            Ptr<MgUserInformation> userInfo = new MgUserInformation(L"Administrator", L"admin");
+            conn = new MgSiteConnection();
+            conn->Open(userInfo);
+
+            Ptr<MgSite> site = conn->GetSite();
+            sessionId = site->CreateSession();
+            userInfo->SetMgSessionId(sessionId);
+            return true;
+        }
+        catch (MgException* ex)
+        {
+            SAFE_RELEASE(ex);
+            return false;
+        }
+    }
+
+    /// Ensures the Sheboygan sample is in the Library, applying the package that the harness builds
+    /// when it stages the test pack. Returns false when the data is not available.
+    bool EnsureSampleData(Ptr<MgSiteConnection>& conn)
+    {
+        try
+        {
+            Ptr<MgResourceService> resSvc = static_cast<MgResourceService*>(
+                conn->CreateService(MgServiceType::ResourceService));
+
+            Ptr<MgResourceIdentifier> parcels =
+                new MgResourceIdentifier(L"Library://Samples/Sheboygan/Data/Parcels.FeatureSource");
+            if (resSvc->ResourceExists(parcels))
+                return true;
+
+            const char* testDataRoot = getenv("MG_TEST_DATA_PATH");
+            if (testDataRoot == NULL)
+                return false;
+
+            STRING package = MgUtil::MultiByteToWideChar(std::string(testDataRoot))
+                + L"/Samples/Sheboygan/Sheboygan.mgp";
+
+            Ptr<MgByteSource> source = new MgByteSource(package.c_str());
+            resSvc->ApplyResourcePackage(source->GetReader());
+
+            return resSvc->ResourceExists(parcels);
+        }
+        catch (MgException* ex)
+        {
+            SAFE_RELEASE(ex);
+            return false;
+        }
+    }
+}
+
+TEST_CASE("Geo operations accept a lower-case FORMAT", "[HttpHandler]")
+{
+    Ptr<MgSiteConnection> conn;
+    STRING sessionId;
+    if (!TryConnect(conn, sessionId))
+    {
+        WARN("No MapGuide server reachable; skipping");
+        return;
+    }
+
+    Ptr<MgHttpResult> result = RunRequest({
+        { L"OPERATION", L"GEO.BOUNDARY" },
+        { L"VERSION", L"4.0.0" },
+        { L"GEOMETRY", L"POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))" },
+        { L"FORMAT", L"wkt" },
+    });
+
+    INFO(MgUtil::WideCharToMultiByte(result->GetHttpStatusMessage()));
+    REQUIRE(result->GetStatusCode() == 200);
+
+    Ptr<MgHttpPrimitiveValue> value = dynamic_cast<MgHttpPrimitiveValue*>(result->GetResultObject());
+    REQUIRE(value.p != nullptr);
+    REQUIRE(value->GetStringValue().find(L"POLYGON") != STRING::npos);
+}
+
+TEST_CASE("Geo operations reject an unsupported FORMAT", "[HttpHandler]")
+{
+    Ptr<MgSiteConnection> conn;
+    STRING sessionId;
+    if (!TryConnect(conn, sessionId))
+    {
+        WARN("No MapGuide server reachable; skipping");
+        return;
+    }
+
+    Ptr<MgHttpResult> result = RunRequest({
+        { L"OPERATION", L"GEO.BOUNDARY" },
+        { L"VERSION", L"4.0.0" },
+        { L"GEOMETRY", L"POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))" },
+        { L"FORMAT", L"BOGUS" },
+    });
+
+    // The agent used to accept any value and write an empty body.
+    INFO(MgUtil::WideCharToMultiByte(result->GetHttpStatusMessage()));
+    REQUIRE(result->GetStatusCode() == 559);
+    REQUIRE(result->GetHttpStatusMessage() == L"MgInvalidArgumentException");
+}
+
+TEST_CASE("GetMapImage requires FORMAT", "[HttpHandler]")
+{
+    Ptr<MgSiteConnection> conn;
+    STRING sessionId;
+    if (!TryConnect(conn, sessionId))
+    {
+        WARN("No MapGuide server reachable; skipping");
+        return;
+    }
+
+    Ptr<MgHttpResult> result = RunRequest({
+        { L"OPERATION", L"GETMAPIMAGE" },
+        { L"VERSION", L"3.0.0" },
+        { L"MAPDEFINITION", L"Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition" },
+        { L"SETVIEWCENTERX", L"-87.73" },
+        { L"SETVIEWCENTERY", L"43.74" },
+        { L"SETVIEWSCALE", L"100000" },
+        { L"SETDISPLAYWIDTH", L"300" },
+        { L"SETDISPLAYHEIGHT", L"200" },
+    });
+
+    // Rejected by the agent, before the rendering service is asked to render anything.
+    INFO(MgUtil::WideCharToMultiByte(result->GetHttpStatusMessage()));
+    REQUIRE(result->GetStatusCode() == 559);
+    REQUIRE(result->GetHttpStatusMessage() == L"MgInvalidArgumentException");
+}
+
+TEST_CASE("GetSpatialContexts treats a missing ACTIVEONLY as false", "[HttpHandler]")
+{
+    Ptr<MgSiteConnection> conn;
+    STRING sessionId;
+    if (!TryConnect(conn, sessionId) || !EnsureSampleData(conn))
+    {
+        WARN("No MapGuide server or sample data; skipping");
+        return;
+    }
+
+    Ptr<MgHttpResult> result = RunRequest({
+        { L"OPERATION", L"GETSPATIALCONTEXTS" },
+        { L"VERSION", L"1.0.0" },
+        { L"SESSION", sessionId },
+        { L"RESOURCEID", L"Library://Samples/Sheboygan/Data/Parcels.FeatureSource" },
+    });
+
+    REQUIRE(result->GetStatusCode() == 200);
+
+    Ptr<MgByteReader> reader = dynamic_cast<MgByteReader*>(result->GetResultObject());
+    REQUIRE(reader.p != nullptr);
+    REQUIRE(reader->ToString().find(L"SpatialContext") != STRING::npos);
+}
+
+TEST_CASE("SelectAggregates converts a property set to JSON faithfully", "[HttpHandler]")
+{
+    Ptr<MgSiteConnection> conn;
+    STRING sessionId;
+    if (!TryConnect(conn, sessionId) || !EnsureSampleData(conn))
+    {
+        WARN("No MapGuide server or sample data; skipping");
+        return;
+    }
+
+    Ptr<MgHttpResult> result = RunRequest({
+        { L"OPERATION", L"SELECTAGGREGATES" },
+        { L"VERSION", L"1.0.0" },
+        { L"SESSION", sessionId },
+        { L"RESOURCEID", L"Library://Samples/Sheboygan/Data/Parcels.FeatureSource" },
+        { L"CLASSNAME", L"Parcels" },
+        { L"COMPUTED_PROPERTIES", L"Count(ID)" },
+        { L"COMPUTED_ALIASES", L"total" },
+        { L"FILTER", L"ID='1'" },
+        { L"FORMAT", L"application/json" },
+    });
+
+    REQUIRE(result->GetStatusCode() == 200);
+
+    Ptr<MgByteReader> reader = dynamic_cast<MgByteReader*>(result->GetResultObject());
+    REQUIRE(reader.p != nullptr);
+
+    STRING json = reader->ToString();
+
+    // The record must come from the reader's property collection. Before the fix the converter was
+    // handed the header XML with the record appended to it, kept only the first root element, and
+    // so emitted the property definitions a second time in place of the row.
+    REQUIRE(json.find(L"\"Properties\":[{\"PropertyCollection\"") != STRING::npos);
+    REQUIRE(json.find(L"\"Properties\":[{\"PropertyDefinitions\"") == STRING::npos);
+}

Modified: branches/4.0/MgDev/Web/src/WebTestRunner/WebTestRunner.vcxproj
===================================================================
--- branches/4.0/MgDev/Web/src/WebTestRunner/WebTestRunner.vcxproj	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/Web/src/WebTestRunner/WebTestRunner.vcxproj	2026-11-06 07:47:46 UTC (rev 10270)
@@ -223,6 +223,7 @@
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClCompile Include="GeoJsonTest.cpp" />
+    <ClCompile Include="HttpParameterTest.cpp" />
     <ClCompile Include="main.cpp" />
     <ClCompile Include="OgcTest.cpp" />
     <ClCompile Include="TestListener.cpp" />

Modified: branches/4.0/MgDev/Web/src/WebTestRunner/WebTestRunner.vcxproj.filters
===================================================================
--- branches/4.0/MgDev/Web/src/WebTestRunner/WebTestRunner.vcxproj.filters	2026-11-05 13:01:46 UTC (rev 10269)
+++ branches/4.0/MgDev/Web/src/WebTestRunner/WebTestRunner.vcxproj.filters	2026-11-06 07:47:46 UTC (rev 10270)
@@ -27,6 +27,9 @@
     <ClCompile Include="GeoJsonTest.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="HttpParameterTest.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
     <ClCompile Include="OgcTest.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>



More information about the mapguide-commits mailing list