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/11/29 18:32:36 UTC

svn commit: r480647 - in /incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src: Makefile.am tuscany/sca/rest/ModREST.cpp tuscany/sca/rest/RESTServiceProxy.cpp

Author: jsdelfino
Date: Wed Nov 29 09:32:35 2006
New Revision: 480647

URL: http://svn.apache.org/viewvc?view=rev&rev=480647
Log:
Support both command-style (XML/HTTP web service) and resource-style (CRUD) invocation.

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

Modified: incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/Makefile.am?view=diff&rev=480647&r1=480646&r2=480647
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/Makefile.am (original)
+++ incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/Makefile.am Wed Nov 29 09:32:35 2006
@@ -14,7 +14,8 @@
 
 libtuscany_sca_rest_service_la_LIBADD = \
   -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo \
-  -L$(top_builddir)/runtime/core/src -ltuscany_sca
+  -L$(top_builddir)/runtime/core/src -ltuscany_sca \
+  -L$(top_builddir)/runtime/extensions/rest/interface/src -ltuscany_sca_rest_interface
 
 rootdir=$(prefix)/extensions/rest/service
 
@@ -24,9 +25,11 @@
 libtuscany_sca_mod_rest_la_LIBADD = \
   -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo \
   -L$(top_builddir)/runtime/core/src -ltuscany_sca \
-  -L$(top_builddir)/runtime/extensions/rest/service/httpd/src -ltuscany_sca_rest_service
+  -L$(top_builddir)/runtime/extensions/rest/service/httpd/src -ltuscany_sca_rest_service \
+  -L$(top_builddir)/runtime/extensions/rest/interface/src -ltuscany_sca_rest_interface
 
 INCLUDES = -I$(top_builddir)/runtime/core/src \
+  -I$(top_builddir)/runtime/extensions/rest/interface/src \
   -I${TUSCANY_SDOCPP}/include \
   -I${HTTPD_INCLUDE}
                    

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=480647&r1=480646&r2=480647
==============================================================================
--- 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 Wed Nov 29 09:32:35 2006
@@ -38,6 +38,7 @@
 #include "tuscany/sca/util/Logging.h"
 #include "RESTServiceProxy.h"
 #include "model/RESTReferenceBinding.h"
+#include "tuscany/sca/rest/model/RESTInterface.h"
 #include "tuscany/sca/model/Composite.h"
 #include "tuscany/sca/model/CompositeService.h"
 #include "tuscany/sca/model/Component.h"
@@ -325,13 +326,13 @@
                         }
                     }
                     
-                    const char* args = request->args;
-                    if (args)
+                    const char* queryArgs = request->args;
+                    if (queryArgs)
                     {
-                        loginfo("Args: %s", args);
+                        loginfo("Args: %s", queryArgs);
                         if (printRequest)
                         {
-                            ap_rprintf(request, "<p>Args: %s", args);
+                            ap_rprintf(request, "<p>Args: %s", queryArgs);
                         }
                     }
                     
@@ -356,22 +357,22 @@
                             path = path_info;
                         }
                         string uri;
-                        string op_name;
-                        Utils::rTokeniseString("/", path, uri, op_name);
-                        loginfo("Operation name: %s", op_name.c_str());
                 
                         string component;
                         string service;        
                         if (strlen(dir_conf->component))
                         {
-                            // The path only specifies the service
+                            // The path only specifies the service, the component name
+                            // is configured in the directory/location configured
                             component = dir_conf->component;
-                            service = uri; 
+                            Utils::tokeniseString("/", path, service, uri); 
                         }
                         else
                         {
                             // The path must be in the form component / service
-                            Utils::rTokeniseString("/", uri, component, service);
+                            string path2;
+                            Utils::tokeniseString("/", path, component, path2);
+                            Utils::tokeniseString("/", path2, service, uri);
                         }
                 
                         loginfo("Component name: %s", component.c_str());
@@ -398,35 +399,59 @@
                         Composite* composite = compositeService->getComposite();
                         Reference* reference = compositeService->getReference();
                         RESTReferenceBinding* binding = (RESTReferenceBinding*)reference->getBinding();
-            
-                        // If we have a WSDL interface, look for the WSDL operation definition
+                        Interface* iface = reference->getType()->getInterface();
+    
+                        // Determine the operation to invoke                    
                         WSDLOperation wsdlOperation;
                         string wsdlNamespace = "";
-                        Interface* iface = reference->getType()->getInterface();
-                        if (iface != NULL &&
-                            iface->getInterfaceTypeQName() == WSDLInterface::typeQName)
+                        string op_name = "";
+                        string uriArgs = "";
+                        if (iface != NULL)
                         {
-                            WSDLInterface* wsdlInterface = (WSDLInterface*)iface;
-                            wsdlNamespace = wsdlInterface->getNamespaceURI();
-                            
-                            if (wsdlNamespace != "")
+                            // If we have a REST interface, the operation name is "retrieve"
+                            if (iface->getInterfaceTypeQName() == RESTInterface::typeQName)
                             {
-                                WSDLDefinition* wsdl = composite->findWSDLDefinition(wsdlNamespace);
-                                if (wsdl == 0)
-                                {
-                                    string msg = "WSDL not found for: " + wsdlNamespace;
-                                    throwException(SystemConfigurationException, msg.c_str());
-                                }
-                                try
+                                op_name = "retrieve";
+                                uriArgs = uri;
+                            }
+                            else if (iface->getInterfaceTypeQName() == WSDLInterface::typeQName)
+                            {
+                                // we have a WSDL interface, the operation name is part of the URI
+                                Utils::tokeniseString("/", uri, op_name, uriArgs);
+                                
+                                // look for the WSDL operation definition
+                                WSDLInterface* wsdlInterface = (WSDLInterface*)iface;
+                                wsdlNamespace = wsdlInterface->getNamespaceURI();
+                                
+                                if (wsdlNamespace != "")
                                 {
-                                    wsdlOperation = wsdl->findOperation(wsdlInterface->getName(), op_name.c_str());
-                                }
-                                catch(SystemConfigurationException& ex)
-                                {   
-                                    throw;
+                                    WSDLDefinition* wsdl = composite->findWSDLDefinition(wsdlNamespace);
+                                    if (wsdl == 0)
+                                    {
+                                        string msg = "WSDL not found for: " + wsdlNamespace;
+                                        throwException(SystemConfigurationException, msg.c_str());
+                                    }
+                                    try
+                                    {
+                                        wsdlOperation = wsdl->findOperation(wsdlInterface->getName(), op_name.c_str());
+                                    }
+                                    catch(SystemConfigurationException&)
+                                    {   
+                                        throw;
+                                    }
+                                    
+                                    if (!wsdlOperation.isDocumentStyle() || !wsdlOperation.isWrappedStyle())
+                                    {
+                                        throwException(ServiceInvocationException,
+                                            "Only wrapped document style WSDL operations are currentlysupported");
+                                    }
                                 }
                             }
                         }
+                        else
+                        {
+                            Utils::tokeniseString("/", uri, op_name, uriArgs);
+                        }
                     
                         // Create a default document literal wrapped WSDL operation
                         if (wsdlNamespace == "")
@@ -443,20 +468,36 @@
                             wsdlOperation.setInputType(string("http://tempuri.org") + "#" + op_name);
                             wsdlOperation.setOutputType(string("http://tempuri.org") + "#" + op_name + "Response");
                         }
-                        else if (!wsdlOperation.isDocumentStyle() || !wsdlOperation.isWrappedStyle())
-                        {
-                            throwException(ServiceInvocationException,
-                                "Only wrapped document style WSDL operations are currentlysupported");
-                        }
                         
                         //  Get the REST proxy
                         RESTServiceProxy* proxy = (RESTServiceProxy*)binding->getServiceProxy();
             
                         // Create the input DataObject
                         Operation operation(op_name.c_str());
-                        if (args)
+                        
+                        // Parse the args part of the URI
+                        if (uriArgs != "")
                         {
-                            string query = args;
+                            string args = uriArgs;
+                            for (; args != ""; )
+                            {
+                                string param;
+                                string next;
+                                Utils::tokeniseString("/", args, param, next);
+                                if (param != "")
+                                {
+                                    string* data = new string;
+                                    *data = param;
+                                    operation.addParameter(data);    
+                                }
+                                args = next;
+                            }
+                        }                        
+                        
+                        // Parse the query string
+                        if (queryArgs)
+                        {
+                            string query = queryArgs;
                             for (; query != ""; )
                             {
                                 string param;
@@ -469,7 +510,7 @@
                                     Utils::tokeniseString("=", param, n, *data);
                                     operation.addParameter(data);    
                                 }
-                               query = next;
+                                query = next;
                             }
                         }
                         DataObjectPtr inputDataObject = createPayload(dataFactory, operation, wsdlOperation);
@@ -489,12 +530,32 @@
                         }
                         
                         // Send the output DataObject
-                        XMLHelperPtr xm = HelperProvider::getXMLHelper(dataFactory);
-                        XMLDocumentPtr doc = xm->createDocument(
-                            outputDataObject,
-                            wsdlOperation.getOutputTypeUri().c_str(), 
-                            wsdlOperation.getOutputTypeName().c_str());
-                       char * str = xm->save(doc);
+                        char *str;
+                        if (iface!=NULL &&
+                            iface->getInterfaceTypeQName() == RESTInterface::typeQName)
+                        {
+                            // Pure REST, send the response document
+                            XMLHelperPtr xm = HelperProvider::getXMLHelper(dataFactory);
+                            DataObjectList& l = outputDataObject->getList("return");
+                            DataObjectPtr resourceDataObject = l[0];
+                            XMLDocumentPtr doc = xm->createDocument(
+                                resourceDataObject,
+                                resourceDataObject->getType().getURI(),
+                                resourceDataObject->getType().getName());
+                           doc->setXMLDeclaration(false);
+                           str = xm->save(doc);
+                        }
+                        else
+                        {
+                            // Command style, send the response wrapper element
+                            XMLHelperPtr xm = HelperProvider::getXMLHelper(dataFactory);
+                            XMLDocumentPtr doc = xm->createDocument(
+                                outputDataObject,
+                                wsdlOperation.getOutputTypeUri().c_str(), 
+                                wsdlOperation.getOutputTypeName().c_str());
+                           doc->setXMLDeclaration(false);
+                           str = xm->save(doc);
+                        }
                        
                         // Set the content type
                         ap_set_content_type(request, "text/xml");

Modified: incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.cpp?view=diff&rev=480647&r1=480646&r2=480647
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.cpp (original)
+++ incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.cpp Wed Nov 29 09:32:35 2006
@@ -64,39 +64,25 @@
                 RESTReferenceBinding* referenceBinding = (RESTReferenceBinding*)reference->getBinding();
                 serviceWrapper = referenceBinding->getTargetServiceBinding()->getServiceWrapper();
                 
-                // Define the SOAP Body type and element to allow a SOAP body to
-                // be loaded in a DataObject
                 DataFactoryPtr dataFactory = reference->getComponent()->getComposite()->getDataFactory();
                 try {
-                    const Type& bodyType = dataFactory->getType("http://www.w3.org/2003/05/soap-envelope", "Body");
+                    const Type& tempType = dataFactory->getType("http://tempuri.org", "RootType");
                 } catch (SDORuntimeException&)
                 {
-                    
-                    // Define the SOAP 1.2 Body type
-                    dataFactory->addType("http://www.w3.org/2003/05/soap-envelope", "RootType", false, false, false);                
-                    dataFactory->addType("http://www.w3.org/2003/05/soap-envelope", "Body", false, true, false);                
+                    dataFactory->addType("http://tempuri.org", "RootType", false, false, false);                
+                    dataFactory->addType("http://tempuri.org", "Body", false, true, false);                
                     dataFactory->addPropertyToType(
-                        "http://www.w3.org/2003/05/soap-envelope", "RootType",
+                        "http://tempuri.org", "RootType",
                         "Body",
-                        "http://www.w3.org/2003/05/soap-envelope", "Body",
+                        "http://tempuri.org", "Body",
                         false, false, true);
-    
-                    // Define the SOAP 1.1 Body type
-                    dataFactory->addType("http://schemas.xmlsoap.org/soap/envelope/", "RootType", false, false, false);
-                    dataFactory->addType("http://schemas.xmlsoap.org/soap/envelope/", "Body", false, true, false);
+                    dataFactory->addType("http://tempuri.org", "Part", false, true, false);                
                     dataFactory->addPropertyToType(
-                        "http://schemas.xmlsoap.org/soap/envelope/", "RootType",
-                        "Body",
-                        "http://schemas.xmlsoap.org/soap/envelope/", "Body",
+                        "http://tempuri.org", "RootType",
+                        "Part",
+                        "http://tempuri.org", "Part",
                         false, false, true);
                 }
-
-                try {
-                    const Type& tempType = dataFactory->getType("http://tempuri.org", "RootType");
-                } catch (SDORuntimeException&)
-                {
-                    dataFactory->addType("http://tempuri.org", "RootType", false, false, false);                
-                }
             }
             
             // ==========
@@ -163,18 +149,19 @@
                         case Type::BytesType:
                             {
                                 int len = inputDataObject->getLength(pl[i]);
-                                char* bytesData = new char[len+1];
-                                int bytesWritten = inputDataObject->getBytes(pl[i], bytesData, len);
+                                char** bytesData = new char*;
+                                *bytesData = new char[len+1];
+                                int bytesWritten = inputDataObject->getBytes(pl[i], *bytesData, len);
                                 // Ensure the bytes end with the null char. Not sure if this is neccessary
                                 if(bytesWritten <= len)
                                 {
-                                    bytesData[bytesWritten] = 0;
+                                    (*bytesData)[bytesWritten] = 0;
                                 }
                                 else
                                 {
-                                    bytesData[len] = 0;
+                                    (*bytesData)[len] = 0;
                                 }
-                                operation.addParameter(&bytesData);
+                                operation.addParameter(bytesData);
                             }
                             break;
                         case Type::CharacterType:
@@ -238,12 +225,17 @@
                             break;
                         case Type::DataObjectType:
                             {
-                                DataObjectPtr dataObjectData = inputDataObject->getDataObject(pl[i]);
-                                if(!dataObjectData)
+                                DataObjectPtr* dataObjectData = new DataObjectPtr;
+                                *dataObjectData = inputDataObject->getDataObject(pl[i]);
+                                if(!*dataObjectData)
                                 {
                                     loginfo("Null DataObject parameter named %s", name);
                                 }
-                                operation.addParameter(&dataObjectData);
+                                else
+                                {
+                                    (*dataObjectData)->detach();
+                                }
+                                operation.addParameter(dataObjectData);
                             }
                             break;
                         case Type::OpenDataObjectType:
@@ -257,18 +249,20 @@
                                 
                                 for(int j=0; j<dataObjectList.size(); j++)
                                 {
-                                    DataObjectPtr dataObjectData = dataObjectList[j];
-                                    if(!dataObjectData)
+                                    DataObjectPtr dob = dataObjectList[j];
+                                    if(!dob)
                                     {
                                         
                                         // Add a null DataObject ptr
+                                        DataObjectPtr* dataObjectData = new DataObjectPtr;
+                                        *dataObjectData = NULL; 
                                         loginfo("Null OpenDataObject parameter named %s[%d]", name, j);
-                                        operation.addParameter(&dataObjectData);
+                                        operation.addParameter(dataObjectData);
                                     }
                                     else
                                     {
                                         
-                                        SequencePtr sequence = dataObjectData->getSequence();
+                                        SequencePtr sequence = dob->getSequence();
                                         if (sequence->size()!=0)
                                         {
                                             // Add a text element        
@@ -280,12 +274,17 @@
                                             else
                                             {
                                                 // Add a complex element DataObject
-                                                DataObjectPtr dob = sequence->getDataObjectValue(0);
-                                                if(!dob)
+                                                DataObjectPtr* dataObjectData =new DataObjectPtr;
+                                                *dataObjectData = sequence->getDataObjectValue(0);
+                                                if(!*dataObjectData)
                                                 {
                                                     loginfo("Null DataObject parameter named %s", name);
                                                 }
-                                                operation.addParameter(&dob);
+                                                else
+                                                {
+                                                    (*dataObjectData)->detach();
+                                                }
+                                                operation.addParameter(dataObjectData);
                                             }
                                         }
                                         else



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