From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../runtime/extensions/rest/service/Makefile.am | 1 + .../runtime/extensions/rest/service/deploy.bat | 66 + .../runtime/extensions/rest/service/deploymod.bat | 63 + .../extensions/rest/service/httpd/Makefile.am | 1 + .../extensions/rest/service/httpd/src/Makefile.am | 44 + .../service/httpd/src/tuscany/sca/rest/ModREST.cpp | 1351 ++++++++++++++++++++ .../sca/rest/RESTReferenceBindingExtension.cpp | 86 ++ .../sca/rest/RESTReferenceBindingExtension.h | 75 ++ .../src/tuscany/sca/rest/RESTServiceProxy.cpp | 559 ++++++++ .../httpd/src/tuscany/sca/rest/RESTServiceProxy.h | 95 ++ .../service/httpd/src/tuscany/sca/rest/export.h | 38 + .../sca/rest/model/RESTReferenceBinding.cpp | 66 + .../tuscany/sca/rest/model/RESTReferenceBinding.h | 90 ++ 13 files changed, 2535 insertions(+) create mode 100644 tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/Makefile.am create mode 100644 tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/deploy.bat create mode 100644 tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/deploymod.bat create mode 100644 tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/Makefile.am create mode 100644 tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/Makefile.am create mode 100644 tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp create mode 100644 tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTReferenceBindingExtension.cpp create mode 100644 tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTReferenceBindingExtension.h create mode 100644 tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.cpp create mode 100644 tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.h create mode 100644 tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/export.h create mode 100644 tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/model/RESTReferenceBinding.cpp create mode 100644 tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/model/RESTReferenceBinding.h (limited to 'tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service') diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/Makefile.am b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/Makefile.am new file mode 100644 index 0000000000..2ecfda6c6c --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = httpd \ No newline at end of file diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/deploy.bat b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/deploy.bat new file mode 100644 index 0000000000..bea89aa81d --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/deploy.bat @@ -0,0 +1,66 @@ +@echo off + +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. + + +setlocal + +if . == .%1 ( +echo sca root not specified +goto usage +) +set rootdir=%1 +set deploydir=%rootdir%\deploy +set extdir=%deploydir%\extensions +set restextdir=%extdir%\rest +set svcextdir=%restextdir%\service +set srcdir=%rootdir%\runtime\extensions\rest\service\httpd\src + +if . == .%2 ( +echo input directory not specified +goto usage +) +set inpath=%2 +echo %inpath% + +if not exist %deploydir% mkdir %deploydir% +if not exist %extdir% mkdir %extdir% +if not exist %restextdir% mkdir %restextdir% +if not exist %svcextdir% mkdir %svcextdir% +if not exist %svcextdir%\module mkdir %svcextdir%\module +if not exist %svcextdir%\bin mkdir %svcextdir%\bin +if not exist %svcextdir%\lib mkdir %svcextdir%\lib + +set libname=tuscany_sca_rest_service + +del %svcextdir%\bin\%libname%.* +del %svcextdir%\lib\%libname%.* + +copy %inpath%\%libname%.lib %svcextdir%\lib +copy %inpath%\%libname%.dll %svcextdir%\bin +copy %inpath%\%libname%.dll %svcextdir%\module + +if exist %inpath%\%libname%.pdb copy %inpath%\%libname%.pdb %svcextdir%\bin +if exist %inpath%\%libname%.pdb copy %inpath%\%libname%.pdb %svcextdir%\module + +goto end +:usage +echo Usage: deploy +:end + +endlocal diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/deploymod.bat b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/deploymod.bat new file mode 100644 index 0000000000..b10b15d5c1 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/deploymod.bat @@ -0,0 +1,63 @@ +@echo off + +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. + + +setlocal + +if . == .%1 ( +echo sca root not specified +goto usage +) +set rootdir=%1 +set deploydir=%rootdir%\deploy +set extdir=%deploydir%\extensions +set restextdir=%extdir%\rest +set svcextdir=%restextdir%\service +set srcdir=%rootdir%\runtime\extensions\rest\service\httpd\src + +if . == .%2 ( +echo input directory not specified +goto usage +) +set inpath=%2 +echo %inpath% + +if not exist %deploydir% mkdir %deploydir% +if not exist %extdir% mkdir %extdir% +if not exist %restextdir% mkdir %restextdir% +if not exist %svcextdir% mkdir %svcextdir% +if not exist %svcextdir%\bin mkdir %svcextdir%\bin +if not exist %svcextdir%\lib mkdir %svcextdir%\lib + +set libname=tuscany_sca_mod_rest + +del %svcextdir%\bin\%libname%.* +del %svcextdir%\lib\%libname%.* + +copy %inpath%\%libname%.lib %svcextdir%\lib +copy %inpath%\%libname%.dll %svcextdir%\bin + +if exist %inpath%\%libname%.pdb copy %inpath%\%libname%.pdb %svcextdir%\bin + +goto end +:usage +echo Usage: deploy +:end + +endlocal diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/Makefile.am b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/Makefile.am new file mode 100644 index 0000000000..f963effea2 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = src \ No newline at end of file diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/Makefile.am b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/Makefile.am new file mode 100644 index 0000000000..49d11faee3 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/Makefile.am @@ -0,0 +1,44 @@ +libdir=$(prefix)/extensions/rest/service/lib +lib_LTLIBRARIES = \ +libtuscany_sca_rest_service.la \ +libtuscany_sca_mod_rest.la + +noinst_HEADERS = \ +tuscany/sca/rest/*.h \ +tuscany/sca/rest/model/*.h + +libtuscany_sca_rest_service_la_SOURCES = \ +tuscany/sca/rest/RESTReferenceBindingExtension.cpp \ +tuscany/sca/rest/model/RESTReferenceBinding.cpp \ +tuscany/sca/rest/RESTServiceProxy.cpp + +libtuscany_sca_rest_service_la_LIBADD = \ + -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo \ + -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 + +libtuscany_sca_mod_rest_la_SOURCES = \ +tuscany/sca/rest/ModREST.cpp + +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/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} -I${APR_INCLUDE} + +AM_CPPFLAGS = $(CPPFLAGS) -D_DEBUG + +moduledir=$(prefix)/extensions/rest/service/module +extension = libtuscany_sca_rest_service$(libsuffix) + +install-exec-hook: + test -z $(moduledir) || $(mkdir_p) $(moduledir); + -rm -f $(moduledir)/$(extension) + $(LN_S) $(libdir)/$(extension) $(moduledir)/$(extension) \ No newline at end of file diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp new file mode 100644 index 0000000000..eb3ac60e01 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp @@ -0,0 +1,1351 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * 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. + */ + +#include + +#include "apr_strings.h" +#include "apr_fnmatch.h" +#include "apr_lib.h" + +#define APR_WANT_STRFUNC +#include "apr_want.h" +#include "ap_config.h" +#include "httpd.h" + +// This section removes the windows/httpd build error "strtoul_is_not_a_portable_function_use_strtol_instead" +#if defined(WIN32) || defined (_WINDOWS) +#ifdef strtoul +#undef strtoul +#endif +#define strtoul strtoul +#endif + +#include "http_config.h" +#include "http_core.h" +#include "http_request.h" +#include "http_protocol.h" +#include "http_log.h" +#include "http_main.h" +#include "util_script.h" +#include "util_md5.h" + +#include "mod_core.h" + +#include "commonj/sdo/SDO.h" + +#include "tuscany/sca/core/Exceptions.h" +#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" +#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" + +using namespace std; +using namespace commonj::sdo; +using namespace tuscany::sca; +using namespace tuscany::sca::model; +using namespace tuscany::sca::util; + + +extern "C" +{ + extern module AP_MODULE_DECLARE_DATA sca_rest_module; +} + +namespace tuscany +{ + 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 * base_uri; + char * component; + } rest_dir_config_rec_t; + + CompositeService* initializeSCARuntime(const char* home, const char* root, + const char* path, const char* baseURI, const char *component, const char* service); + + DataObjectPtr createPayload(DataFactoryPtr dataFactory, + Operation& operation, const WSDLOperation& wsdlOperation); + + void addPart(XMLHelper* xmlHelper, string& payload, Operation& operation); + + 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* baseURI, const char *component, const char* service) + { + logentry(); + loginfo("Home: %s", home); + loginfo("Root: %s", root); + loginfo("Path: %s", path); + loginfo("Base URI: %s", baseURI); + loginfo("Component: %s", component); + loginfo("Service: %s", service); + + try + { + SCARuntime* runtime = SCARuntime::initializeSharedRuntime(home, root, path, baseURI); + + string componentName; + if (strlen(component)) + { + componentName = component; + } + else + { + componentName = runtime->getDefaultComponentName(); + } + string serviceName = service; + + loginfo("Resolving composite: %s, service: %s", componentName.c_str(), serviceName.c_str()); + Component* compositeComponent = runtime->getSystem()->findComponent(componentName); + if (compositeComponent == NULL) + { + string msg = "Component not found " + componentName; + throwException(SystemConfigurationException, msg.c_str()); + } + runtime->setDefaultComponent(compositeComponent); + + 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, "
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); + if (request->read_chunked == true && request->remaining == 0) + { + request->chunked = true; + } + + apr_table_setn(request->headers_out, "Connection", "close"); + + if (printRequest) + { + // Set the content type + ap_set_content_type(request, "text/html"); + + // Send the response document + ap_rputs("

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, "

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, "

Tuscany root: %s", dir_conf->root); + } + loginfo("Tuscany path: %s", dir_conf->path); + if (printRequest) + { + ap_rprintf(request, "

Tuscany path: %s", dir_conf->path); + } + loginfo("SCA component: %s", dir_conf->component); + if (printRequest) + { + ap_rprintf(request, "

SCA component: %s", dir_conf->component); + } + + if (request->protocol) + { + loginfo("Protocol: %s", request->protocol); + if (printRequest) + { + ap_rprintf(request, "

Protocol: %s", request->protocol); + } + } + + if (request->method) + { + loginfo("HTTP method: %s", request->method); + if (printRequest) + { + ap_rprintf(request, "

HTTP method: %s", request->method); + } + } + + loginfo("HTTP method number: %d", request->method_number); + if (printRequest) + { + ap_rprintf(request, "

HTTP method number: %d", request->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, "

Content type: %s", content_type); + } + } + else + { + content_type = "text/plain"; + } + + if (request->content_encoding) + { + loginfo("Content encoding: %s", request->content_encoding); + if (printRequest) + { + ap_rprintf(request, "

Content encoding: %s", request->content_encoding); + } + } + + if (printRequest) + { + ap_rputs("

", request); + } + apr_table_do(logHeaders, request, request->headers_in, NULL); + + if (request->uri) + { + loginfo("URI: %s", request->uri); + if (printRequest) + { + ap_rprintf(request, "

URI: %s", request->uri); + } + } + + if (request->path_info) + { + loginfo("Path info: %s", request->path_info); + if (printRequest) + { + ap_rprintf(request, "

Path info: %s", request->path_info); + } + } + + if (request->args) + { + loginfo("Args: %s", request->args); + if (printRequest) + { + ap_rprintf(request, "

Args: %s", request->args); + } + } + + if (printRequest) + { + ap_rputs("", request); + } + + // Extract the service and component names from the HTTP URI path + string path; + if (strlen(request->path_info) != 0 && *(request->path_info) == '/') + { + path = request->path_info + 1; + } + else + { + path = request->path_info; + } + string uri; + + string component; + string service; + if (strlen(dir_conf->component)) + { + // The path only specifies the service, the component name + // is configured in the directory/location configured + component = dir_conf->component; + Utils::tokeniseString("/", path, service, uri); + } + else + { + // The path must be in the form component / service + string path2; + Utils::tokeniseString("/", path, component, path2); + Utils::tokeniseString("/", path2, service, uri); + } + + loginfo("Component name: %s", component.c_str()); + loginfo("Service name: %s", service.c_str()); + + // Initialize the SCA runtime + CompositeService* compositeService = initializeSCARuntime( + server_conf->home, dir_conf->root, dir_conf->path, dir_conf->base_uri, component.c_str(), service.c_str()); + + if(!compositeService) + { + throwException(SystemConfigurationException, + "Failed to initialize SCA runtime, could not initialize CompositeService"); + } + + Composite* composite = compositeService->getComposite(); + DataFactoryPtr dataFactory = composite->getDataFactory(); + if (dataFactory == 0) + { + throwException(SystemConfigurationException, + "Failed to initialize SCA runtime, could not get DataFactory"); + } + XMLHelper* xmlHelper = composite->getXMLHelper(); + + // Get the REST binding + Reference* reference = compositeService->getReference(); + RESTReferenceBinding* binding = (RESTReferenceBinding*)reference->getBinding(); + + // Get the REST proxy + RESTServiceProxy* proxy = (RESTServiceProxy*)binding->getServiceProxy(); + + // Get the component interface + Interface* iface = reference->getType()->getInterface(); + + if (request->method_number == M_GET) + { + // Handle an HTTP GET + + // Determine the operation to invoke + WSDLOperation wsdlOperation; + string wsdlNamespace = ""; + string op_name = ""; + string uriArgs = ""; + if (iface != NULL) + { + // If we have a REST interface, the operation name is "retrieve" + if (iface->getInterfaceTypeQName() == RESTInterface::typeQName) + { + 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 != "") + { + 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 == "") + { + 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"); + } + + // Create the input DataObject + Operation operation(op_name.c_str()); + + // Parse the args part of the URI + if (uriArgs != "") + { + 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 (request->args) + { + string query = request->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 output DataObject + if (iface!=NULL && + iface->getInterfaceTypeQName() == RESTInterface::typeQName) + { + if (outputDataObject == NULL) + { + throwException(ServiceInvocationException, "Null output from REST create operation"); + } + else + { + + // Pure REST, send the response document + XMLHelperPtr xm = HelperProvider::getXMLHelper(dataFactory); + DataObjectList& l = outputDataObject->getList("return"); + if (l.size() != 0) + { + DataObjectPtr resourceDataObject = l[0]; + XMLDocumentPtr doc = xm->createDocument( + resourceDataObject, + resourceDataObject->getType().getURI(), + resourceDataObject->getType().getName()); + char* str = xm->save(doc); + + // Calculate an Etag hash for the response + char* etag = ap_md5(request->pool, (const unsigned char*)str); + + // Handle a conditional GET, if the etag matches the etag + // sent by the client, we don't need to send the whole response + const char* match = apr_table_get(request->headers_in, "If-None-Match"); + if (match != NULL && !strcmp(etag, match)) + { + loginfo("REST resource matches ETag, sending HTTP 304 response code"); + request->status = HTTP_NOT_MODIFIED; + } + else + { + loginfo("Sending response: %s", str); + ap_set_content_type(request, "text/xml"); + apr_table_setn(request->headers_out, "ETag", etag); + + // Send an Etag header to allow caching and + // conditional gets + apr_table_setn(request->headers_out, "ETag", etag); + + ap_rputs(str, request); + } + } + else + { + loginfo("REST resource not found, sending HTTP 404 response code"); + request->status = HTTP_NOT_FOUND; + + return OK; + } + } + } + else + { + // Command style, send the response wrapper element + + if (outputDataObject == NULL) + { + loginfo("Sending empty response"); + //request->status = HTTP_NO_CONTENT; + } + else + { + XMLHelperPtr xm = HelperProvider::getXMLHelper(dataFactory); + DataObjectList& l = outputDataObject->getList("return"); + if (l.size() != 0) + { + DataObjectPtr resultDataObject = l[0]; + XMLDocumentPtr doc = xm->createDocument( + resultDataObject, + resultDataObject->getType().getURI(), + resultDataObject->getType().getName()); + char* str = xm->save(doc); + + loginfo("Sending response: %s", str); + ap_set_content_type(request, "text/xml"); + ap_rputs(str, request); + } + else + { + loginfo("Sending empty response"); + //request->status = HTTP_NO_CONTENT; + } + } + } + + return OK; + } + else if (request->method_number == M_POST) + { + // Handle an HTTP POST + + // Determine the operation to invoke + WSDLOperation wsdlOperation; + string wsdlNamespace = ""; + string op_name = ""; + string uriArgs = ""; + if (iface != NULL) + { + // If we have a REST interface, the operation name is "create" + if (iface->getInterfaceTypeQName() == RESTInterface::typeQName) + { + op_name = "create"; + } + 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 != "") + { + 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 == "") + { + 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"); + } + + // Create the input DataObject + Operation operation(op_name.c_str()); + + // Parse the args part of the URI + if (uriArgs != "") + { + 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 (request->args) + { + string query = request->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; + } + } + + // Read the POST input + ostringstream sinput; + char buffer[2049]; + for ( ; ; ) + { + int size = ap_get_client_block(request, buffer, 2048); + if (size > 0) + { + buffer[size] = '\0'; + sinput << buffer; + } + else if (size == 0) + { + break; + } + else if (size < 0) + { + throwException(ServiceInvocationException, "Error reading POST input"); + } + } + string input = sinput.str(); + + string contentType = content_type; + if (contentType.find("multipart/form-data") == 0) + { + // This is a multipart POST, extract each part from the + // POST body + string begin; + string boundary; + Utils::tokeniseString("boundary=", contentType, begin, boundary); + + for (;;) + { + // Read each part + string part; + string next; + Utils::tokeniseString(boundary, input, part, next); + input = next; + + // Skip first and last empty parts + if (part.length() == 0 || part == "--") + continue; + + // Read headers + bool xml = false; + int empty = -1; + for (;;) + { + string header; + Utils::tokeniseString("\r\n", part, header, next); + part = next; + if (header == "") + { + // Two empty lines signal the beginning of the content + empty++; + if (empty == 1) + break; + } + else + { + empty = 0; + + // Detect XML content + if (header == "Content-Type: text/xml") + xml = true; + } + } + + // Read the part content + if (part.length()) + { + // Strip the trailer + string value; + Utils::tokeniseString("\r\n--", part, value, next); + + if (xml) + { + // Add an XML parameter to the operation + addPart(xmlHelper, value, operation); + } + else + { + // Add a text parameter to the operation + string* stringData = new string; + *stringData = value; + operation.addParameter(stringData); + } + } + + // Read till the end of the POST body + if (input.length() == 0) + break; + } + } + else + { + // The POST body represents a single part + addPart(xmlHelper, input, operation); + } + + DataObjectPtr inputDataObject = createPayload(dataFactory, operation, wsdlOperation); + + // Dispatch to the REST proxy + DataObjectPtr outputDataObject = proxy->invoke(wsdlOperation, inputDataObject); + + // Send the response back to the client + if (iface!=NULL && + iface->getInterfaceTypeQName() == RESTInterface::typeQName) + { + // Pure REST, send the location of the created resource + + if (outputDataObject == NULL) + { + throwException(ServiceInvocationException, "Null output from REST create operation"); + } + + string location = ""; + + DataObjectList& l = outputDataObject->getList("return"); + if (l.size()) + { + location = l.getCString(0); + } + + if (location == "") + { + loginfo("No resource location, sending HTTP 400 response code"); + request->status = HTTP_BAD_REQUEST; + + return OK; + } + + string locuri = request->uri; + locuri += '/'; + locuri += location; + + const char* loc = ap_construct_url(request->pool, locuri.c_str(), request); + loginfo("Sending resource location: %s", loc); + apr_table_setn(request->headers_out, "Location", loc); + apr_table_setn(request->headers_out, "Content-Location", loc); + request->status = HTTP_CREATED; + + // Send the created resource entity back to the client + ap_set_content_type(request, "text/xml"); + ap_rputs(input.c_str(), request); + + } + else + { + // Command style, send the response element + + if (outputDataObject == NULL) + { + loginfo("Sending empty response"); + //request->status = HTTP_NO_CONTENT; + } + else + { + XMLHelperPtr xm = HelperProvider::getXMLHelper(dataFactory); + DataObjectList& l = outputDataObject->getList("return"); + if (l.size() != 0) + { + DataObjectPtr resultDataObject = l[0]; + XMLDocumentPtr doc = xm->createDocument( + resultDataObject, + resultDataObject->getType().getURI(), + resultDataObject->getType().getName()); + char* str = xm->save(doc); + + loginfo("Sending response: %s", str); + ap_set_content_type(request, "text/xml"); + ap_rputs(str, request); + } + else + { + loginfo("Sending empty response"); + //request->status = HTTP_NO_CONTENT; + } + } + } + + return OK; + } + else if (request->method_number == M_PUT) + { + + // Handle an HTTP PUT + + // Determine the operation to invoke + WSDLOperation wsdlOperation; + string wsdlNamespace = ""; + string op_name = "update"; + string uriArgs = uri; + + // Create a default document literal wrapped WSDL operation + 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"); + + // Create the input DataObject + Operation operation(op_name.c_str()); + + // Parse the args part of the URI + if (uriArgs != "") + { + 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 (request->args) + { + string query = request->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; + } + } + + // Read the PUT input + ostringstream sinput; + char buffer[2049]; + for ( ; ; ) + { + int size = ap_get_client_block(request, buffer, 2048); + if (size > 0) + { + buffer[size] = '\0'; + sinput << buffer; + } + else if (size == 0) + { + break; + } + else if (size < 0) + { + throwException(ServiceInvocationException, "Error reading PUT input"); + } + } + string input = sinput.str(); + addPart(xmlHelper, input, operation); + + DataObjectPtr inputDataObject = createPayload(dataFactory, operation, wsdlOperation); + + // Dispatch to the REST proxy + DataObjectPtr outputDataObject = proxy->invoke(wsdlOperation, inputDataObject); + + // Empty response + //request->status = HTTP_NO_CONTENT; + return OK; + } + else if (request->method_number == M_DELETE) + { + + // Determine the operation to invoke + WSDLOperation wsdlOperation; + string wsdlNamespace = ""; + string op_name = "delete"; + string uriArgs = uri; + + // Create a default document literal wrapped WSDL operation + 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"); + + // Create the input DataObject + Operation operation(op_name.c_str()); + + // Parse the args part of the URI + if (uriArgs != "") + { + 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 (request->args) + { + string query = request->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); + + // Empty response + //request->status = HTTP_NO_CONTENT; + return OK; + } + else + { + if (request->method) + { + logerror("Unsupported HTTP method: %s", request->method); + } + else + { + logerror("Unsupported HTTP method: %d", request->method_number); + } + return HTTP_NOT_IMPLEMENTED; + } + } + 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("http://tempuri.org", "Wrapper"); + } + } + + // 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; igetList(pname.str()); + + const Operation::Parameter& parm = operation.getParameter(i); + switch(parm.getType()) + { + case Operation::STRING: + { + l.append((*(string*)parm.getValue()).c_str()); + break; + } + case Operation::DATAOBJECT: + { + l.append(*(DataObjectPtr*)parm.getValue()); + break; + } + default: + { + break; + } + } + } + } + } + else { + + // Each parameter in the operation should be a property on the request dataobject + for (unsigned int i=0; isetCString(i, (*(string*)parm.getValue()).c_str()); + break; + } + case Operation::DATAOBJECT: + { + inputDataObject->setDataObject(i, *(DataObjectPtr*)parm.getValue()); + break; + } + default: + { + break; + } + } + } + } + + return inputDataObject; + } + + void addPart(XMLHelper* xmlHelper, string& payload, Operation& operation) + { + logentry(); + + + //TODO Remove this workaround once SDO supports loading of open top level content + // The workaround is to wrap the open content in a wrapper element + string xmldecl; + string xml; + Utils::rTokeniseString("?>", payload, xmldecl, xml); + string body = "\n"; + body += "\n"; + body += xml; + body += "\n"; + + // Convert the body to an SDO DataObject + DataObjectPtr inputWrapperDataObject = NULL; + XMLDocumentPtr theXMLDocument = xmlHelper->load(body.c_str(), NULL); + if (theXMLDocument != 0) + { + inputWrapperDataObject = theXMLDocument->getRootDataObject(); + } + if(!inputWrapperDataObject) + { + ostringstream msg; + msg << "Could not convert received document to SDO: " << body; + throwException(ServiceDataException, msg.str().c_str()); + } + + // Get the body part + DataObjectPtr inputDataObject = NULL; + PropertyList bpl = inputWrapperDataObject->getInstanceProperties(); + if (bpl.size()!=0) + { + if (bpl[0].isMany()) + { + DataObjectList& parts = inputWrapperDataObject->getList((unsigned int)0); + inputDataObject = parts[0]; + } + else + { + inputDataObject = inputWrapperDataObject->getDataObject(bpl[0]); + } + } + if (inputDataObject == NULL) + { + ostringstream msg; + msg << "Could not convert received document to SDO: " << body; + throwException(ServiceDataException, msg.str().c_str()); + } + + DataObjectPtr* dataObjectData = new DataObjectPtr; + *dataObjectData = inputDataObject; + (*dataObjectData)->detach(); + operation.addParameter(dataObjectData); + } + + 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_base_uri(cmd_parms *cmd, void *c, + const char *arg) + { + rest_dir_config_rec_t *conf = (rest_dir_config_rec_t*)c; + conf->base_uri = 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*(*)())tuscany::sca::rest::rest_set_home, NULL, RSRC_CONF, + "Tuscany home directory"), + AP_INIT_TAKE1("TuscanyPath", (const char*(*)())tuscany::sca::rest::rest_set_path, NULL, ACCESS_CONF, + "Tuscany SCA composite search path"), + AP_INIT_TAKE1("TuscanyRoot", (const char*(*)())tuscany::sca::rest::rest_set_root, NULL, ACCESS_CONF, + "Tuscany root SCA configuration path"), + AP_INIT_TAKE1("TuscanyBaseURI", (const char*(*)())tuscany::sca::rest::rest_set_base_uri, NULL, ACCESS_CONF, + "Tuscany SCA system base URI"), + AP_INIT_TAKE1("TuscanyComponent", (const char*(*)())tuscany::sca::rest::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->base_uri = ""; + 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 + +extern "C" +{ + + module AP_MODULE_DECLARE_DATA sca_rest_module = + { + STANDARD20_MODULE_STUFF, + tuscany::sca::rest::rest_create_dir_config, /* dir config */ + NULL, /* dir merger --- default is to override */ + tuscany::sca::rest::rest_create_server_config, /* server config */ + NULL, /* merge server config */ + tuscany::sca::rest::rest_module_cmds, /* command table */ + tuscany::sca::rest::register_hooks /* register_hooks */ + }; + +} diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTReferenceBindingExtension.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTReferenceBindingExtension.cpp new file mode 100644 index 0000000000..18720f42f5 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTReferenceBindingExtension.cpp @@ -0,0 +1,86 @@ +/* +* 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. +*/ + +#include "RESTReferenceBindingExtension.h" +#include "model/RESTReferenceBinding.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/core/SCARuntime.h" + +using namespace std; +using namespace commonj::sdo; +using namespace tuscany::sca::model; + +extern "C" +{ +#if defined(WIN32) || defined(_WINDOWS) + __declspec(dllexport) +#endif + void tuscany_sca_rest_service_initialize() + { + tuscany::sca::rest::RESTReferenceBindingExtension::initialize(); + } +} + +namespace tuscany +{ + namespace sca + { + namespace rest + { + // =================================================================== + // Constructor for the RESTReferenceBinding class. + // =================================================================== + RESTReferenceBindingExtension::RESTReferenceBindingExtension() + { + logentry(); + } + + // =================================================================== + // Destructor for the RESTReferenceBindingExtension class. + // =================================================================== + RESTReferenceBindingExtension::~RESTReferenceBindingExtension() + { + logentry(); + } + + const string RESTReferenceBindingExtension::extensionName("rest"); + const string RESTReferenceBindingExtension::typeQName("http://www.osoa.org/xmlns/sca/1.0#RESTBinding"); + + // =================================================================== + // loadModelElement - load the info from binding.rest + // =================================================================== + ReferenceBinding* RESTReferenceBindingExtension::getReferenceBinding(Composite *composite, Reference* reference, DataObjectPtr scdlBinding) + { + string uri = scdlBinding->getCString("uri"); + + RESTReferenceBinding* referenceBinding = new RESTReferenceBinding(reference, uri); + + return referenceBinding; + } + + void RESTReferenceBindingExtension::initialize() + { + logentry(); + SCARuntime::getCurrentRuntime()->registerReferenceBindingExtension(new RESTReferenceBindingExtension()); + } + + } // End namespace rest + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTReferenceBindingExtension.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTReferenceBindingExtension.h new file mode 100644 index 0000000000..0d9e41841b --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTReferenceBindingExtension.h @@ -0,0 +1,75 @@ +/* + * 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. + */ + +#ifndef tuscany_sca_extension_rest_restreferencebindingextension_h +#define tuscany_sca_extension_rest_restreferencebindingextension_h + +#include "tuscany/sca/extension/ReferenceBindingExtension.h" + +namespace tuscany +{ + namespace sca + { + namespace rest + { + + class RESTReferenceBindingExtension : public ReferenceBindingExtension + { + public: + /** + * Default constructor + */ + RESTReferenceBindingExtension(); + + /** + * Destructor + */ + virtual ~RESTReferenceBindingExtension(); + + /** + * return the name of the extension + */ + virtual const std::string& getExtensionName() {return extensionName;} + + /** + * return the QName of schema elemant for this implementation extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#binding.rest") + */ + virtual const std::string& getExtensionTypeQName() {return typeQName;} + + virtual tuscany::sca::model::ReferenceBinding* getReferenceBinding( + tuscany::sca::model::Composite* composite, + tuscany::sca::model::Reference *reference, + commonj::sdo::DataObjectPtr scdlBinding); + + static void initialize(); + + private: + static const std::string extensionName; + static const std::string typeQName; + + }; + + + } // End namespace rest + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_extension_rest_restreferencebindingextension_h + diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.cpp new file mode 100644 index 0000000000..5806c83773 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.cpp @@ -0,0 +1,559 @@ +/* + * 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$ */ + +#include + +#include "commonj/sdo/SDO.h" + +#include "RESTServiceProxy.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/Exceptions.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/ComponentType.h" +#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" + +using namespace std; +using namespace commonj::sdo; +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace rest + { + + // ============================ + // Constructor: Create a proxy + // ============================ + RESTServiceProxy::RESTServiceProxy(Reference* reference) + : ServiceProxy(reference) + { + logentry(); + + // Get the target service wrapper + RESTReferenceBinding* referenceBinding = (RESTReferenceBinding*)reference->getBinding(); + serviceWrapper = referenceBinding->getTargetServiceBinding()->getServiceWrapper(); + + DataFactoryPtr dataFactory = reference->getComponent()->getComposite()->getDataFactory(); + try { + const Type& tempType = dataFactory->getType("http://tempuri.org", "RootType"); + } catch (SDORuntimeException&) + { + dataFactory->addType("http://tempuri.org", "RootType", false, false, false); + dataFactory->addType("http://tempuri.org", "Wrapper", false, true, false); + dataFactory->addPropertyToType( + "http://tempuri.org", "RootType", + "Wrapper", + "http://tempuri.org", "Wrapper", + false, false, true); + dataFactory->addType("http://tempuri.org", "Part", false, true, false); + dataFactory->addPropertyToType( + "http://tempuri.org", "RootType", + "Part", + "http://tempuri.org", "Part", + false, false, true); + } + } + + // ========== + // Destructor + // ========== + RESTServiceProxy::~RESTServiceProxy() + { + logentry(); + } + + /// + /// This method will be called to process an operation invocation. + /// + DataObjectPtr RESTServiceProxy::invoke(const WSDLOperation& wsdlOperation, DataObjectPtr inputDataObject) + { + logentry(); + + Reference* reference = getReference(); + Component* component = reference->getComponent(); + Composite* composite = component ->getComposite(); + + RESTReferenceBinding* referenceBinding = (RESTReferenceBinding*)reference->getBinding(); + DataFactoryPtr dataFactoryPtr = reference->getComponent()->getComposite()->getDataFactory(); + + const char* outputTypeURI = wsdlOperation.getOutputTypeUri().c_str(); + const char* outputTypeName = wsdlOperation.getOutputTypeName().c_str(); + + 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; igetBoolean(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*; + *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 = new DataObjectPtr; + if (pl[i].isMany()) + { + DataObjectList& l = inputDataObject->getList((unsigned int)i); + *dataObjectData = l[0]; + } + else + { + *dataObjectData = inputDataObject->getDataObject(pl[i]); + } + if(!*dataObjectData) + { + loginfo("Null DataObject parameter named %s", name); + } + else + { + (*dataObjectData)->detach(); + } + 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; jgetSequence(); + 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* dataObjectData =new DataObjectPtr; + *dataObjectData = sequence->getDataObjectValue(0); + if(!*dataObjectData) + { + loginfo("Null DataObject parameter named %s", name); + } + else + { + (*dataObjectData)->detach(); + } + operation.addParameter(dataObjectData); + } + } + 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("http://tempuri.org", "Wrapper"); + } + } + + 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) + { + logentry(); + + // Go through data object to set the return value + PropertyList pl = outputDataObject->getType().getProperties(); + + if(pl.size() == 0) + { + if(outputDataObject->getType().isOpenType() && outputDataObject->getType().isDataObjectType()) + { + /* + * This code deals with returning xsd:any elements + */ + DataObjectList& l = outputDataObject->getList("return"); + Operation::ParameterType resultType = operation.getReturnType(); + switch(resultType) + { + case Operation::BOOL: + { + l.append(*(bool*)operation.getReturnValue()); + break; + } + case Operation::SHORT: + { + l.append(*(short*)operation.getReturnValue()); + break; + } + case Operation::INT: + { + l.append(*(long*)operation.getReturnValue()); + break; + } + case Operation::LONG: + { + l.append(*(long*)operation.getReturnValue()); + break; + } + case Operation::USHORT: + { + l.append(*(short*)operation.getReturnValue()); + break; + } + case Operation::UINT: + { + l.append(*(long*)operation.getReturnValue()); + break; + } + case Operation::ULONG: + { + l.append(*(long*)operation.getReturnValue()); + break; + } + case Operation::FLOAT: + { + l.append(*(float*)operation.getReturnValue()); + break; + } + case Operation::DOUBLE: + { + l.append(*(long double*)operation.getReturnValue()); + break; + } + case Operation::LONGDOUBLE: + { + l.append(*(long double*)operation.getReturnValue()); + break; + } + case Operation::CHARS: + { + l.append(*(char**)operation.getReturnValue()); + break; + } + case Operation::STRING: + { + l.append((*(string*)operation.getReturnValue()).c_str()); + break; + } + case Operation::DATAOBJECT: + { + l.append(*(DataObjectPtr*)operation.getReturnValue()); + break; + } + default: + { + break; + } + } + } + else + { + loginfo("No return values defined"); + } + } + else { + + // Should only be one return value.. This goes through all return values + for(int i=0; isetBoolean(pl[i], *(bool*)operation.getReturnValue()); + break; + } + case Operation::SHORT: + { + outputDataObject->setShort(pl[i], *(short*)operation.getReturnValue()); + break; + } + case Operation::INT: + { + outputDataObject->setInteger(pl[i], *(int*)operation.getReturnValue()); + break; + } + case Operation::LONG: + { + outputDataObject->setInteger(pl[i], *(long*)operation.getReturnValue()); + break; + } + case Operation::USHORT: + { + outputDataObject->setInteger(pl[i], *(unsigned short*)operation.getReturnValue()); + break; + } + case Operation::UINT: + { + outputDataObject->setInteger(pl[i], *(unsigned int*)operation.getReturnValue()); + break; + } + case Operation::ULONG: + { + outputDataObject->setInteger(pl[i], *(unsigned long*)operation.getReturnValue()); + break; + } + case Operation::FLOAT: + { + outputDataObject->setFloat(pl[i], *(float*)operation.getReturnValue()); + break; + } + case Operation::DOUBLE: + { + outputDataObject->setDouble(pl[i], *(double*)operation.getReturnValue()); + break; + } + case Operation::LONGDOUBLE: + { + outputDataObject->setDouble(pl[i], *(long double*)operation.getReturnValue()); + break; + } + case Operation::CHARS: + { + if(*(char**)operation.getReturnValue() != NULL) + { + outputDataObject->setCString(pl[i], *(char**)operation.getReturnValue()); + } + else + { + loginfo("Null return value, leaving property %s unset", pl[i].getName()); + } + break; + } + case Operation::STRING: + { + outputDataObject->setCString(pl[i], (*(string*)operation.getReturnValue()).c_str()); + break; + } + case Operation::DATAOBJECT: + { + + if(*(DataObjectPtr*)operation.getReturnValue() != NULL) + { + outputDataObject->setDataObject(pl[i], *(DataObjectPtr*)operation.getReturnValue()); + } + else + { + loginfo("Null return value, leaving property %s unset", pl[i].getName()); + } + + break; + } + default: + { + break; + } + } + } + } + } + + } // End namespace rest + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.h new file mode 100644 index 0000000000..387add3f35 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/RESTServiceProxy.h @@ -0,0 +1,95 @@ +/* + * + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_extension_rest_restserviceproxy_h +#define tuscany_sca_extension_rest_restserviceproxy_h + +#include "commonj/sdo/SDO.h" + +#include "export.h" +#include "tuscany/sca/core/ServiceProxy.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#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" + + +namespace tuscany +{ + namespace sca + { + namespace rest + { + + /** + * Holds a proxy for a given component and reference. + * The proxy which is held inside a ServiceProxy will be specific to the programming + * interface expected by the client. In this particular case the client is an Axis2 + * Web service skeleton. + */ + class RESTServiceProxy : public ServiceProxy + { + public: + /** + * Create a new service proxy for a reference. The proxy will contain a pointer to + * the target ServiceWrapper. + * @param reference The reference on the source component. + * @param target The wrapper of the service which is wired to this reference. + */ + RESTServiceProxy(tuscany::sca::model::Reference* reference); + + /** + * Create a new service proxy for a service. The proxy will contain a pointer to + * the target ServiceWrapper. + * @param reference The service on the target component. + * @param target The wrapper of the target service. + */ + RESTServiceProxy(tuscany::sca::model::Service* service); + + /** + * Destructor. + */ + virtual ~RESTServiceProxy(); + + /** + * Invoke the specified operation + */ + SCA_REST_SERVICE_API commonj::sdo::DataObjectPtr invoke( + const tuscany::sca::model::WSDLOperation& wsdlOperation, + commonj::sdo::DataObjectPtr inputDataObject); + + private: + + void setOutputData(Operation& operation, + commonj::sdo::DataObjectPtr outputDataObject, commonj::sdo::DataFactoryPtr dataFactoryPtr); + + /** + * The target service wrapper + */ + ServiceWrapper* serviceWrapper; + + }; + + } // End namespace rest + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_extension_rest_restserviceproxy_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/export.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/export.h new file mode 100644 index 0000000000..802218a2fe --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/export.h @@ -0,0 +1,38 @@ +/* + * 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$ */ + +#ifndef tuscany_sca_rest_service_export_h +#define tuscany_sca_rest_service_export_h + +#if defined(WIN32) || defined (_WINDOWS) +#pragma warning(disable: 4786) + +#ifdef TUSCANY_SCA_REST_SERVICE_EXPORTS +#define SCA_REST_SERVICE_API __declspec(dllexport) +#else +#define SCA_REST_SERVICE_API __declspec(dllimport) +#endif + +#else +#define SCA_REST_SERVICE_API +#endif + +#endif // tuscany_sca_rest_service_export_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/model/RESTReferenceBinding.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/model/RESTReferenceBinding.cpp new file mode 100644 index 0000000000..1b4b2d3403 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/model/RESTReferenceBinding.cpp @@ -0,0 +1,66 @@ +/* + * + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/rest/model/RESTReferenceBinding.h" +#include "tuscany/sca/core/ServiceProxy.h" +#include "tuscany/sca/rest/RESTServiceProxy.h" + +using namespace std; +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace rest + { + + // Constructor + RESTReferenceBinding::RESTReferenceBinding(Reference* reference, const string& uri) + : ReferenceBinding(reference, uri) + { + logentry(); + } + + // Destructor + RESTReferenceBinding::~RESTReferenceBinding() + { + logentry(); + } + + void RESTReferenceBinding::configure(ServiceBinding *binding) + { + logentry(); + + targetServiceBinding = binding; + + serviceProxy = new RESTServiceProxy(getReference()); + } + + ServiceProxy* RESTReferenceBinding::getServiceProxy() + { + logentry(); + + return serviceProxy; + } + + } // End namespace rest + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/model/RESTReferenceBinding.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/model/RESTReferenceBinding.h new file mode 100644 index 0000000000..d19f3926a1 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/model/RESTReferenceBinding.h @@ -0,0 +1,90 @@ +/* + * + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_extension_rest_model_restreferencebinding_h +#define tuscany_sca_extension_rest_model_restreferencebinding_h + +#include + +#include "tuscany/sca/model/ReferenceBinding.h" + +namespace tuscany +{ + namespace sca + { + namespace rest + { + /** + * Information about a web service binding for service or a reference. + */ + class RESTReferenceBinding : public tuscany::sca::model::ReferenceBinding + { + public: + + /** + * Constructor. + * @param uri The uri of the binding. + */ + RESTReferenceBinding(tuscany::sca::model::Reference* reference, const std::string& uri); + + /** + * Destructor. + */ + virtual ~RESTReferenceBinding(); + + /** + * Returns the type of binding. + */ + virtual std::string getType() { return "http://www.osoa.org/xmlns/sca/1.0#RESTBinding"; }; + + /** + * Configure this binding from a service binding. + */ + virtual void configure(tuscany::sca::model::ServiceBinding* serviceBinding); + + /** + * Create a proxy representing the reference to the + * client component. + */ + virtual ServiceProxy* getServiceProxy(); + + /** + * Returns the target service binding. + */ + tuscany::sca::model::ServiceBinding* getTargetServiceBinding() const { return targetServiceBinding; }; + + private: + + /** + * The proxy representing the reference to the client + * component. + */ + ServiceProxy* serviceProxy; + + /** + * The service binding of the target + */ + tuscany::sca::model::ServiceBinding* targetServiceBinding; + }; + + } // End namespace rest + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_extension_rest_model_restreferencebinding_h -- cgit v1.2.3