[mapguide-commits] r7786 - in trunk/MgDev: Common/MapGuideCommon/Resources Web/src/HttpHandler

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Aug 20 08:33:39 PDT 2013


Author: jng
Date: 2013-08-20 08:33:39 -0700 (Tue, 20 Aug 2013)
New Revision: 7786

Modified:
   trunk/MgDev/Common/MapGuideCommon/Resources/mapguide_en.res
   trunk/MgDev/Web/src/HttpHandler/HttpSelectFeatures.cpp
   trunk/MgDev/Web/src/HttpHandler/HttpSelectFeaturesSpatially.cpp
   trunk/MgDev/Web/src/HttpHandler/HttpWfsGetFeature.cpp
   trunk/MgDev/Web/src/HttpHandler/OgcWfsServer.cpp
   trunk/MgDev/Web/src/HttpHandler/ResponseStream.h
Log:
#2342: Fix the broken test cases
 - SELECTFEATURE/SELECTAGGREGATES
   - Default to text/xml if no format specified (PHP test runner doesn't specify FORMAT for some tests and is expecting a non-exception response)
 - WFS GetFeature
   - Throw exception on malformed WFS feature type names (ie. No ":" in the type name)
   - Throw exception if WFS feature type name could not be resolved to a Feature Source ID
   - Make MgGetWfsFeaturesResponseStream an actual stream inheriting from MgHttpResponseStream with an extra MgByteReader property (that a successful GetFeature request will set). This way, any exceptions written by MgOgcServer::ServiceExceptionReportResponse() will be captured. When it comes to sending back the actual result, the GetFeature response will be returned if it exists, otherwise whatever the MgOgcServer wrote will be returned.

Modified: trunk/MgDev/Common/MapGuideCommon/Resources/mapguide_en.res
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/Resources/mapguide_en.res	2013-08-20 15:15:32 UTC (rev 7785)
+++ trunk/MgDev/Common/MapGuideCommon/Resources/mapguide_en.res	2013-08-20 15:33:39 UTC (rev 7786)
@@ -159,6 +159,7 @@
 MgArgumentsMismatch                                   = The arguments needed do not match the arguments provided.
 MgArgumentOutOfRange                                  = Argument out of range [%1, %2]: %3
 MgClassWOIdentity                                     = A class definition has no identity property.
+MgCannotResolveFeatureSourceFromWfsTypeName           = Could not resolve the Feature Source from the given WFS Type Name: %1
 MgCollectionEmpty                                     = The collection cannot be empty.
 MgCoordinateSystemNotReadyException                   = The object is not ready for this operation.
 MgConfigurationPropertyLengthIsInvalid                = The value of property %1 under section %2 is %3. Its length must be %4

Modified: trunk/MgDev/Web/src/HttpHandler/HttpSelectFeatures.cpp
===================================================================
--- trunk/MgDev/Web/src/HttpHandler/HttpSelectFeatures.cpp	2013-08-20 15:15:32 UTC (rev 7785)
+++ trunk/MgDev/Web/src/HttpHandler/HttpSelectFeatures.cpp	2013-08-20 15:33:39 UTC (rev 7786)
@@ -38,6 +38,10 @@
     Ptr<MgHttpRequestParam> params = hRequest->GetRequestParam();
     m_resId = params->GetParameterValue(MgHttpResourceStrings::reqFeatResourceId);
     m_className = params->GetParameterValue(MgHttpResourceStrings::reqFeatClass);
+
+    //Default to xml if not specified
+    if (m_responseFormat.empty())
+        m_responseFormat = MgMimeType::Xml;
 }
 
 /// <summary>

Modified: trunk/MgDev/Web/src/HttpHandler/HttpSelectFeaturesSpatially.cpp
===================================================================
--- trunk/MgDev/Web/src/HttpHandler/HttpSelectFeaturesSpatially.cpp	2013-08-20 15:15:32 UTC (rev 7785)
+++ trunk/MgDev/Web/src/HttpHandler/HttpSelectFeaturesSpatially.cpp	2013-08-20 15:33:39 UTC (rev 7786)
@@ -48,6 +48,10 @@
         m_operation = atoi(MgUtil::WideCharToMultiByte(spatialOp).c_str());
 
     m_geometry = params->GetParameterValue(MgHttpResourceStrings::reqFeatGeometry);
+
+    //Default to xml if not specified
+    if (m_responseFormat.empty())
+        m_responseFormat = MgMimeType::Xml;
 }
 
 /// <summary>

Modified: trunk/MgDev/Web/src/HttpHandler/HttpWfsGetFeature.cpp
===================================================================
--- trunk/MgDev/Web/src/HttpHandler/HttpWfsGetFeature.cpp	2013-08-20 15:15:32 UTC (rev 7785)
+++ trunk/MgDev/Web/src/HttpHandler/HttpWfsGetFeature.cpp	2013-08-20 15:33:39 UTC (rev 7786)
@@ -23,6 +23,9 @@
 #include "OgcFramework.h"
 #include "OgcWfsServer.h"
 
+extern CPSZ kpszQueryStringTypeName;
+extern CPSZ kpszExceptionMessageMalformedRequestedType;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////
 //                                          MgException* or derivative                       //
 //                                          |                 MgOgcWfsException::kpsz...     //
@@ -34,7 +37,7 @@
             ogc_server.ServiceExceptionReportResponse(                                        \
                 MgOgcWfsException(MgOgcWfsException::ogc_exception_code,                      \
                                   sReport.c_str() ));                                         \
-            Ptr<MgByteReader> capabilities = responseStream.GetReader();                      \
+            Ptr<MgByteReader> capabilities = responseStream.Stream().GetReader();             \
             hResult->SetResultObject(capabilities, capabilities->GetMimeType());              \
             e->Release();                                                                     \
         }                                                                                     \
@@ -49,7 +52,7 @@
             ogc_server.ServiceExceptionReportResponse(                                        \
                 MgOgcWfsException(MgOgcWfsException::kpszInternalError,                       \
                                   _("Unexpected exception was thrown.  No additional details available.")));\
-            Ptr<MgByteReader> capabilities = responseStream.GetReader();                      \
+            Ptr<MgByteReader> capabilities = responseStream.Stream().GetReader();             \
             hResult->SetResultObject(capabilities, capabilities->GetMimeType());              \
         }                                                                                     \
 ///////////////////////////////////////////////////////////////////////////////////////////////
@@ -130,16 +133,27 @@
     try
     {
         wfsServer.ProcessRequest(this);
+        //We have the GetFeature response
+        if (responseStream.HasReader())
+        {
+            // Obtain the response byte reader
+            Ptr<MgByteReader> responseReader = responseStream.GetReader();
 
-        // Obtain the response byte reader
-        Ptr<MgByteReader> responseReader = responseStream.GetReader();
+            Ptr<MgHttpHeader> respHeader = hResponse.GetHeader();
+            //This is the "hint" to chunk the MgByteReader content
+            respHeader->AddHeader(MgHttpResourceStrings::hrhnTransfer_Encoding, MgHttpResourceStrings::hrhnChunked);
 
-        Ptr<MgHttpHeader> respHeader = hResponse.GetHeader();
-        //This is the "hint" to chunk the MgByteReader content
-        respHeader->AddHeader(MgHttpResourceStrings::hrhnTransfer_Encoding, MgHttpResourceStrings::hrhnChunked);
+            // Set the result
+            hResult->SetResultObject(responseReader, responseReader->GetMimeType());
+        }
+        else //Write out whatever the MgOgcWfsServer has written
+        {
+            // Slurp the results.
+            Ptr<MgByteReader> response = responseStream.Stream().GetReader();
 
-        // Set the result
-        hResult->SetResultObject(responseReader, responseReader->GetMimeType());
+            // Set the result
+            hResult->SetResultObject(response, response->GetMimeType());
+        }
     }
     
     CATCH_MGEXCEPTION_HANDLE_AS_OGC_WFS(MgException,kpszInternalError,wfsServer)
@@ -292,7 +306,19 @@
                             //
                             // This *is* already the WFS GetFeature response. There is nothing to post-process through the XML templates!
                         }
+                        else //Cannot resolve feature source from feature type name
+                        {
+                            MgStringCollection args;
+                            args.Add(sFeatureType);
+                            throw new MgInvalidArgumentException(L"MgHttpWfsGetFeature.AcquireResponseData", __LINE__, __WFILE__, NULL, L"MgCannotResolveFeatureSourceFromWfsTypeName", &args);
+                        }
                     }
+                    else //Feature type name is malformed. We expected the form <namespace>:<class_name>
+                    {
+                        wfsServer->ServiceExceptionReportResponse(MgOgcWfsException(MgOgcWfsException::kpszInvalidParameterValue,
+                                                                                    kpszExceptionMessageMalformedRequestedType,
+                                                                                    kpszQueryStringTypeName));
+                    }
                 }
             }
         }

Modified: trunk/MgDev/Web/src/HttpHandler/OgcWfsServer.cpp
===================================================================
--- trunk/MgDev/Web/src/HttpHandler/OgcWfsServer.cpp	2013-08-20 15:15:32 UTC (rev 7785)
+++ trunk/MgDev/Web/src/HttpHandler/OgcWfsServer.cpp	2013-08-20 15:33:39 UTC (rev 7786)
@@ -40,6 +40,7 @@
 CPSZ kpszQueryStringGetFeatureOutputFormatDefault_1_1_0    = _("Formats.GetFeature.default.1.1.0");
 CPSZ kpszPiGetFeatureCollection              = _("GetFeatureCollection");
 CPSZ kpszPiGetFeatureCollectionDefaultFormat = _("&GetFeatureCollection.xml;");
+CPSZ kpszQueryStringTypeName                 = _("typename");
 
 CPSZ kpszQueryStringAcceptVersions           = _("acceptversions");
 CPSZ kpszQueryStringSections                 = _("sections");
@@ -65,6 +66,7 @@
 CPSZ kpszExceptionMessageWfsVersionNegotiationFailed = _("Requested version is unsupported in AcceptVersions"); //Localize
 CPSZ kpszExceptionMessageWfsInvalidVersion = _("Version number specified must correspond to a version supported by the service."); // Localize
 CPSZ kpszExceptionMessageWfsInvalidService = _("Invalid parameter value for SERVICE"); //Localize
+CPSZ kpszExceptionMessageMalformedRequestedType = _("Encountered malformed typeName in request"); //Localize
 
 CPSZ kpszInternalErrorMissingGetFeatureRequestParams   = _("Internal Error: Missing WFS GetFeature request parameters."); // Localize
 //

Modified: trunk/MgDev/Web/src/HttpHandler/ResponseStream.h
===================================================================
--- trunk/MgDev/Web/src/HttpHandler/ResponseStream.h	2013-08-20 15:15:32 UTC (rev 7785)
+++ trunk/MgDev/Web/src/HttpHandler/ResponseStream.h	2013-08-20 15:33:39 UTC (rev 7786)
@@ -52,31 +52,6 @@
 };
 */
 
-// This is not a true stream. It's just a temporary MgByteReader
-// placeholder that passes the CStream type test allowing us to 
-// pass this into a MgOgcWfsServer instance.
-class MgGetWfsFeaturesResponseStream : public CStream
-{
-public:
-    MgGetWfsFeaturesResponseStream() 
-    {
-        m_reader = NULL;
-    }
-    ~MgGetWfsFeaturesResponseStream() 
-    { 
-        m_reader = NULL;
-    }
-
-    virtual void SetContentType(CPSZ pszContentTypeMime) { }
-    virtual long Write(CPSZ pszBuffer,size_t uBytesToWrite,size_t* puBytesWritten) { return -1; }
-
-    void SetReader(MgByteReader* reader) { m_reader = SAFE_ADDREF(reader); }
-    MgByteReader* GetReader() { return SAFE_ADDREF(m_reader); }
-
-private:
-    MgByteReader* m_reader;
-};
-
 class MgHttpResponseStream: public CStream
 {
 public:
@@ -86,6 +61,12 @@
         m_pStream = new MgByteSource(m_pStore);
     }
 
+    virtual ~MgHttpResponseStream()
+    {
+        m_pStream = NULL;
+        m_pStore = NULL;
+    }
+
     void SetContentType(CPSZ pszContentTypeMime)
     {
         m_pStream->SetMimeType(pszContentTypeMime);
@@ -121,9 +102,33 @@
         return *m_pStream;
     }
 
-private:
+protected:
     Ptr<MgByte>       m_pStore;
     Ptr<MgByteSource> m_pStream;
 };
 
+// This is a specialized response stream for GetFeature that allows us to attach
+// the MgFeatureService.GetWfsFeature() response directly (which the GetFeature operation will
+// check for), while still retaining the ability to have any exception responses written to it
+// by the MgOgcServer instance.
+class MgGetWfsFeaturesResponseStream : public MgHttpResponseStream
+{
+public:
+    MgGetWfsFeaturesResponseStream() : MgHttpResponseStream()
+    {
+        m_reader = NULL;
+    }
+    virtual ~MgGetWfsFeaturesResponseStream() 
+    { 
+        SAFE_RELEASE(m_reader);
+    }
+
+    bool HasReader() { return NULL != m_reader; }
+    void SetReader(MgByteReader* reader) { m_reader = SAFE_ADDREF(reader); }
+    MgByteReader* GetReader() { return SAFE_ADDREF(m_reader); }
+
+private:
+    MgByteReader* m_reader;
+};
+
 #endif//_CgiResponseStream_h



More information about the mapguide-commits mailing list