diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-02-26 20:59:35 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-02-26 20:59:35 +0000 |
commit | 7c018c6fb691b65ac1cb181a95f5766e2933eb3c (patch) | |
tree | b12eb4fd6fc05faebd9d481f1d57599cd0b2829e /sca-cpp/trunk/modules/server | |
parent | 0ee21c5d9657a1259a731722f53666ad135279bb (diff) |
Correctly pass query strings through component wiring redirects and improve format of XML and JSON response documents.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1074924 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/server')
-rw-r--r-- | sca-cpp/trunk/modules/server/htdocs/test/entry.xml | 14 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/htdocs/test/feed.xml | 44 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/htdocs/test/json-properties.txt | 14 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/htdocs/test/json-result.txt | 5 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/mod-eval.hpp | 79 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/mod-wiring.cpp | 4 |
6 files changed, 126 insertions, 34 deletions
diff --git a/sca-cpp/trunk/modules/server/htdocs/test/entry.xml b/sca-cpp/trunk/modules/server/htdocs/test/entry.xml index 6528c793e3..46053c3138 100644 --- a/sca-cpp/trunk/modules/server/htdocs/test/entry.xml +++ b/sca-cpp/trunk/modules/server/htdocs/test/entry.xml @@ -1,2 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> -<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><id>111</id><content type="application/xml"><item><name>Apple</name><currencyCode>USD</currencyCode><currencySymbol>$</currencySymbol><price>2.99</price></item></content><link href="111"/></entry> +<entry xmlns="http://www.w3.org/2005/Atom"> + <title type="text">Item</title> + <id>111</id> + <content type="application/xml"> + <item> + <name>Apple</name> + <currencyCode>USD</currencyCode> + <currencySymbol>$</currencySymbol> + <price>2.99</price> + </item> + </content> + <link href="111"/> +</entry> diff --git a/sca-cpp/trunk/modules/server/htdocs/test/feed.xml b/sca-cpp/trunk/modules/server/htdocs/test/feed.xml index bcb304f9c2..337320e4c5 100644 --- a/sca-cpp/trunk/modules/server/htdocs/test/feed.xml +++ b/sca-cpp/trunk/modules/server/htdocs/test/feed.xml @@ -1,2 +1,44 @@ <?xml version="1.0" encoding="UTF-8"?> -<feed xmlns="http://www.w3.org/2005/Atom"><title type="text">Sample Feed</title><id>123456789</id><entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><id>111</id><content type="application/xml"><item><name>Apple</name><currencyCode>USD</currencyCode><currencySymbol>$</currencySymbol><price>2.99</price></item></content><link href="111"/></entry><entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><id>222</id><content type="application/xml"><item><name>Orange</name><currencyCode>USD</currencyCode><currencySymbol>$</currencySymbol><price>3.55</price></item></content><link href="222"/></entry><entry xmlns="http://www.w3.org/2005/Atom"><title type="text">Item</title><id>333</id><content type="application/xml"><item><name>Pear</name><currencyCode>USD</currencyCode><currencySymbol>$</currencySymbol><price>1.55</price></item></content><link href="333"/></entry></feed> +<feed xmlns="http://www.w3.org/2005/Atom"> + <title type="text">Sample Feed</title> + <id>123456789</id> + <entry xmlns="http://www.w3.org/2005/Atom"> + <title type="text">Item</title> + <id>111</id> + <content type="application/xml"> + <item> + <name>Apple</name> + <currencyCode>USD</currencyCode> + <currencySymbol>$</currencySymbol> + <price>2.99</price> + </item> + </content> + <link href="111"/> + </entry> + <entry xmlns="http://www.w3.org/2005/Atom"> + <title type="text">Item</title> + <id>222</id> + <content type="application/xml"> + <item> + <name>Orange</name> + <currencyCode>USD</currencyCode> + <currencySymbol>$</currencySymbol> + <price>3.55</price> + </item> + </content> + <link href="222"/> + </entry> + <entry xmlns="http://www.w3.org/2005/Atom"> + <title type="text">Item</title> + <id>333</id> + <content type="application/xml"> + <item> + <name>Pear</name> + <currencyCode>USD</currencyCode> + <currencySymbol>$</currencySymbol> + <price>1.55</price> + </item> + </content> + <link href="333"/> + </entry> +</feed> diff --git a/sca-cpp/trunk/modules/server/htdocs/test/json-properties.txt b/sca-cpp/trunk/modules/server/htdocs/test/json-properties.txt index 70f0139ea0..75843bc286 100644 --- a/sca-cpp/trunk/modules/server/htdocs/test/json-properties.txt +++ b/sca-cpp/trunk/modules/server/htdocs/test/json-properties.txt @@ -1 +1,13 @@ -{"id":"1","result":{"host":"localhost","path":["components","property-test"],"query":{"id":"1","method":"print"}}}
\ No newline at end of file +{ + "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/htdocs/test/json-result.txt b/sca-cpp/trunk/modules/server/htdocs/test/json-result.txt index 121bf74902..38aa8a2a5e 100644 --- a/sca-cpp/trunk/modules/server/htdocs/test/json-result.txt +++ b/sca-cpp/trunk/modules/server/htdocs/test/json-result.txt @@ -1 +1,4 @@ -{"id":1,"result":"Hello"}
\ No newline at end of file +{ + "id":1, + "result":"Hello" +}
\ No newline at end of file diff --git a/sca-cpp/trunk/modules/server/mod-eval.hpp b/sca-cpp/trunk/modules/server/mod-eval.hpp index 64ab6df4bb..8047015cbc 100644 --- a/sca-cpp/trunk/modules/server/mod-eval.hpp +++ b/sca-cpp/trunk/modules/server/mod-eval.hpp @@ -125,24 +125,43 @@ const failable<int> get(request_rec* r, const lambda<value(const list<value>&)>& // Evaluate the GET expression const list<value> path(pathValues(r->uri)); - const failable<value> val = failableResult(impl(cons<value>("get", mklist<value>(cddr(path))))); + const list<value> params(append<value>(cddr(path), mkvalues(args))); + const failable<value> val = failableResult(impl(cons<value>("get", mklist<value>(params)))); if (!hasContent(val)) return mkfailure<int>(reason(val)); const value c = content(val); + // Write a simple value as a JSON value + if (!isList(c)) { + js::JSContext cx; + return httpd::writeResult(json::writeJSON(valuesToElements(mklist<value>(mklist<value>("value", c))), cx), "application/json", r); + } + + // Write an empty list as a JSON empty value + if (isNil(c)) { + js::JSContext cx; + return httpd::writeResult(json::writeJSON(list<value>(), cx), "application/json", r); + } + + // Write an assoc value as a JSON result + if (isSymbol(car<value>(c)) && !isNil(cdr<value>(c))) { + js::JSContext cx; + return httpd::writeResult(json::writeJSON(valuesToElements(mklist<value>(c)), cx), "application/json", r); + } + // Write content-type / content-list pair - if (isString(car<value>(c)) && isList(cadr<value>(c))) + if (isString(car<value>(c)) && !isNil(cdr<value>(c)) && isList(cadr<value>(c))) return httpd::writeResult(convertValues<string>(cadr<value>(c)), car<value>(c), r); - // Write ATOM feed or entry - if (isString(car<value>(c)) && isString(cadr<value>(c))) { + // Write an ATOM feed or entry + if (isString(car<value>(c)) && !isNil(cdr<value>(c)) && isString(cadr<value>(c))) { if (isNil(cddr(path))) return httpd::writeResult(atom::writeATOMFeed(atom::feedValuesToElements(c)), "application/atom+xml", r); else return httpd::writeResult(atom::writeATOMEntry(atom::entryValuesToElements(c)), "application/atom+xml", r); } - // Write JSON value + // Write any other compound value as a JSON value js::JSContext cx; return httpd::writeResult(json::writeJSON(valuesToElements(c), cx), "application/json", r); } @@ -419,27 +438,29 @@ 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") - return lambda<value(const list<value>&)>(envPropProxy("REALM", elementValue(prop))); - if (scdl::name(prop) == "email") - return lambda<value(const list<value>&)>(envPropProxy("EMAIL", elementValue(prop))); - if (scdl::name(prop) == "nickname") - return lambda<value(const list<value>&)>(envPropProxy("NICKNAME", elementValue(prop))); - if (scdl::name(prop) == "fullname") - return lambda<value(const list<value>&)>(envPropProxy("FULLNAME", elementValue(prop))); - if (scdl::name(prop) == "firstname") - return lambda<value(const list<value>&)>(envPropProxy("FIRSTNAME", elementValue(prop))); - if (scdl::name(prop) == "lastname") - return lambda<value(const list<value>&)>(envPropProxy("LASTNAME", elementValue(prop))); - return lambda<value(const list<value>&)>(propProxy(elementValue(prop))); + const value n = scdl::name(prop); + const value v = elementHasValue(prop)? elementValue(prop):value(string("")); + if (n == "host") + return lambda<value(const list<value>&)>(hostPropProxy(v)); + if (n == "path") + return lambda<value(const list<value>&)>(pathPropProxy(v)); + if (n == "query") + return lambda<value(const list<value>&)>(queryPropProxy(v)); + if (n == "user") + return lambda<value(const list<value>&)>(userPropProxy(v)); + if (n == "realm") + return lambda<value(const list<value>&)>(envPropProxy("REALM", v)); + if (n == "email") + return lambda<value(const list<value>&)>(envPropProxy("EMAIL", v)); + if (n == "nickname") + return lambda<value(const list<value>&)>(envPropProxy("NICKNAME", v)); + if (n == "fullname") + return lambda<value(const list<value>&)>(envPropProxy("FULLNAME", v)); + if (n == "firstname") + return lambda<value(const list<value>&)>(envPropProxy("FIRSTNAME", v)); + if (n == "lastname") + return lambda<value(const list<value>&)>(envPropProxy("LASTNAME", v)); + return lambda<value(const list<value>&)>(propProxy(v)); } const list<value> propProxies(const list<value>& props) { @@ -675,8 +696,10 @@ int handler(request_rec *r) { // Get the component implementation lambda const list<value> path(pathValues(r->uri)); const list<value> impl(assoctree<value>(cadr(path), usevh? vhc.vsc.implTree : sc.implTree)); - if (isNil(impl)) - return httpd::reportStatus(mkfailure<int>(string("Couldn't find component implementation: ") + cadr(path))); + if (isNil(impl)) { + mkfailure<int>(string("Couldn't find component implementation: ") + cadr(path)); + return HTTP_NOT_FOUND; + } // Handle HTTP method const lambda<value(const list<value>&)> l(cadr<value>(impl)); diff --git a/sca-cpp/trunk/modules/server/mod-wiring.cpp b/sca-cpp/trunk/modules/server/mod-wiring.cpp index b63cd3fb37..ac9e621177 100644 --- a/sca-cpp/trunk/modules/server/mod-wiring.cpp +++ b/sca-cpp/trunk/modules/server/mod-wiring.cpp @@ -107,7 +107,7 @@ int translateReference(const ServerConf& sc, request_rec *r) { if (useModProxy) { // Build proxy URI // current request's protocol scheme, reference target uri and request path info - string turi = httpd::scheme(r) + substr(target, find(target, "://")) + path(pathInfo); + string turi = httpd::scheme(r) + substr(target, find(target, "://")) + path(pathInfo) + (r->args != NULL? string("?") + r->args : string("")); r->filename = apr_pstrdup(r->pool, c_str(string("proxy:") + turi)); debug(r->filename, "modwiring::translateReference::filename"); r->proxyreq = PROXYREQ_REVERSE; @@ -124,7 +124,7 @@ int translateReference(const ServerConf& sc, request_rec *r) { // Route to a relative target URI using a local internal redirect // /components/, target component name and request path info const value tname = substr(target, 0, find(target, '/')); - const string tpath = path(cons(tname, pathInfo)); + const string tpath = path(cons(tname, pathInfo)) + (r->args != NULL? string("?") + r->args : string("")); r->filename = apr_pstrdup(r->pool, c_str(string("/redirect:/components") + tpath)); debug(r->filename, "modwiring::translateReference::filename"); r->handler = "mod_tuscany_wiring"; |