From f278315081b24b59bf73e9613e552e3519200a71 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 28 May 2012 04:39:18 +0000 Subject: Improve error reporting with a reason code. Improve debug and audit logging. Fix test scripts to cleanup state from previous builds and correctly report test errors. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1343138 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/server/mod-eval.hpp | 135 ++++++++++++++++++++---------- 1 file changed, 89 insertions(+), 46 deletions(-) (limited to 'sca-cpp/trunk/modules/server/mod-eval.hpp') diff --git a/sca-cpp/trunk/modules/server/mod-eval.hpp b/sca-cpp/trunk/modules/server/mod-eval.hpp index ef2a2f6575..ac5bf55698 100644 --- a/sca-cpp/trunk/modules/server/mod-eval.hpp +++ b/sca-cpp/trunk/modules/server/mod-eval.hpp @@ -151,7 +151,7 @@ public: const failable failableResult(const list& v) { if (isNil(cdr(v))) return car(v); - return mkfailure(string(cadr(v)), false); + return mkfailure(string(cadr(v)), isNil(cddr(v))? -1 : (int)caddr(v), false); } /** @@ -191,7 +191,7 @@ public: } const value callImpl(const value& cname, const list& aparams) const { - debug(impls, "modeval::implProxy::callImpl::impls"); + //debug(impls, "modeval::implProxy::callImpl::impls"); // Lookup the component implementation const list impl(assoctree(cname, impls)); @@ -345,9 +345,11 @@ struct hostPropProxy { hostPropProxy(const value& v) : v(v) { } const value operator()(unused const list& params) const { - const value r = httpd::hostName(currentRequest, v); - debug(r, "modeval::hostPropProxy::value"); - return r; + if (currentRequest == NULL) + return http::hostName(); + const value h = httpd::hostName(currentRequest, v); + debug(h, "modeval::hostPropProxy::value"); + return h; } }; @@ -356,6 +358,8 @@ struct appPropProxy { appPropProxy(const value& v) : v(v) { } const value operator()(unused const list& params) const { + if (currentRequest == NULL) + return v; const RequestConf& reqc = httpd::requestConf(currentRequest, &mod_tuscany_eval); const value a = isNil(reqc.vpath)? v : car(reqc.vpath); debug(a, "modeval::appPropProxy::value"); @@ -364,23 +368,29 @@ struct appPropProxy { }; struct pathPropProxy { - pathPropProxy(unused const value& v) { + const value v; + pathPropProxy(const value& v) : v(v) { } const value operator()(unused const list& params) const { + if (currentRequest == NULL) + return v; const RequestConf& reqc = httpd::requestConf(currentRequest, &mod_tuscany_eval); - const value v = reqc.rpath; - debug(v, "modeval::pathPropProxy::value"); - return v; + const value p = reqc.rpath; + debug(p, "modeval::pathPropProxy::value"); + return p; } }; struct queryPropProxy { - queryPropProxy(unused const value& v) { + const value v; + queryPropProxy(const value& v) : v(v) { } const value operator()(unused const list& params) const { - const value v = httpd::unescapeArgs(httpd::queryArgs(currentRequest)); - debug(v, "modeval::queryPropProxy::value"); - return v; + if (currentRequest == NULL) + return v; + const value q = httpd::unescapeArgs(httpd::queryArgs(currentRequest)); + debug(q, "modeval::queryPropProxy::value"); + return q; } }; @@ -390,10 +400,34 @@ struct envPropProxy { envPropProxy(const string& name, const value& v) : name(name), v(v) { } const value operator()(unused const list& params) const { + if (currentRequest == NULL) + return v; const char* env = apr_table_get(currentRequest->subprocess_env, c_str(name)); if (env == NULL || *env == '\0') return v; - return string(env); + debug(name, "modeval::envPropProxy::name"); + const value e = string(env); + debug(e, "modeval::envPropProxy::value"); + return e; + } +}; + +struct realmPropProxy { + const value v; + realmPropProxy(const value& v) : v(v) { + } + const value operator()(unused const list& params) const { + if (currentRequest == NULL) + return v; + const char* env = apr_table_get(currentRequest->subprocess_env, "REALM"); + if (env == NULL) + return v; + const char* realm = strncmp(env, "www.", 4) == 0? env + 4 : env; + if (*realm == '\0') + return v; + const value r = string(realm); + debug(r, "modeval::realmPropProxy::value"); + return r; } }; @@ -402,9 +436,13 @@ struct userPropProxy { userPropProxy(const value& v) : v(v) { } const value operator()(unused const list& params) const { + if (currentRequest == NULL) + return v; if (currentRequest->user == NULL) return v; - return string(currentRequest->user); + const value u = string(currentRequest->user); + debug(u, "modeval::userPropProxy::value"); + return u; } }; @@ -422,7 +460,7 @@ const value mkpropProxy(const value& prop) { if (n == "user") return lambda&)>(userPropProxy(v)); if (n == "realm") - return lambda&)>(envPropProxy("REALM", v)); + return lambda&)>(realmPropProxy(v)); if (n == "email") return lambda&)>(envPropProxy("EMAIL", v)); if (n == "nickname") @@ -508,13 +546,13 @@ const failable > readComponents(const string& path) { const failable > getComponents(const lambda&)>& provider, const string& name) { const failable val = failableResult(provider(cons("get", mklist(mklist(name))))); if (!hasContent(val)) - return mkfailure >(reason(val)); + return mkfailure >(val); const list c = assoc(value("content"), (list >)cdr(content(val))); if (isNil(c)) return mkfailure >(string("Could not get composite: ") + name); const failable > x = writeXML(car(valuesToElements(mklist(mklist(cadr(c)))))); if (!hasContent(x)) - return mkfailure >(reason(x)); + return mkfailure >(x); return scdl::components(readXML(content(x))); } @@ -530,7 +568,7 @@ const failable > applyLifecycleExpr(const list& impls, const const lambda&)> l = cadr(car(impls)); const failable r = failableResult(l(expr)); if (!hasContent(r)) - return mkfailure >(reason(r)); + return mkfailure >(r); const lambda&)> rl = content(r); // Use the returned lambda function, if any, from now on @@ -604,7 +642,7 @@ const failable confComponents(const string& contribPath, const string readComponents(scdl::resourcePath(length(vhost) != 0? contribPath + vhost + "/" : contribPath, composName)) : getComponents(provider, vhost); if (!hasContent(fcomps)) - return mkfailure(reason(fcomps)); + return mkfailure(fcomps); const list comps = content(fcomps); debug(comps, "modeval::confComponents::comps"); @@ -630,7 +668,7 @@ const failable > startComponents(const list& impls) { debug(flatten(impls), "modeval::startComponents::impls"); const failable > fsimpls = applyLifecycleExpr(flatten(impls), mklist("start")); if (!hasContent(fsimpls)) - return mkfailure >(reason(fsimpls)); + return mkfailure >(fsimpls); const list simpls = content(fsimpls); debug(impls, "modeval::startComponents::simpls"); @@ -667,7 +705,7 @@ const failable get(const list& rpath, request_rec* r, const lambda val = failableResult(impl(cons(func, json::queryParams(args)))); if (!hasContent(val)) - return mkfailure(reason(val)); + return mkfailure(val); // Return JSON result js::JSContext cx; @@ -678,7 +716,7 @@ const failable get(const list& rpath, request_rec* r, const lambda params(cddr(rpath)); const failable val = failableResult(impl(cons("get", mklist(params)))); if (!hasContent(val)) - return mkfailure(reason(val)); + return mkfailure(val); const value c = content(val); debug(c, "modeval::get::content"); @@ -776,7 +814,7 @@ const failable post(const list& rpath, request_rec* r, const lambda< // Evaluate the request expression const failable val = failableResult(impl(cons(func, params))); if (!hasContent(val)) - return mkfailure(reason(val)); + return mkfailure(val); // Return JSON result return httpd::writeResult(json::jsonResult(id, content(val), cx), "application/json-rpc; charset=utf-8", r); @@ -796,7 +834,7 @@ const failable post(const list& rpath, request_rec* r, const lambda< // Evaluate the POST expression const failable val = failableResult(impl(cons("post", mklist(cddr(rpath), aval)))); if (!hasContent(val)) - return mkfailure(reason(val)); + return mkfailure(val); // Return the created resource location debug(content(val), "modeval::post::location"); @@ -809,7 +847,7 @@ const failable post(const list& rpath, request_rec* r, const lambda< // the component implementation function const failable val = failableResult(impl(cons("handle", mklist(httpd::requestValue(r))))); if (!hasContent(val)) - return mkfailure(reason(val)); + return mkfailure(val); return (int)content(val); } @@ -830,7 +868,7 @@ const failable put(const list& rpath, request_rec* r, const lambda val = failableResult(impl(cons("put", mklist(cddr(rpath), aval)))); if (!hasContent(val)) - return mkfailure(reason(val)); + return mkfailure(val); if (val == value(false)) return HTTP_NOT_FOUND; return OK; @@ -845,7 +883,7 @@ const failable del(const list& rpath, request_rec* r, const lambda val = failableResult(impl(cons("delete", mklist(cddr(rpath))))); if (!hasContent(val)) - return mkfailure(reason(val)); + return mkfailure(val); if (val == value(false)) return HTTP_NOT_FOUND; return OK; @@ -854,7 +892,12 @@ const failable del(const list& rpath, request_rec* r, const lambda& rpath, const list& vpath, const list& impls) { +int proceedToHandler(request_rec* r, const int rc) { + r->handler = "mod_tuscany_eval"; + return rc; +} + +int proceedToHandler(request_rec* r, const int rc, const bool valias, const list& rpath, const list& vpath, const list& impls) { r->handler = "mod_tuscany_eval"; r->filename = apr_pstrdup(r->pool, c_str(string("/redirect:") + r->uri)); @@ -864,7 +907,7 @@ int proceedToHandler(request_rec* r, const bool valias, const list& rpath reqc.rpath = rpath; reqc.vpath = vpath; reqc.impls = impls; - return OK; + return rc; } /** @@ -882,7 +925,7 @@ int translateComponent(request_rec *r, const list& rpath, const list& rpath, const list redir = cons(string("c"), cons(tname, pathInfo)); debug(redir, "modeval::translateReference::redirect"); - return proceedToHandler(r, false, redir, vpath, impls);; + return proceedToHandler(r, OK, false, redir, vpath, impls);; } /** @@ -973,7 +1016,7 @@ int translateService(request_rec *r, const list& rpath, const list // / c / target component name / request path info const list redir = cons(string("c"), cons(cadr(svc), httpd::pathInfo(rpath, car(svc)))); debug(redir, "modeval::translateService::redirect"); - return proceedToHandler(r, false, redir, vpath, impls); + return proceedToHandler(r, OK, false, redir, vpath, impls); } /** @@ -986,15 +1029,15 @@ const int translateRequest(request_rec* r, const list& rpath, const list< // Translate a component request if ((prefix == string("components") || prefix == string("c")) && translateComponent(r, rpath, vpath, impls) == OK) - return OK; + return proceedToHandler(r, OK); // Translate a component reference request if ((prefix == string("references") || prefix == string("r")) && translateReference(r, rpath, vpath, refs, impls) == OK) - return OK; + return proceedToHandler(r, OK); // Attempt to translate the request to a service request if (translateService(r, rpath, vpath, svcs, impls) == OK) - return OK; + return proceedToHandler(r, OK); // Attempt to map a request targeting the main host to an actual file if (isNil(vpath)) { @@ -1019,15 +1062,14 @@ const int translateRequest(request_rec* r, const list& rpath, const list< if (isNil(rpath) && r->uri[strlen(r->uri) - 1] != '/') { const string target = string(r->uri) + string("/") + (r->args != NULL? string("?") + string(r->args) : string("")); debug(target, "modeval::translateRequest::location"); - r->handler = "mod_tuscany_eval"; - return httpd::externalRedirect(target, r); + return proceedToHandler(r, httpd::externalRedirect(target, r)); } // If the request didn't match a service, reference or component, // redirect it to / v / app / path. This will allow mapping to // the actual app resource using HTTPD aliases. debug(true, "modeval::translateRequest::valias"); - return proceedToHandler(r, true, rpath, vpath, impls); + return proceedToHandler(r, OK, true, rpath, vpath, impls); } return HTTP_NOT_FOUND; @@ -1093,7 +1135,6 @@ int translate(request_rec *r) { reqc.impls = vcompos.impls; return translateRequest(r, cdr(rpath), mklist(vname), vcompos.refs, vcompos.svcs, reqc.impls); } - return DECLINED; } @@ -1129,15 +1170,18 @@ const int handleRequest(const list& rpath, request_rec *r, const listmethod_number != M_GET && r->method_number != M_POST && r->method_number != M_PUT && r->method_number != M_DELETE) + if (r->handler != NULL && r->handler[0] != '\0') return DECLINED; + + // Attempt to translate the request + const int trc = translate(r); + + // Pass if we couldn't translate the request + if(trc != OK) + return trc; if(strcmp(r->handler, "mod_tuscany_eval")) return DECLINED; - // Nothing to do for an external redirect - if (r->status == HTTP_MOVED_TEMPORARILY) - return OK; - // Create a scoped memory pool and a scope for the current request gc_scoped_pool pool(r->pool); ScopedRequest sr(r); @@ -1397,7 +1441,6 @@ void registerHooks(unused apr_pool_t *p) { ap_hook_post_config(postConfig, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_child_init(childInit, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_handler(handler, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_translate_name(translate, NULL, NULL, APR_HOOK_LAST); } } -- cgit v1.2.3