diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-02-20 22:03:50 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-02-20 22:03:50 +0000 |
commit | c657f276d8045caf41450ee882854df2f1ad1504 (patch) | |
tree | c9630ad14530063e4dfe6d34b5d05ef267513018 /sca-cpp | |
parent | 844d7bf0cfde2bccca36c583d4221d7b461772cf (diff) |
Add two builtin component properties containing the current HTTP request path and query parameters.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1072763 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp')
-rw-r--r-- | sca-cpp/trunk/modules/server/domain-test.composite | 10 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/htdocs/test/json-properties.txt | 1 | ||||
-rwxr-xr-x | sca-cpp/trunk/modules/server/httpd-test | 7 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/mod-eval.hpp | 28 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/property-test.scm | 21 |
5 files changed, 66 insertions, 1 deletions
diff --git a/sca-cpp/trunk/modules/server/domain-test.composite b/sca-cpp/trunk/modules/server/domain-test.composite index 048c451ef6..56bfb700f0 100644 --- a/sca-cpp/trunk/modules/server/domain-test.composite +++ b/sca-cpp/trunk/modules/server/domain-test.composite @@ -29,6 +29,16 @@ </service> </component> + <component name="property-test"> + <t:implementation.scheme script="property-test.scm"/> + <service name="properties"> + <t:binding.http uri="properties"/> + </service> + <property name="host"></property> + <property name="path"></property> + <property name="query"></property> + </component> + <component name="cpp-test"> <implementation.cpp path="." library="libimpl-test"/> <service name="cpp"> diff --git a/sca-cpp/trunk/modules/server/htdocs/test/json-properties.txt b/sca-cpp/trunk/modules/server/htdocs/test/json-properties.txt new file mode 100644 index 0000000000..70f0139ea0 --- /dev/null +++ b/sca-cpp/trunk/modules/server/htdocs/test/json-properties.txt @@ -0,0 +1 @@ +{"id":"1","result":{"host":"localhost","path":["components","property-test"],"query":{"id":"1","method":"print"}}}
\ No newline at end of file diff --git a/sca-cpp/trunk/modules/server/httpd-test b/sca-cpp/trunk/modules/server/httpd-test index 050becdb24..e39412fe11 100755 --- a/sca-cpp/trunk/modules/server/httpd-test +++ b/sca-cpp/trunk/modules/server/httpd-test @@ -69,6 +69,13 @@ if [ "$rc" = "0" ]; then rc=$? fi +# Test built-in properties +if [ "$rc" = "0" ]; then + $curl_prefix/bin/curl 'http://localhost:8090/properties?id=1&method=print' >tmp/json-properties.txt 2>/dev/null + diff tmp/json-properties.txt htdocs/test/json-properties.txt + rc=$? +fi + # Cleanup ../http/httpd-stop tmp sleep 2 diff --git a/sca-cpp/trunk/modules/server/mod-eval.hpp b/sca-cpp/trunk/modules/server/mod-eval.hpp index 4ee40e51ee..64ab6df4bb 100644 --- a/sca-cpp/trunk/modules/server/mod-eval.hpp +++ b/sca-cpp/trunk/modules/server/mod-eval.hpp @@ -368,7 +368,29 @@ struct hostPropProxy { hostPropProxy(const value& v) : v(v) { } const value operator()(unused const list<value>& params) const { - return httpd::hostName(currentRequest, v); + const value r = httpd::hostName(currentRequest, v); + debug(r, "modeval::hostPropProxy::value"); + return r; + } +}; + +struct pathPropProxy { + pathPropProxy(unused const value& v) { + } + const value operator()(unused const list<value>& params) const { + const value v = pathValues(currentRequest->uri); + debug(v, "modeval::pathPropProxy::value"); + return v; + } +}; + +struct queryPropProxy { + queryPropProxy(unused const value& v) { + } + const value operator()(unused const list<value>& params) const { + const value v = httpd::queryArgs(currentRequest); + debug(v, "modeval::queryPropProxy::value"); + return v; } }; @@ -399,6 +421,10 @@ struct userPropProxy { const value mkpropProxy(const value& prop) { if (scdl::name(prop) == "host") return lambda<value(const list<value>&)>(hostPropProxy(elementValue(prop))); + if (scdl::name(prop) == "path") + return lambda<value(const list<value>&)>(pathPropProxy(elementValue(prop))); + if (scdl::name(prop) == "query") + return lambda<value(const list<value>&)>(queryPropProxy(elementValue(prop))); if (scdl::name(prop) == "user") return lambda<value(const list<value>&)>(userPropProxy(elementValue(prop))); if (scdl::name(prop) == "realm") diff --git a/sca-cpp/trunk/modules/server/property-test.scm b/sca-cpp/trunk/modules/server/property-test.scm new file mode 100644 index 0000000000..f5ba76f1f3 --- /dev/null +++ b/sca-cpp/trunk/modules/server/property-test.scm @@ -0,0 +1,21 @@ +; 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. + +; Built-in property test case + +(define (print host path query) (list (list 'host (host)) (list 'path (path)) (list 'query (query)))) + |