You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2006/12/03 04:39:54 UTC

svn commit: r481699 - /incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp

Author: jsdelfino
Date: Sat Dec  2 19:39:53 2006
New Revision: 481699

URL: http://svn.apache.org/viewvc?view=rev&rev=481699
Log:
Correct parsing of multipart/form-data POSTs in the REST server-side binding.

Modified:
    incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp

Modified: incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp?view=diff&rev=481699&r1=481698&r2=481699
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp (original)
+++ incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp Sat Dec  2 19:39:53 2006
@@ -287,6 +287,10 @@
                             ap_rprintf(request, "<p>Content type: %s", content_type);
                         }
                     }
+                    else
+                    {
+                        content_type = "text/plain";
+                    }
                 
                     if (request->content_encoding)
                     {
@@ -721,7 +725,84 @@
                             }
                         }
                         string input = sinput.str();
-                        addPart(xmlHelper, input, operation);
+                        
+                        string contentType = content_type;
+                        if (contentType.find("multipart/form-data") == 0)
+                        {
+                            // This is a multipart POST, extract each part from the
+                            // POST body
+                            string begin;
+                            string boundary;
+                            Utils::tokeniseString("boundary=", contentType, begin, boundary);
+                            
+                            for (;;)
+                            {
+                                // Read each part
+                                string part;
+                                string next;
+                                Utils::tokeniseString(boundary, input, part, next);
+                                input = next;
+                                
+                                // Skip first and last empty parts
+                                if (part.length() == 0 || part == "--")
+                                    continue;
+                                
+                                // Read headers
+                                bool xml = false;
+                                int empty = -1;
+                                for (;;)
+                                {
+                                    string header;
+                                    Utils::tokeniseString("\r\n", part, header, next);
+                                    part = next;
+                                    if (header == "")
+                                    {
+                                        // Two empty lines signal the beginning of the content
+                                        empty++;
+                                        if (empty == 1)
+                                            break;
+                                    }
+                                    else
+                                    {
+                                        empty = 0;
+                                        
+                                        // Detect XML content
+                                        if (header == "Content-Type: text/xml")
+                                            xml = true;
+                                    }
+                                }
+
+                                // Read the part content
+                                if (part.length())
+                                {                       
+                                    // Strip the trailer         
+                                    string value;
+                                    Utils::tokeniseString("\r\n--", part, value, next);
+                                    
+                                    if (xml)
+                                    {
+                                        // Add an XML parameter to the operation
+                                        addPart(xmlHelper, value, operation);
+                                    }
+                                    else
+                                    {
+                                        // Add a text parameter to the operation
+                                        string* stringData = new string;
+                                        *stringData = value;
+                                        operation.addParameter(stringData); 
+                                    }
+                                }
+
+                                // Read till the end of the POST body
+                                if (input.length() == 0)
+                                    break;
+                            }                    
+                        }
+                        else
+                        {
+                            // The POST body represents a single part 
+                            addPart(xmlHelper, input, operation);
+                        }
                         
                         DataObjectPtr inputDataObject = createPayload(dataFactory, operation, wsdlOperation);
                         



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org