Author: jsdelfino
Date: Sun Feb 20 22:03:50 2011
New Revision: 1072763

URL: http://svn.apache.org/viewvc?rev=1072763&view=rev
Log:
Add two builtin component properties containing the current HTTP request path 
and query parameters.

Added:
    tuscany/sca-cpp/trunk/modules/server/htdocs/test/json-properties.txt
    tuscany/sca-cpp/trunk/modules/server/property-test.scm
Modified:
    tuscany/sca-cpp/trunk/modules/server/domain-test.composite
    tuscany/sca-cpp/trunk/modules/server/httpd-test
    tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp

Modified: tuscany/sca-cpp/trunk/modules/server/domain-test.composite
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/domain-test.composite?rev=1072763&r1=1072762&r2=1072763&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/domain-test.composite (original)
+++ tuscany/sca-cpp/trunk/modules/server/domain-test.composite Sun Feb 20 
22:03:50 2011
@@ -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">

Added: tuscany/sca-cpp/trunk/modules/server/htdocs/test/json-properties.txt
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/htdocs/test/json-properties.txt?rev=1072763&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/htdocs/test/json-properties.txt (added)
+++ tuscany/sca-cpp/trunk/modules/server/htdocs/test/json-properties.txt Sun 
Feb 20 22:03:50 2011
@@ -0,0 +1 @@
+{"id":"1","result":{"host":"localhost","path":["components","property-test"],"query":{"id":"1","method":"print"}}}
\ No newline at end of file

Modified: tuscany/sca-cpp/trunk/modules/server/httpd-test
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/httpd-test?rev=1072763&r1=1072762&r2=1072763&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/httpd-test (original)
+++ tuscany/sca-cpp/trunk/modules/server/httpd-test Sun Feb 20 22:03:50 2011
@@ -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

Modified: tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp?rev=1072763&r1=1072762&r2=1072763&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp Sun Feb 20 22:03:50 2011
@@ -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")

Added: tuscany/sca-cpp/trunk/modules/server/property-test.scm
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/property-test.scm?rev=1072763&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/property-test.scm (added)
+++ tuscany/sca-cpp/trunk/modules/server/property-test.scm Sun Feb 20 22:03:50 
2011
@@ -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))))
+


Reply via email to