summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/server
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk/modules/server')
-rw-r--r--sca-cpp/trunk/modules/server/client-test.hpp16
-rw-r--r--sca-cpp/trunk/modules/server/client-test.scm4
-rwxr-xr-xsca-cpp/trunk/modules/server/httpd-test4
-rw-r--r--sca-cpp/trunk/modules/server/impl-test.cpp6
-rw-r--r--sca-cpp/trunk/modules/server/mod-eval.hpp62
-rw-r--r--sca-cpp/trunk/modules/server/server-test.scm6
-rwxr-xr-xsca-cpp/trunk/modules/server/wiring-test4
7 files changed, 85 insertions, 17 deletions
diff --git a/sca-cpp/trunk/modules/server/client-test.hpp b/sca-cpp/trunk/modules/server/client-test.hpp
index dc9ca299ad..29da9e4798 100644
--- a/sca-cpp/trunk/modules/server/client-test.hpp
+++ b/sca-cpp/trunk/modules/server/client-test.hpp
@@ -294,6 +294,21 @@ const bool testPut() {
return true;
}
+const bool testPatch() {
+ const gc_scoped_pool pool;
+ const list<value> i = nilListValue + "content" + (nilListValue + "item"
+ + (nilListValue + "name" + string("Apple"))
+ + (nilListValue + "price" + string("$2.99")));
+ const list<value> a = nilListValue + (nilListValue + "entry"
+ + (nilListValue + "title" + string("item"))
+ + (nilListValue + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ + i);
+ const http::CURLSession ch("", "", "", "", 0);
+ const value rc = content(http::patch(a, testURI + "/111", ch));
+ assert(rc == trueValue);
+ return true;
+}
+
const bool testDel() {
const gc_scoped_pool pool;
const http::CURLSession ch("", "", "", "", 0);
@@ -306,6 +321,7 @@ const bool testServer() {
tuscany::server::testGet();
tuscany::server::testPost();
tuscany::server::testPut();
+ tuscany::server::testPatch();
tuscany::server::testDel();
tuscany::server::testEval();
tuscany::server::testGetPerf();
diff --git a/sca-cpp/trunk/modules/server/client-test.scm b/sca-cpp/trunk/modules/server/client-test.scm
index 47b799d390..a4db7f1b26 100644
--- a/sca-cpp/trunk/modules/server/client-test.scm
+++ b/sca-cpp/trunk/modules/server/client-test.scm
@@ -33,6 +33,10 @@
(ref "put" id entry)
)
+(define (patch id entry ref)
+ (ref "patch" id entry)
+)
+
(define (delete id ref)
(ref "delete" id)
)
diff --git a/sca-cpp/trunk/modules/server/httpd-test b/sca-cpp/trunk/modules/server/httpd-test
index 195caa4562..ef30682171 100755
--- a/sca-cpp/trunk/modules/server/httpd-test
+++ b/sca-cpp/trunk/modules/server/httpd-test
@@ -60,6 +60,10 @@ if [ "$rc" = "0" ]; then
rc=$?
fi
if [ "$rc" = "0" ]; then
+ $curl_prefix/bin/curl http://localhost:8090/scheme/111 -X PATCH -H "Content-type: application/atom+xml" --data @htdocs/test/entry.xml 2>/dev/null
+ rc=$?
+fi
+if [ "$rc" = "0" ]; then
$curl_prefix/bin/curl http://localhost:8090/scheme/111 -X DELETE 2>/dev/null
rc=$?
fi
diff --git a/sca-cpp/trunk/modules/server/impl-test.cpp b/sca-cpp/trunk/modules/server/impl-test.cpp
index a9bd9ad585..0ad1302217 100644
--- a/sca-cpp/trunk/modules/server/impl-test.cpp
+++ b/sca-cpp/trunk/modules/server/impl-test.cpp
@@ -45,6 +45,10 @@ const failable<value> put(unused const list<value>& params) {
return trueValue;
}
+const failable<value> patch(unused const list<value>& params) {
+ return trueValue;
+}
+
const failable<value> del(unused const list<value>& params) {
return trueValue;
}
@@ -66,6 +70,8 @@ const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
return tuscany::server::post(cdr(params));
if (func == "put")
return tuscany::server::put(cdr(params));
+ if (func == "patch")
+ return tuscany::server::patch(cdr(params));
if (func == "delete")
return tuscany::server::del(cdr(params));
if (func == "echo")
diff --git a/sca-cpp/trunk/modules/server/mod-eval.hpp b/sca-cpp/trunk/modules/server/mod-eval.hpp
index aa13584534..5a8a15bf43 100644
--- a/sca-cpp/trunk/modules/server/mod-eval.hpp
+++ b/sca-cpp/trunk/modules/server/mod-eval.hpp
@@ -206,7 +206,7 @@ public:
debug(impls, "modeval::implProxy::callImpl::impls");
// Lookup the component implementation
- const list<value> impl(assoctree<value>(cname, (list<value>)impls));
+ const list<value> impl(rbtreeAssoc<value>(cname, (list<value>)impls));
if (isNil(impl))
return mkfailure<value>(string("Couldn't find component implementation: ") + (string)cname);
@@ -573,7 +573,7 @@ const failable<list<value> > applyLifecycleExpr(const list<value>& impls, const
* arranged in trees of reference-name + reference-target pairs.
*/
const list<value> componentReferenceToTargetTree(const value& c) {
- return mklist<value>(scdl::name(c), mkbtree(sort(scdl::referenceToTargetAssoc(scdl::references(c)))));
+ return mklist<value>(scdl::name(c), mkbrbtree(sort(scdl::referenceToTargetAssoc(scdl::references(c)))));
}
const list<value> componentReferenceToTargetAssoc(const list<value>& c) {
@@ -634,13 +634,13 @@ const failable<Composite> confComponents(const string& contribPath, const string
const list<value> comps = content(fcomps);
debug(comps, "modeval::confComponents::comps");
- const list<value> refs = mkbtree(sort(componentReferenceToTargetAssoc(comps)));
+ const list<value> refs = mkbrbtree(sort(componentReferenceToTargetAssoc(comps)));
debug(flatten(refs), "modeval::confComponents::refs");
- const list<value> svcs = mkbtree(sort(uriToComponentAssoc(comps)));
+ const list<value> svcs = mkbrbtree(sort(uriToComponentAssoc(comps)));
debug(flatten(svcs), "modeval::confComponents::svcs");
- const list<value> cimpls = mkbtree(sort(componentToImplementationAssoc(comps,
+ const list<value> cimpls = mkbrbtree(sort(componentToImplementationAssoc(comps,
isNil(contributor)? length(vhost) != 0? contribPath + vhost + "/" : contribPath : contribPath,
impls, lifecycle, sslc, timeout)));
debug(flatten(cimpls), "modeval::confComponents::impls");
@@ -659,7 +659,7 @@ const failable<list<value> > startComponents(const list<value>& impls) {
const list<value> simpls = content(fsimpls);
debug(impls, "modeval::startComponents::simpls");
- return mkbtree(sort(simpls));
+ return mkbrbtree(sort(simpls));
}
/**
@@ -696,7 +696,7 @@ const failable<int> get(const list<value>& rpath, request_rec* const r, const lv
debug(r->uri, "modeval::get::uri");
// Inspect the query string
- const list<list<value> > args = httpd::unescapeArgs(httpd::queryArgs(r));
+ const list<value> args = httpd::unescapeArgs(httpd::queryArgs(r));
const list<value> ia = assoc(value("id"), args);
const list<value> ma = assoc(value("method"), args);
@@ -795,7 +795,7 @@ const failable<int> post(const list<value>& rpath, request_rec* const r, const l
const list<string> ls = httpd::read(r);
debug(ls, "modeval::post::input");
const value jsreq = content(json::readValue(ls));
- const list<list<value> > args = httpd::postArgs(jsreq);
+ const list<value> args = httpd::postArgs(jsreq);
// Extract the request id, method and params
const value id = cadr(assoc(value("id"), args));
@@ -878,6 +878,34 @@ const failable<int> put(const list<value>& rpath, request_rec* const r, const lv
}
/**
+ * Handle an HTTP PATCH.
+ */
+const failable<int> patch(const list<value>& rpath, request_rec* const r, const lvvlambda& impl) {
+ debug(r->uri, "modeval::put::patch");
+
+ // Read the ATOM entry
+ const int rc = httpd::setupReadPolicy(r);
+ if(rc != OK)
+ return rc;
+ const list<string> ls = httpd::read(r);
+ debug(ls, "modeval::patch::input");
+ const value aval = elementsToValues(content(atom::isATOMEntry(ls)? atom::readATOMEntry(ls) : atom::readATOMFeed(ls)));
+
+ // Evaluate the PATCH expression and update the corresponding resource
+ const failable<value> val = failableResult(impl(cons<value>("patch", mklist<value>(cddr(rpath), aval))));
+ if (!hasContent(val))
+ return mkfailure<int>(val);
+
+ // Report HTTP status
+ const value rval = content(val);
+ if (isNil(rval) || rval == falseValue)
+ return HTTP_NOT_FOUND;
+ if (isNumber(rval))
+ return (int)rval;
+ return OK;
+}
+
+/**
* Handle an HTTP DELETE.
*/
const failable<int> del(const list<value>& rpath, request_rec* const r, const lvvlambda& impl) {
@@ -928,7 +956,7 @@ int translateComponent(request_rec* const r, const list<value>& rpath, const lis
// Find the requested component
if (isNil(cdr(rpath)))
return HTTP_NOT_FOUND;
- const list<value> impl(assoctree(cadr(rpath), impls));
+ const list<value> impl(rbtreeAssoc(cadr(rpath), impls));
if (isNil(impl))
return HTTP_NOT_FOUND;
debug(impl, "modeval::translateComponent::impl");
@@ -947,13 +975,13 @@ int translateReference(request_rec* const r, const list<value>& rpath, const lis
// Find the requested component
if (isNil(cdr(rpath)))
return HTTP_NOT_FOUND;
- const list<value> comp(assoctree(cadr(rpath), refs));
+ const list<value> comp(rbtreeAssoc(cadr(rpath), refs));
if (isNil(comp))
return HTTP_NOT_FOUND;
debug(comp, "modeval::translateReference::comp");
// Find the requested reference and target configuration
- const list<value> ref(assoctree<value>(caddr(rpath), cadr(comp)));
+ const list<value> ref(rbtreeAssoc<value>(caddr(rpath), cadr(comp)));
if (isNil(ref))
return HTTP_NOT_FOUND;
debug(ref, "modeval::translateReference::ref");
@@ -1087,7 +1115,7 @@ const int translateRequest(request_rec* const r, const list<value>& rpath, const
* Translate a request.
*/
int translate(request_rec *r) {
- if(r->method_number != M_GET && r->method_number != M_POST && r->method_number != M_PUT && r->method_number != M_DELETE)
+ if(r->method_number != M_GET && r->method_number != M_POST && r->method_number != M_PUT && r->method_number != M_PATCH && r->method_number != M_DELETE)
return DECLINED;
const gc_scoped_pool sp(r->pool);
@@ -1151,7 +1179,7 @@ const int handleRequest(const list<value>& rpath, request_rec* const r, const li
debug(rpath, "modeval::handleRequest::path");
// Get the component implementation lambda
- const list<value> impl(assoctree<value>(cadr(rpath), impls));
+ const list<value> impl(rbtreeAssoc<value>(cadr(rpath), impls));
if (isNil(impl)) {
mkfailure<int>(string("Couldn't find component implementation: ") + (string)cadr(rpath));
return HTTP_NOT_FOUND;
@@ -1167,6 +1195,8 @@ const int handleRequest(const list<value>& rpath, request_rec* const r, const li
return httpd::reportStatus(post(rpath, r, l));
if(r->method_number == M_PUT)
return httpd::reportStatus(put(rpath, r, l));
+ if(r->method_number == M_PATCH)
+ return httpd::reportStatus(patch(rpath, r, l));
if(r->method_number == M_DELETE)
return httpd::reportStatus(del(rpath, r, l));
return HTTP_NOT_IMPLEMENTED;
@@ -1219,7 +1249,7 @@ int handler(request_rec* r) {
const list<value> simpls = content(fsimpls);
// Merge the components in the virtual host with the components in the main host
- reqc.impls = mkbtree(sort(append(flatten((const list<value>)sc.compos.impls), flatten(simpls))));
+ reqc.impls = mkbrbtree(sort(append(flatten((const list<value>)sc.compos.impls), flatten(simpls))));
// Handle the request against the running components
const int rc = handleRequest(reqc.rpath, r, reqc.impls);
@@ -1418,7 +1448,7 @@ void childInit(apr_pool_t* p, server_rec* s) {
// Get the vhost contributor component implementation lambda
if (length(sc.vhostc.contributorName) != 0) {
- const list<value> impl(assoctree<value>((string)sc.vhostc.contributorName, (const list<value>)sc.compos.impls));
+ const list<value> impl(rbtreeAssoc<value>((string)sc.vhostc.contributorName, (const list<value>)sc.compos.impls));
if (isNil(impl)) {
mkfailure<int>(string("Couldn't find contributor component implementation: ") + sc.vhostc.contributorName);
failureExitChild();
@@ -1428,7 +1458,7 @@ void childInit(apr_pool_t* p, server_rec* s) {
// Get the vhost authenticator component implementation lambda
if (length(sc.vhostc.authenticatorName) != 0) {
- const list<value> impl(assoctree<value>((string)sc.vhostc.authenticatorName, (const list<value>)sc.compos.impls));
+ const list<value> impl(rbtreeAssoc<value>((string)sc.vhostc.authenticatorName, (const list<value>)sc.compos.impls));
if (isNil(impl)) {
mkfailure<int>(string("Couldn't find authenticator component implementation: ") + sc.vhostc.authenticatorName);
failureExitChild();
diff --git a/sca-cpp/trunk/modules/server/server-test.scm b/sca-cpp/trunk/modules/server/server-test.scm
index 4bbff6e5c2..b9ed6d584c 100644
--- a/sca-cpp/trunk/modules/server/server-test.scm
+++ b/sca-cpp/trunk/modules/server/server-test.scm
@@ -22,7 +22,7 @@
; ATOMPub test case
(define (get id)
- (if (nul id)
+ (if (null? id)
'((feed (title "Sample Feed") (id "123456789") (entry
(((title "Item") (id "111") (content (item (name "Apple") (currencyCode "USD") (currencySymbol "$") (price 2.99))))
((title "Item") (id "222") (content (item (name "Orange") (currencyCode "USD") (currencySymbol "$") (price 3.55))))
@@ -39,6 +39,10 @@
true
)
+(define (patch id item)
+ true
+)
+
(define (delete id)
true
)
diff --git a/sca-cpp/trunk/modules/server/wiring-test b/sca-cpp/trunk/modules/server/wiring-test
index 7e1aea22b1..a00255e332 100755
--- a/sca-cpp/trunk/modules/server/wiring-test
+++ b/sca-cpp/trunk/modules/server/wiring-test
@@ -60,6 +60,10 @@ if [ "$rc" = "0" ]; then
rc=$?
fi
if [ "$rc" = "0" ]; then
+ $curl_prefix/bin/curl http://localhost:8090/client/111 -X PATCH -H "Content-type: application/atom+xml" --data @htdocs/test/entry.xml 2>/dev/null
+ rc=$?
+fi
+if [ "$rc" = "0" ]; then
$curl_prefix/bin/curl http://localhost:8090/client/111 -X DELETE 2>/dev/null
rc=$?
fi