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/26 11:52:03 UTC

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

Author: jsdelfino
Date: Sun Nov 26 02:52:03 2006
New Revision: 479337

URL: http://svn.apache.org/viewvc?view=rev&rev=479337
Log:
Complete handling of GET REST command style requests.

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
    incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.h

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=479337&r1=479336&r2=479337
==============================================================================
--- 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 Sun Nov 26 02:52:03 2006
@@ -23,7 +23,8 @@
 
 libtuscany_sca_mod_rest_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/service/httpd/src -ltuscany_sca_rest_service
 
 INCLUDES = -I$(top_builddir)/runtime/core/src \
   -I${TUSCANY_SDOCPP}/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=479337&r1=479336&r2=479337
==============================================================================
--- 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 Sun Nov 26 02:52:03 2006
@@ -34,193 +34,680 @@
 
 #include "mod_core.h"
 
+#include "tuscany/sca/util/Exceptions.h"
+#include "tuscany/sca/util/Logging.h"
+#include "RESTServiceProxy.h"
+#include "model/RESTReferenceBinding.h"
+#include "tuscany/sca/model/Composite.h"
+#include "tuscany/sca/model/CompositeService.h"
+#include "tuscany/sca/model/Component.h"
+#include "tuscany/sca/model/Reference.h"
+#include "tuscany/sca/model/ReferenceType.h"
+#include "tuscany/sca/model/WSDLDefinition.h"
+#include "tuscany/sca/model/WSDLOperation.h"
+#include "tuscany/sca/model/WSDLInterface.h" 
+#include "tuscany/sca/model/Interface.h" 
+#include "tuscany/sca/core/SCARuntime.h"
+#include "tuscany/sca/util/Utils.h"
+
+#include "commonj/sdo/SDO.h"
+
+#include <sstream>
+
+using namespace commonj::sdo;
+
+using namespace tuscany::sca;
+using namespace tuscany::sca::rest;
+using namespace tuscany::sca::model;
+
 
 extern "C"
 {                                                                                   
+    extern module AP_MODULE_DECLARE_DATA sca_rest_module;
+}
 
-/* Configuration structure populated by apache2.conf */
-typedef struct rest_server_config_rec
-{
-    char * home;
-} rest_server_config_rec_t;
-
-typedef struct rest_dir_config_rec
+namespace tuscany
 {
-    char * root;
-    char * path;
-    char * component;
-} rest_dir_config_rec_t;
-
-extern module AP_MODULE_DECLARE_DATA sca_rest_module;
-
-static const char *rest_set_home(cmd_parms *cmd, void *dummy, 
-                        const char *arg);
+    namespace sca
+    {
+        namespace rest
+        {
+            
+            typedef struct rest_server_config_rec
+            {
+                char * home;
+            } rest_server_config_rec_t;
+            
+            typedef struct rest_dir_config_rec
+            {
+                char * root;
+                char * path;
+                char * component;
+            } rest_dir_config_rec_t;
+            
+            CompositeService* initializeSCARuntime(
+                const char* home, const char* root, const char* path, const char *component, const char* service);
+            
+            DataObjectPtr createPayload(DataFactoryPtr dataFactory,
+                Operation& operation, const WSDLOperation& wsdlOperation);
+
+            int logHeaders(void* request, const char* key, const char* value);
+
+            /**
+             * Initialize the SCA runtime
+             */
+            CompositeService* initializeSCARuntime(const char* home, const char* root, const char* path, const char *component, const char* service)
+            {
+                logentry();
+                loginfo("Root: %s, path: %s, component: %s, service: %s", root, path, component, service);
+                
+                try
+                {
+                    bool restart = false;
+                    bool resolve = false;
+            
+                    string systemRoot = SCARuntime::getSystemRoot();
+                    if (systemRoot != root)
+                    {
+                        systemRoot = root;
+                        restart = true;
+                        resolve = true;
+                    }
+            
+                    string systemPath = SCARuntime::getSystemPath();
+                    if (systemPath != path)
+                    {
+                        systemPath = path;
+                        restart = true;
+                        resolve = true;
+                    }
+            
+                    string componentName = SCARuntime::getDefaultComponentName();
+                    if (componentName != component)
+                    {
+                        componentName = component;
+                        resolve = true;
+                    }
+                    
+                    string serviceName = service;
+            
+                    SCARuntime* scaRuntime;
+                    if (restart)
+                    {
+                        loginfo("Starting SCA runtime");
+                        SCARuntime::releaseInstance();
+                        SCARuntime::setSystemRoot(systemRoot);
+                        SCARuntime::setSystemPath(systemPath);
+                        SCARuntime::setDefaultComponentName(componentName);
+                        scaRuntime = SCARuntime::getInstance();
+                    }
+                    else if (resolve)
+                    {
+                        loginfo("Starting SCA runtime");
+                        SCARuntime::releaseInstance();
+                        SCARuntime::setSystemRoot(systemRoot);
+                        SCARuntime::setSystemPath(systemPath);
+                        SCARuntime::setDefaultComponentName(componentName);
+                        scaRuntime = SCARuntime::getInstance();
+                    }
+                    else
+                    {
+                        scaRuntime = SCARuntime::getInstance();
+                    }
+            
+                    loginfo("Resolving composite: %s, service: %s", componentName.c_str(), serviceName.c_str());
+                    Component* compositeComponent = scaRuntime->getDefaultComponent();
+                    if (compositeComponent == NULL)
+                    {
+                        string msg = "Component not found " + componentName;
+                        throwException(SystemConfigurationException, msg.c_str());
+                    }
+                    Composite* composite = (Composite*)compositeComponent->getType();
+                    CompositeService* compositeService = (CompositeService*)composite->findComponent(serviceName);
+                    if (compositeService == NULL)
+                    {
+                        string msg = "Composite service not found " + serviceName;
+                        throwException(SystemConfigurationException, msg.c_str());
+                    }
+                    
+                    return compositeService;
+                }
+                catch(TuscanyRuntimeException &ex)
+                {
+                    ostringstream msg;
+                    msg << ex;
+                    logerror("Failed to initialize SCA runtime: %s", msg.str().c_str());
+                    throw;
+                }
+            }
+            
+            bool printRequest = false;
+            
+            int logHeaders(void* request, const char* key, const char* value)
+            {
+                loginfo("Header key: %s, value: %s", key, value);
+                if (printRequest)
+                {
+                    ap_rprintf((request_rec*)request, "<br>Header key: %s, value: %s", key, value);
+                }
+                return 1;
+            }
+            
+            int rest_handler(request_rec *request)
+            {
+                logentry();
+                
+                if (strcmp(request->handler, "sca_rest_module"))
+                {
+                    return DECLINED;
+                }
+                
+                try {
+                    
+                    // Set up the read policy
+                    int rc = ap_setup_client_block(request, REQUEST_CHUNKED_DECHUNK);
+                    if (rc != OK)
+                    {
+                        return rc;
+                    }
+                    ap_should_client_block(request);
+                    
+                    int content_length = request->remaining;
+                    if (request->read_chunked == true && content_length == 0)
+                    {
+                        content_length = -1;
+                        request->chunked = true;
+                    }
+                
+                    if (printRequest)
+                    {
+                        // Set the content type
+                        ap_set_content_type(request, "text/html");
                         
-static const char *rest_set_path(cmd_parms *cmd, void *conf, 
-                        const char *arg);
+                        // Send the response document
+                        ap_rputs("<html><body><p>Tuscany Mod_rest works!", request);
+                    }
+                
+                    rest_server_config_rec_t* server_conf = (rest_server_config_rec_t*)ap_get_module_config(request->server->module_config, &sca_rest_module);
+                    loginfo("Tuscany home: %s", server_conf->home);
+                    if (printRequest)
+                    {
+                        ap_rprintf(request, "<p>Tuscany home: %s", server_conf->home);
+                    }
+                
+                    rest_dir_config_rec_t* dir_conf = (rest_dir_config_rec_t*)ap_get_module_config(request->per_dir_config, &sca_rest_module);
+                    loginfo("Tuscany root: %s", dir_conf->root);
+                    if (printRequest)
+                    {
+                        ap_rprintf(request, "<p>Tuscany root: %s", dir_conf->root);
+                    }
+                    loginfo("Tuscany path: %s", dir_conf->path);
+                    if (printRequest)
+                    {
+                        ap_rprintf(request, "<p>Tuscany path: %s", dir_conf->path);
+                    }
+                    loginfo("SCA component: %s", dir_conf->component);
+                    if (printRequest)
+                    {
+                        ap_rprintf(request, "<p>SCA component: %s", dir_conf->component);
+                    }
+                    
+                    const char* protocol = request->protocol;
+                    if (protocol)
+                    {
+                        loginfo("Protocol: %s", protocol);
+                        if (printRequest)
+                        {
+                            ap_rprintf(request, "<p>Protocol: %s", protocol);
+                        }
+                    }
+                    
+                    const char* method = request->method;
+                    if (method)
+                    {
+                        loginfo("HTTP method: %s", method);
+                        if (printRequest)
+                        {
+                            ap_rprintf(request, "<p>HTTP method: %s", method);
+                        }
+                    }
+                
+                    const int method_number = request->method_number;
+                    loginfo("HTTP method number: %d", method_number);
+                    if (printRequest)
+                    {
+                        ap_rprintf(request, "<p>HTTP method number: %d", method_number);
+                    }
+                    
+                    const char* content_type = apr_table_get(request->headers_in, "Content-Type");
+                    if (content_type)
+                    {
+                        loginfo("Content type: %s", content_type);
+                        if (printRequest)
+                        {
+                            ap_rprintf(request, "<p>Content type: %s", content_type);
+                        }
+                    }
+                
+                    const char* content_encoding = request->content_encoding;
+                    if (content_encoding)
+                    {
+                        loginfo("Content encoding: %s", content_encoding);
+                        if (printRequest)
+                        {
+                            ap_rprintf(request, "<p>Content encoding: %s", content_encoding);
+                        }
+                    }
+                
+                    if (printRequest)
+                    {
+                        ap_rputs("<p>", request);
+                    }
+                    apr_table_do(logHeaders, request, request->headers_in, NULL);
+                    
+                    const char* uri = request->uri;
+                    if (uri)
+                    {
+                        loginfo("URI: %s", uri);
+                        if (printRequest)
+                        {
+                            ap_rprintf(request, "<p>URI: %s", uri);
+                        }
+                    }
+                    
+                    const char* path_info = request->path_info;
+                    if (path_info)
+                    {
+                        loginfo("Path info: %s", path_info);
+                        if (printRequest)
+                        {
+                            ap_rprintf(request, "<p>Path info: %s", path_info);
+                        }
+                    }
+                    
+                    const char* args = request->args;
+                    if (args)
+                    {
+                        loginfo("Args: %s", args);
+                        if (printRequest)
+                        {
+                            ap_rprintf(request, "<p>Args: %s", args);
+                        }
+                    }
+                    
+                    if (printRequest)
+                    {
+                        ap_rputs("</body></html>", request);
+                    }
+                    
+                    if (method_number == M_GET)
+                    {
+                        // Handle an HTTP GET
                         
-static const char *rest_set_root(cmd_parms *cmd, void *conf, 
-                        const char *arg);
+                        // Extract the operation name, service and component names from
+                        // the HTTP URI path
+                        string path;
+                        if (strlen(path_info) != 0 && *path_info == '/')
+                        {
+                            path = path_info + 1;
+                        }
+                        else
+                        {
+                            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
+                            component = dir_conf->component;
+                            service = uri; 
+                        }
+                        else
+                        {
+                            // The path must be in the form component / service
+                            Utils::rTokeniseString("/", uri, component, service);
+                        }
+                
+                        loginfo("Component name: %s", component.c_str());
+                        loginfo("Service name: %s", service.c_str());
                         
-static const char *rest_set_component(cmd_parms *cmd, void *conf, 
-                        const char *arg);
-
-static void* rest_create_svr(apr_pool_t *p, server_rec *s);
-
-
-static const char *rest_set_home(cmd_parms *cmd, void *dummy, 
-                        const char *arg)
-{
-    rest_server_config_rec_t *conf = (rest_server_config_rec_t*)ap_get_module_config(
-                        cmd->server->module_config, &sca_rest_module);
-    conf->home = apr_pstrdup(cmd->pool, arg);
-    return NULL;
-}
-
-static const char *rest_set_path(cmd_parms *cmd, void *c, 
-                        const char *arg)
-{
-    rest_dir_config_rec_t *conf = (rest_dir_config_rec_t*)c;
-    conf->path = apr_pstrdup(cmd->pool, arg);
-    return NULL;
-}
-
-static const char *rest_set_root(cmd_parms *cmd, void *c, 
-                        const char *arg)
-{
-    rest_dir_config_rec_t *conf = (rest_dir_config_rec_t*)c;
-    conf->root = apr_pstrdup(cmd->pool, arg);
-    return NULL;
-}
-
-static const char *rest_set_component(cmd_parms *cmd, void *c, 
-                        const char *arg)
-{
-    rest_dir_config_rec_t *conf = (rest_dir_config_rec_t*)c;
-    conf->component = apr_pstrdup(cmd->pool, arg);
-    return NULL;
-}
-
-
-static const command_rec rest_module_cmds[] = 
-{
-    AP_INIT_TAKE1("TuscanyHome", (const char*(*)())rest_set_home, NULL, RSRC_CONF,
-                  "Tuscany home directory"),
-    AP_INIT_TAKE1("TuscanyPath", (const char*(*)())rest_set_path, NULL, ACCESS_CONF,
-                  "Tuscany SCA composite search path"),
-    AP_INIT_TAKE1("TuscanyRoot", (const char*(*)())rest_set_root, NULL, ACCESS_CONF,
-                  "Tuscany root SCA configuration path"),
-    AP_INIT_TAKE1("TuscanyComponent", (const char*(*)())rest_set_component, NULL, ACCESS_CONF,
-                  "SCA component name"),
-    {NULL}
-};
+                        // Initialize the SCA runtime
+                        CompositeService* compositeService = initializeSCARuntime(
+                                    server_conf->home, dir_conf->root, dir_conf->path, component.c_str(), service.c_str());
+                                    
+                        if(!compositeService)
+                        {
+                            throwException(SystemConfigurationException,
+                                "Failed to initialize SCA runtime, could not initialize CompositeService");
+                        }
+            
+                        DataFactoryPtr dataFactory = compositeService->getComposite()->getDataFactory();
+                        if (dataFactory == 0)
+                        {
+                            throwException(SystemConfigurationException,
+                                "Failed to initialize SCA runtime, could not get DataFactory");
+                        }
+            
+                        // Get the REST binding
+                        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
+                        WSDLOperation wsdlOperation;
+                        string wsdlNamespace = "";
+                        Interface* iface = reference->getType()->getInterface();
+                        if (iface != NULL &&
+                            iface->getInterfaceTypeQName() == WSDLInterface::typeQName)
+                        {
+                            WSDLInterface* wsdlInterface = (WSDLInterface*)iface;
+                            wsdlNamespace = wsdlInterface->getNamespaceURI();
+                            
+                            if (wsdlNamespace != "")
+                            {
+                                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& ex)
+                                {   
+                                    throw;
+                                }
+                            }
+                        }
+                    
+                        // Create a default document literal wrapped WSDL operation
+                        if (wsdlNamespace == "")
+                        {
+                            wsdlNamespace = compositeService->getName();
+                            wsdlOperation = WSDLOperation();
+                            wsdlOperation.setOperationName(op_name.c_str());
+                            wsdlOperation.setSoapAction(wsdlNamespace+ "#" +op_name);
+                            wsdlOperation.setEndpoint("");
+                            wsdlOperation.setSoapVersion(WSDLOperation::SOAP11);
+                            wsdlOperation.setDocumentStyle(true);
+                            wsdlOperation.setWrappedStyle(true);
+                            wsdlOperation.setEncoded(false);
+                            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)
+                        {
+                            string query = args;
+                            for (; query != ""; )
+                            {
+                                string param;
+                                string next;
+                                Utils::tokeniseString("&", query, param, next);
+                                if (param != "")
+                                {
+                                    string n;
+                                    string* data = new string;
+                                    Utils::tokeniseString("=", param, n, *data);
+                                    operation.addParameter(data);    
+                                }
+                               query = next;
+                            }
+                        }
+                        DataObjectPtr inputDataObject = createPayload(dataFactory, operation, wsdlOperation);
+                        
+                        // Dispatch to the REST proxy
+                        DataObjectPtr outputDataObject = proxy->invoke(wsdlOperation, inputDataObject);
+                        
+                        // Send the response back to the client
+                        if (outputDataObject == NULL)
+                        {
+                            loginfo("Sending empty response");
 
+                            // Set the content type
+                            ap_set_content_type(request, "text/xml");
+                        
+                            return OK;
+                        }
+                        
+                        // 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);
+                       
+                        // Set the content type
+                        ap_set_content_type(request, "text/xml");
+                    
+                        loginfo("Sending response: %s", str);
+                       ap_rputs(str, request);
+                       
+                       return OK;
+                    }
+                    else if (method_number == M_POST)
+                    {
+                    }
+                    else if (method_number == M_PUT)
+                    {
+                    }
+                    else if (method_number == M_DELETE)
+                    {
+                    }
+                    else
+                    {
+                        if (method)
+                        {
+                            ostringstream msg;
+                            msg << "Unsupported HTTP method: %s" << method;
+                            throwException(ServiceInvocationException, msg.str().c_str());
+                        }
+                        else
+                        {
+                            throwException(ServiceInvocationException, "Unsupported HTTP method");
+                        }
+                    }
+                    
+                    return OK;
+                }
+                catch(TuscanyRuntimeException& ex)
+                {
+                    ostringstream msg;
+                    msg << ex;
+                    logerror("Failed to process REST request: %s", msg.str().c_str());
+                    return HTTP_INTERNAL_SERVER_ERROR;
+                }        
+            }
+            
+            DataObjectPtr createPayload(DataFactoryPtr dataFactory, Operation& operation, const WSDLOperation& wsdlOperation)
+            {   
+                logentry();
+            
+                DataObjectPtr inputDataObject;
+                try
+                {
+                    
+                    // Create the input wrapper
+                    const Type& rootType = dataFactory->getType(wsdlOperation.getInputTypeUri().c_str(), "RootType");
+                    const Property& prop = rootType.getProperty(wsdlOperation.getInputTypeName().c_str());
+                    const Type& inputType = prop.getType();
+                    inputDataObject = dataFactory->create(inputType);
+                }
+                catch (SDORuntimeException&)
+                {
+                    try
+                    {
+                        // Create the input wrapper
+                        const Type& inputType = dataFactory->getType(wsdlOperation.getInputTypeUri().c_str(), 
+                            wsdlOperation.getInputTypeName().c_str());
+                        inputDataObject = dataFactory->create(inputType);
+                    }
+                    catch (SDORuntimeException&)
+                    {
+                        
+                        // The input wrapper type is not known, create an open DataObject 
+                        inputDataObject = dataFactory->create(Type::SDOTypeNamespaceURI, "OpenDataObject");
+                    }
+                }
+                        
+                // Go through data object to set the input parameters
+                PropertyList pl = inputDataObject->getType().getProperties();
+            
+                if(pl.size() == 0)
+                {
+                    if(inputDataObject->getType().isOpenType() && inputDataObject->getType().isDataObjectType())
+                    {
+                        /*
+                         * This code deals with sending xsd:any elements
+                         */
+                        for (int i=0; i<operation.getNParms(); i++)
+                        {
+                            ostringstream pname;
+                            pname << "param" << (i+1);
+                            DataObjectList& l = inputDataObject->getList(pname.str());
+                            
+                            const Operation::Parameter& parm = operation.getParameter(i);
+                            l.append((*(string*)parm.getValue()).c_str());
+                        }
+                    }
+                }
+                else {
+                    
+                    // Each parameter in the operation should be a property on the request dataobject
+                    for (int i=0; i<operation.getNParms(); i++)
+                    {
+                        const Operation::Parameter& parm = operation.getParameter(i);
+                        inputDataObject->setCString(i, (*(string*)parm.getValue()).c_str());
+                    }
+                }
+                
+                return inputDataObject;
+             }
+
+
+            const char *rest_set_home(cmd_parms *cmd, void *dummy, 
+                                    const char *arg)
+            {
+                rest_server_config_rec_t *conf = (rest_server_config_rec_t*)ap_get_module_config(
+                                    cmd->server->module_config, &sca_rest_module);
+                conf->home = apr_pstrdup(cmd->pool, arg);
+                return NULL;
+            }
+            
+            const char *rest_set_path(cmd_parms *cmd, void *c, 
+                                    const char *arg)
+            {
+                rest_dir_config_rec_t *conf = (rest_dir_config_rec_t*)c;
+                conf->path = apr_pstrdup(cmd->pool, arg);
+                return NULL;
+            }
+            
+            const char *rest_set_root(cmd_parms *cmd, void *c, 
+                                    const char *arg)
+            {
+                rest_dir_config_rec_t *conf = (rest_dir_config_rec_t*)c;
+                conf->root = apr_pstrdup(cmd->pool, arg);
+                return NULL;
+            }
+            
+            const char *rest_set_component(cmd_parms *cmd, void *c, 
+                                    const char *arg)
+            {
+                rest_dir_config_rec_t *conf = (rest_dir_config_rec_t*)c;
+                conf->component = apr_pstrdup(cmd->pool, arg);
+                return NULL;
+            }
+            
+            const command_rec rest_module_cmds[] = 
+            {
+                AP_INIT_TAKE1("TuscanyHome", (const char*(*)())rest_set_home, NULL, RSRC_CONF,
+                              "Tuscany home directory"),
+                AP_INIT_TAKE1("TuscanyPath", (const char*(*)())rest_set_path, NULL, ACCESS_CONF,
+                              "Tuscany SCA composite search path"),
+                AP_INIT_TAKE1("TuscanyRoot", (const char*(*)())rest_set_root, NULL, ACCESS_CONF,
+                              "Tuscany root SCA configuration path"),
+                AP_INIT_TAKE1("TuscanyComponent", (const char*(*)())rest_set_component, NULL, ACCESS_CONF,
+                              "SCA component name"),
+                {NULL}
+            };
+            
+            int rest_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
+                                   server_rec *s)
+            {
+                return OK;
+            }
+            
+            void rest_child_init(apr_pool_t* p, server_rec* svr_rec)
+            {
+                rest_server_config_rec_t *conf = (rest_server_config_rec_t*)ap_get_module_config(
+                                    svr_rec->module_config, &sca_rest_module); 
+            
+                if(false)
+                {
+                    fprintf(stderr, "[Tuscany] Due to one or more errors mod_rest loading"
+                                    " failed. Causing apache2 to stop loading\n");
+                    exit(APEXIT_CHILDFATAL);
+                }
+            }
+            
+            void register_hooks(apr_pool_t *p)
+            {
+                ap_hook_handler(rest_handler, NULL, NULL, APR_HOOK_MIDDLE);
+                ap_hook_post_config(rest_init, NULL, NULL, APR_HOOK_MIDDLE);
+                ap_hook_child_init(rest_child_init, NULL, NULL, APR_HOOK_MIDDLE);
+            }
+            
+            void *rest_create_dir_config(apr_pool_t *p, char *dirspec)
+            {
+                rest_dir_config_rec_t* conf = (rest_dir_config_rec_t* )apr_palloc(p, sizeof(*conf));
+                conf->path = "";
+                conf->root = "";
+                conf->component = "";
+                return conf;
+            }
+            
+            void* rest_create_server_config(apr_pool_t *p, server_rec *s)
+            {
+                rest_server_config_rec_t* conf = (rest_server_config_rec_t* )apr_palloc(p, sizeof(*conf));
+                conf->home = "";
+                return conf;
+            }
+            
+        } // End namespace rest        
+    } // End namespace sca
+} // End namespace tuscany
 
-static int rest_handler(request_rec *request)
+extern "C"
 {
-    
-    if (strcmp(request->handler, "sca_rest_module"))
-    {
-        return DECLINED;
-    }
-    
-    // Set up the read policy
-    int rc = ap_setup_client_block(request, REQUEST_CHUNKED_DECHUNK);
-    if (rc != OK)
-    {
-        return rc;
-    }
-    ap_should_client_block(request);
-    
-    const char* http_version = request->protocol;
-    
-    const char* content_type = apr_table_get(request->headers_in, "Content-Type");
-    request->content_type = content_type;
-    
-    int content_length = request->remaining;
-    if (request->read_chunked == true && content_length == 0)
-    {
-        content_length = -1;
-        request->chunked = true;
-    }
-
-    // Set the content type    
-    ap_set_content_type(request, "text/html");
-    
-    // Send the response document
-    ap_rputs("<html><body><p>mod_rest works!", request);
 
-    rest_server_config_rec_t* server_conf = (rest_server_config_rec_t*)ap_get_module_config(request->server->module_config, &sca_rest_module);
-    ap_rprintf(request, "<p>home: %s", server_conf->home);
-
-    rest_dir_config_rec_t* dir_conf = (rest_dir_config_rec_t*)ap_get_module_config(request->per_dir_config, &sca_rest_module);
-    ap_rprintf(request, "<p>root: %s", dir_conf->root);
-    if (dir_conf->path)
-    {
-        ap_rprintf(request, "<p>path: %s", dir_conf->path);
-    }
-    if (dir_conf->path)
+    module AP_MODULE_DECLARE_DATA sca_rest_module =
     {
-        ap_rprintf(request, "<p>component: %s", dir_conf->component);
-    }
+        STANDARD20_MODULE_STUFF,
+        rest_create_dir_config,         /* dir config */
+        NULL,                       /* dir merger --- default is to override */
+        rest_create_server_config,        /* server config */
+        NULL,                       /* merge server config */
+        rest_module_cmds,         /* command table */
+        register_hooks              /* register_hooks */
+    };
     
-    ap_rputs("</body></html>", request);
-    
-    //return HTTP_INTERNAL_SERVER_ERROR;
-    return OK;
-}
-
-static int rest_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
-                       server_rec *s)
-{
-    return OK;
-}
-
-static void rest_child_init(apr_pool_t* p, server_rec* svr_rec)
-{
-    rest_server_config_rec_t *conf = (rest_server_config_rec_t*)ap_get_module_config(
-                        svr_rec->module_config, &sca_rest_module); 
-
-    if(false)
-    {
-        fprintf(stderr, "[Tuscany] Due to one or more errors mod_rest loading"
-                        " failed. Causing apache2 to stop loading\n");
-        exit(APEXIT_CHILDFATAL);
-    }
-}
-
-static void register_hooks(apr_pool_t *p)
-{
-    ap_hook_handler(rest_handler, NULL, NULL, APR_HOOK_MIDDLE);
-    ap_hook_post_config(rest_init, NULL, NULL, APR_HOOK_MIDDLE);
-    ap_hook_child_init(rest_child_init, NULL, NULL, APR_HOOK_MIDDLE);
-}
-
-static void *rest_create_dir_config(apr_pool_t *p, char *dirspec)
-{
-    rest_dir_config_rec_t* conf = (rest_dir_config_rec_t* )apr_palloc(p, sizeof(*conf));
-    conf->path = NULL;
-    conf->root = NULL;
-    conf->component = NULL;
-    return conf;
-}
-
-static void* rest_create_server_config(apr_pool_t *p, server_rec *s)
-{
-    rest_server_config_rec_t* conf = (rest_server_config_rec_t* )apr_palloc(p, sizeof(*conf));
-    conf->home = NULL;
-    return conf;
-}
-
-module AP_MODULE_DECLARE_DATA sca_rest_module =
-{
-    STANDARD20_MODULE_STUFF,
-    rest_create_dir_config,         /* dir config */
-    NULL,                       /* dir merger --- default is to override */
-    rest_create_server_config,        /* server config */
-    NULL,                       /* merge server config */
-    rest_module_cmds,         /* command table */
-    register_hooks              /* register_hooks */
-};
-
 }

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=479337&r1=479336&r2=479337
==============================================================================
--- 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 Sun Nov 26 02:52:03 2006
@@ -1,18 +1,20 @@
 /*
- *
- *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *   
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  */
 
 /* $Rev$ $Date$ */
@@ -31,8 +33,13 @@
 #include "tuscany/sca/core/ServiceWrapper.h"
 #include "tuscany/sca/model/Composite.h"
 #include "tuscany/sca/model/ServiceBinding.h"
+#include "tuscany/sca/model/WSDLDefinition.h"
+#include "tuscany/sca/model/WSDLInterface.h"
+#include "tuscany/sca/model/WSDLOperation.h"
 #include "model/RESTReferenceBinding.h"
 
+#include <sstream>
+
 #include "commonj/sdo/SDO.h"
 using namespace commonj::sdo;
 
@@ -83,7 +90,13 @@
                         "http://schemas.xmlsoap.org/soap/envelope/", "Body",
                         false, false, true);
                 }
-                
+
+                try {
+                    const Type& tempType = dataFactory->getType("http://tempuri.org", "RootType");
+                } catch (SDORuntimeException&)
+                {
+                    dataFactory->addType("http://tempuri.org", "RootType", false, false, false);                
+                }
             }
             
             // ==========
@@ -97,7 +110,7 @@
             ///
             /// This method will be called to process an operation invocation.
             ///
-            DataObjectPtr RESTServiceProxy::invoke(const string& operationName, DataObjectPtr inputDataObject)
+            DataObjectPtr RESTServiceProxy::invoke(const WSDLOperation& wsdlOperation, DataObjectPtr inputDataObject)
             {
                 logentry();
     
@@ -108,264 +121,239 @@
                 RESTReferenceBinding* referenceBinding = (RESTReferenceBinding*)reference->getBinding();
                 DataFactoryPtr dataFactoryPtr = reference->getComponent()->getComposite()->getDataFactory();
                                     
-//                const char* outputTypeURI = "";
-//                const char* outputTypeName = "";
-//
-//                LOGINFO_2(4, "RESTServiceProxy has got WSDLOperation with inputType: %s#%s",
-//                    wsdlOperation.getInputTypeUri().c_str(), 
-//                    wsdlOperation.getInputTypeName().c_str());
-//                LOGINFO_2(4, "RESTServiceProxy has got WSDLOperation with outputType: %s#%s",
-//                    outputTypeURI, 
-//                    outputTypeName);
-//                LOGINFO_2(4, "RESTServiceProxy has got WSDLOperation with documentStyle=%d and wrapped=%d",        
-//                    documentStyle,
-//                    wrappedStyle);
-//                
-//                if (documentStyle)
-//                {
-//                    if (wrappedStyle)
-//                    {
-//
-//                        // Create new Operation object and set parameters and return value
-//                        Operation operation(wsdlOperation.getOperationName().c_str());
-//                    
-//                        // Go through the input data object to set the operation parameters
-//                        PropertyList pl = inputDataObject->getInstanceProperties();
-//                    
-//                        for(int i=0; i<pl.size(); i++)
-//                        {
-//                            const char* name = pl[i].getName();
-//                    
-//                            switch (pl[i].getTypeEnum()) 
-//                            {
-//                            case Type::BooleanType:
-//                                {
-//                                    bool* boolData = new bool;
-//                                    *boolData = inputDataObject->getBoolean(pl[i]);
-//                                    operation.addParameter(boolData);
-//                                }
-//                                break;
-//                            case Type::ByteType:
-//                                {
-//                                    char* byteData = new char;
-//                                    *byteData = inputDataObject->getByte(pl[i]);
-//                                    operation.addParameter(byteData);
-//                                }
-//                                break;
-//                            case Type::BytesType:
-//                                {
-//                                    int len = inputDataObject->getLength(pl[i]);
-//                                    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;
-//                                    }
-//                                    else
-//                                    {
-//                                        bytesData[len] = 0;
-//                                    }
-//                                    operation.addParameter(&bytesData);
-//                                }
-//                                break;
-//                            case Type::CharacterType:
-//                                {
-//                                    // This code should work but won't be used as there is no mapping from an XSD type to the SDO CharacterType
-//                                    wchar_t* charData = new wchar_t;
-//                                    *charData = inputDataObject->getCharacter(pl[i]);
-//                                    operation.addParameter(charData);
-//                                }
-//                                break;
-//                            case Type::DoubleType:
-//                                {
-//                                    long double* doubleData = new long double;
-//                                    *doubleData = inputDataObject->getDouble(pl[i]);
-//                                    operation.addParameter(doubleData);
-//                                }
-//                                break;
-//                            case Type::FloatType:
-//                                {
-//                                    float* floatData = new float;
-//                                    *floatData = inputDataObject->getFloat(pl[i]);
-//                                    operation.addParameter(floatData); 
-//                                }
-//                                break;
-//                            case Type::IntegerType:
-//                                {
-//                                    long* intData = new long;
-//                                    *intData = inputDataObject->getInteger(pl[i]);
-//                                    operation.addParameter(intData);
-//                                }
-//                                break;
-//                            case Type::ShortType:
-//                                {
-//                                    short* shortData = new short;
-//                                    *shortData = inputDataObject->getShort(pl[i]);
-//                                    operation.addParameter(shortData);
-//                                }
-//                                break;
-//                            case Type::StringType:
-//                                {
-//                                    string* stringData;
-//                                    if(inputDataObject->isSet(pl[i]))
-//                                    {
-//                                        stringData = new string(inputDataObject->getCString(pl[i]));                                        
-//                                    }
-//                                    else
-//                                    {
-//                                        // The data is not set, so pass an empty string as the parameter
-//                                        stringData = new string();
-//                                    }
-//                                    operation.addParameter(stringData);
-//                                }
-//                                break;
-//                            case Type::DataObjectType:
-//                                {
-//                                    DataObjectPtr dataObjectData = inputDataObject->getDataObject(pl[i]);
-//                    
-//                                    if(!dataObjectData)
-//                                    {
-//                                        LOGINFO_1(4, "SDO DataObject parameter named %s was null", name);
-//                                    }
-//                                    operation.addParameter(&dataObjectData);
-//                                }
-//                                break;
-//                            case Type::OpenDataObjectType:
-//                                {         
-//                                    /*
-//                                     * This code deals with xsd:any element parameters
-//                                     * Get each element as a DataObject and add in to the parameter list
-//                                     */
-//                    
-//                                    DataObjectList& dataObjectList = inputDataObject->getList(pl[i]);
-//                                    
-//                                    for(int j=0; j<dataObjectList.size(); j++)
-//                                    {
-//                                        DataObjectPtr dataObjectData = dataObjectList[j];
-//                                        if(!dataObjectData)
-//                                        {
-//                                            
-//                                            // Add a null DataObject ptr
-//                                            LOGINFO_2(4, "SDO OpenDataObject parameter named %s[%d] was null", name, j);
-//                                            operation.addParameter(&dataObjectData);
-//                                        }
-//                                        else
-//                                        {
-//                                            
-//                                            SequencePtr sequence = dataObjectData->getSequence();
-//                                            if (sequence->size()!=0)
-//                                            {
-//                                                // Add a text element        
-//                                                if (sequence->isText(0))
-//                                                {                                        
-//                                                    string* stringData = new string(sequence->getCStringValue(0));
-//                                                    operation.addParameter(stringData);
-//                                                }
-//                                                else
-//                                                {
-//                                                    // Add a complex element DataObject
-//                                                    DataObjectPtr dob = sequence->getDataObjectValue(0);
-//                                                    if(!dob)
-//                                                    {
-//                                                        LOGINFO_1(4, "SDO DataObject parameter named %s was null", name);
-//                                                    }
-//                                                    operation.addParameter(&dob);
-//                                                }
-//                                            }
-//                                            else
-//                                            {
-//                                                // Empty content, add an empty string
-//                                                LOGINFO_2(4, "SDO OpenDataObject parameter named %s[%d] was empty", name, j);
-//                                                string* stringData = new string(""); 
-//                                                operation.addParameter(stringData);
-//                                            }
-//                                        }                       
-//                                    }
-//                                }
-//                                break;
-//                            case Type::DateType:
-//                                LOGERROR_1(0, "SDO DateType parameters are not yet supported (%s)", name);
-//                                return NULL;
-//                            case Type::LongType:
-//                                LOGERROR_1(0, "SDO LongType (int64_t) parameters are not yet supported (%s)", name);
-//                                return NULL;
-//                                break;
-//                            case Type::UriType:
-//                                LOGERROR_1(0, "SDO UriType parameters are not yet supported (%s)", name);
-//                                return NULL;
-//                                break;
-//                            case Type::BigDecimalType:
-//                                LOGERROR_1(0, "SDO BigDecimalType parameters are not yet supported (%s)", name);
-//                                return NULL;
-//                                break;
-//                            case Type::BigIntegerType:
-//                                LOGERROR_1(0, "SDO BigIntegerType parameters are not yet supported (%s)", name);
-//                                return NULL;
-//                                break;
-//                            default:
-//                                LOGERROR_1(0, "Unknown SDO type parameter named %s has been found. Unknown types are not yet supported", name);
-//                                return NULL;
-//                            }         
-//                        }
-//                                
-//                        try
-//                        {
-//                            
-//                            // Call into the target service wrapper
-//                            serviceWrapper->invoke(operation);
-//                    
-//                            // Set the data in the outputDataObject to be returned
-//                            DataObjectPtr outputDataObject;
-//                            try
-//                            {
-//                                
-//                                // Create the output wrapper
-//                                const Type& outputType = dataFactoryPtr->getType(outputTypeURI, outputTypeName);
-//                                outputDataObject = dataFactoryPtr->create(outputType);
-//                            }
-//                            catch (SDORuntimeException&)
-//                            {
-//                                // The output wrapper type is not known, create an open DataObject 
-//                                outputDataObject = dataFactoryPtr->create(Type::SDOTypeNamespaceURI, "OpenDataObject");
-//                            }
-//                            
-//                            setOutputData(operation, outputDataObject, dataFactoryPtr);                            
-//
-//                            return outputDataObject;
-//
-//                        }
-//                      catch(SDORuntimeException& ex)
-//                      {   
-//                            // TODO: Return more error information than just a null DataObject
-//                            LOGERROR_2(0, "%s has been caught: %s\n", ex.getEClassName(), ex.getMessageText());
-//                            return NULL;
-//                      }  
-//                      catch(TuscanyRuntimeException& ex)
-//                      {   
-//                            // TODO: Return more error information than just a null DataObject
-//                            LOGERROR_2(0, "%s has been caught: %s\n", ex.getEClassName(), ex.getMessageText());
-//                            return NULL;
-//                      }  
-//                    }
-//                    else
-//                    {
-//                        LOGERROR(0, "CompositeServices with non-wrapped document style WSDL Operations are not yet supported");
-//                        return NULL;
-//                    }
-//                }
-//                else
-//                {
-//                    // RPC style
-//                    LOGERROR(0, "CompositeServices with RPC style WSDL Operations are not yet supported");
-//                    return NULL;
-//                }
+                const char* outputTypeURI = wsdlOperation.getOutputTypeUri().c_str();
+                const char* outputTypeName = wsdlOperation.getOutputTypeName().c_str();
 
-                return NULL;
+                loginfo("WSDLOperation inputType: %s#%s",
+                    wsdlOperation.getInputTypeUri().c_str(), 
+                    wsdlOperation.getInputTypeName().c_str());
+                loginfo("WSDLOperation outputType: %s#%s",
+                    outputTypeURI, 
+                    outputTypeName);
+                
+                // Create new Operation object and set parameters and return value
+                Operation operation(wsdlOperation.getOperationName().c_str());
+            
+                try
+                {
+                    
+                    // Go through the input data object to set the operation parameters
+                    PropertyList pl = inputDataObject->getInstanceProperties();
+                
+                    for(int i=0; i<pl.size(); i++)
+                    {
+                        const char* name = pl[i].getName();
+                
+                        switch (pl[i].getTypeEnum()) 
+                        {
+                        case Type::BooleanType:
+                            {
+                                bool* boolData = new bool;
+                                *boolData = inputDataObject->getBoolean(pl[i]);
+                                operation.addParameter(boolData);
+                            }
+                            break;
+                        case Type::ByteType:
+                            {
+                                char* byteData = new char;
+                                *byteData = inputDataObject->getByte(pl[i]);
+                                operation.addParameter(byteData);
+                            }
+                            break;
+                        case Type::BytesType:
+                            {
+                                int len = inputDataObject->getLength(pl[i]);
+                                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;
+                                }
+                                else
+                                {
+                                    bytesData[len] = 0;
+                                }
+                                operation.addParameter(&bytesData);
+                            }
+                            break;
+                        case Type::CharacterType:
+                            {
+                                // This code should work but won't be used as there is no mapping from an XSD type to the SDO CharacterType
+                                wchar_t* charData = new wchar_t;
+                                *charData = inputDataObject->getCharacter(pl[i]);
+                                operation.addParameter(charData);
+                            }
+                            break;
+                        case Type::DoubleType:
+                            {
+                                long double* doubleData = new long double;
+                                *doubleData = inputDataObject->getDouble(pl[i]);
+                                operation.addParameter(doubleData);
+                            }
+                            break;
+                        case Type::FloatType:
+                            {
+                                float* floatData = new float;
+                                *floatData = inputDataObject->getFloat(pl[i]);
+                                operation.addParameter(floatData); 
+                            }
+                            break;
+                        case Type::IntegerType:
+                            {
+                                long* intData = new long;
+                                *intData = inputDataObject->getInteger(pl[i]);
+                                operation.addParameter(intData);
+                            }
+                            break;
+                        case Type::ShortType:
+                            {
+                                short* shortData = new short;
+                                *shortData = inputDataObject->getShort(pl[i]);
+                                operation.addParameter(shortData);
+                            }
+                            break;
+                        case Type::StringType:
+                            {
+                                string* stringData;
+                                if (pl[i].isMany())
+                                {
+                                    DataObjectList& l = inputDataObject->getList(pl[i]);
+                                    stringData = new string(l.getCString(0));                                        
+                                }
+                                else
+                                {
+                                    if(inputDataObject->isSet(pl[i]))
+                                    {
+                                        stringData = new string(inputDataObject->getCString(pl[i]));                                        
+                                    }
+                                    else
+                                    {
+                                        // The data is not set, so pass an empty string as the parameter
+                                        stringData = new string();
+                                    }
+                                }
+                                operation.addParameter(stringData);
+                            }
+                            break;
+                        case Type::DataObjectType:
+                            {
+                                DataObjectPtr dataObjectData = inputDataObject->getDataObject(pl[i]);
+                                if(!dataObjectData)
+                                {
+                                    loginfo("Null DataObject parameter named %s", name);
+                                }
+                                operation.addParameter(&dataObjectData);
+                            }
+                            break;
+                        case Type::OpenDataObjectType:
+                            {         
+                                /*
+                                 * This code deals with xsd:any element parameters
+                                 * Get each element as a DataObject and add in to the parameter list
+                                 */
+                
+                                DataObjectList& dataObjectList = inputDataObject->getList(pl[i]);
+                                
+                                for(int j=0; j<dataObjectList.size(); j++)
+                                {
+                                    DataObjectPtr dataObjectData = dataObjectList[j];
+                                    if(!dataObjectData)
+                                    {
+                                        
+                                        // Add a null DataObject ptr
+                                        loginfo("Null OpenDataObject parameter named %s[%d]", name, j);
+                                        operation.addParameter(&dataObjectData);
+                                    }
+                                    else
+                                    {
+                                        
+                                        SequencePtr sequence = dataObjectData->getSequence();
+                                        if (sequence->size()!=0)
+                                        {
+                                            // Add a text element        
+                                            if (sequence->isText(0))
+                                            {                                        
+                                                string* stringData = new string(sequence->getCStringValue(0));
+                                                operation.addParameter(stringData);
+                                            }
+                                            else
+                                            {
+                                                // Add a complex element DataObject
+                                                DataObjectPtr dob = sequence->getDataObjectValue(0);
+                                                if(!dob)
+                                                {
+                                                    loginfo("Null DataObject parameter named %s", name);
+                                                }
+                                                operation.addParameter(&dob);
+                                            }
+                                        }
+                                        else
+                                        {
+                                            // Empty content, add an empty string
+                                            loginfo("Empty OpenDataObject parameter named %s[%d]", name, j);
+                                            string* stringData = new string(""); 
+                                            operation.addParameter(stringData);
+                                        }
+                                    }                       
+                                }
+                            }
+                            break;
+                        default:
+                            {
+                                ostringstream msg;
+                                msg << "Unsupported param type: " << pl[i].getTypeEnum();
+                                throwException(SystemConfigurationException, msg.str().c_str());
+                            }
+                        }         
+                    }
+                            
+                    // Call into the target service wrapper
+                    serviceWrapper->invoke(operation);
+            
+                    // Set the data in the outputDataObject to be returned
+                    DataObjectPtr outputDataObject;
+                    try {
+                        
+                        // Create the output wrapper
+                        const Type& rootType = dataFactoryPtr->getType(outputTypeURI, "RootType");
+                        const Property& prop = rootType.getProperty(outputTypeName);
+                        const Type& outputType = prop.getType();
+                        outputDataObject = dataFactoryPtr->create(outputType);
+                    }
+                    catch (SDORuntimeException&)
+                    {
+                        try
+                        {
+                            
+                            // Create the output wrapper
+                            const Type& outputType = dataFactoryPtr->getType(outputTypeURI, outputTypeName);
+                            outputDataObject = dataFactoryPtr->create(outputType);
+                        }
+                        catch (SDORuntimeException&)
+                        {
+                            // The output wrapper type is not known, create an open DataObject 
+                            outputDataObject = dataFactoryPtr->create(Type::SDOTypeNamespaceURI, "OpenDataObject");
+                        }
+                    }
+                    
+                    setOutputData(operation, outputDataObject, dataFactoryPtr);                            
+
+                    return outputDataObject;
+
+                }
+                catch(SDORuntimeException& ex)
+                {
+                    throwException(ServiceInvocationException, ex);   
+                }  
+                catch(TuscanyRuntimeException& ex)
+                {
+                    throw;   
+                }  
             }
             
             
-            void RESTServiceProxy::setOutputData(Operation operation, DataObjectPtr outputDataObject, DataFactoryPtr dataFactoryPtr)
+            void RESTServiceProxy::setOutputData(Operation& operation, DataObjectPtr outputDataObject, DataFactoryPtr dataFactoryPtr)
             {    
                 logentry();
 
@@ -450,9 +438,9 @@
                             }
                         default:
                             {
-                                string msg = "Unsupported parameter type";
-                                msg += resultType;
-                                throwException(ServiceDataException, msg.c_str()); 
+                                ostringstream msg;
+                                msg << "Unsupported result type: " << resultType;
+                                throwException(SystemConfigurationException, msg.str().c_str());
                             }
                         }
                     }
@@ -547,16 +535,16 @@
                                 }
                                 else
                                 {
-                                    loginfo("Null return value, so leaving property %s unset", pl[i].getName());
+                                    loginfo("Null return value, leaving property %s unset", pl[i].getName());
                                 }
                                 
                                 break;
                             }
                         default:
                             {
-                                string msg = "Unsupported parameter type";
-                                msg += resultType;
-                                throwException(ServiceDataException, msg.c_str()); 
+                                ostringstream msg;
+                                msg << "Unsupported result type: " << resultType;
+                                throwException(SystemConfigurationException, msg.str().c_str());
                             }
                         }
                     }

Modified: incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.h?view=diff&rev=479337&r1=479336&r2=479337
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.h (original)
+++ incubator/tuscany/cpp/sca/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.h Sun Nov 26 02:52:03 2006
@@ -25,6 +25,7 @@
 #include "tuscany/sca/model/Component.h"
 #include "tuscany/sca/model/Reference.h"
 #include "tuscany/sca/model/Service.h"
+#include "tuscany/sca/model/WSDLOperation.h"
 #include "model/RESTReferenceBinding.h"
 #include "commonj/sdo/SDO.h"
 
@@ -73,11 +74,11 @@
                 /**
                  * Invoke the specified operation
                  */
-                DataObjectPtr invoke(const string& operationName, DataObjectPtr inputDataObject);    
+                DataObjectPtr invoke(const WSDLOperation& wsdlOperation, DataObjectPtr inputDataObject);    
     
             private:
 
-                void setOutputData(Operation operation, DataObjectPtr outputDataObject, DataFactoryPtr dataFactoryPtr);
+                void setOutputData(Operation& operation, DataObjectPtr outputDataObject, DataFactoryPtr dataFactoryPtr);
                 
                 /**
                  * The target service wrapper



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