Added: tuscany/sca-cpp/trunk/modules/server/mod-scm.hpp URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/mod-scm.hpp?rev=883249&view=auto ============================================================================== --- tuscany/sca-cpp/trunk/modules/server/mod-scm.hpp (added) +++ tuscany/sca-cpp/trunk/modules/server/mod-scm.hpp Mon Nov 23 05:25:33 2009 @@ -0,0 +1,92 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_modscm_hpp +#define tuscany_modscm_hpp + +/** + * Evaluation functions used by mod-eval to evaluate implementation.scheme + * component implementations. + */ + +#include <string> +#include <iostream> +#include <fstream> + +#include "function.hpp" +#include "list.hpp" +#include "value.hpp" +#include "monad.hpp" +#include "cache.hpp" +#include "../eval/driver.hpp" +#include "../http/httpd.hpp" +#include "mod-eval.hpp" + +namespace tuscany { +namespace server { +namespace modeval { +namespace scm { + +/** + * Evaluate a script component implementation function. + */ +struct evalImplementation { + const value impl; + evalImplementation(const value& impl) : impl(impl) { + } + const failable<value, std::string> operator()(const value& func, const list<value>& params) const { + const value expr = cons<value>(func, eval::quotedParameters(params)); + httpd::logValue(expr, "expr"); + gc_pool pool; + eval::Env globalEnv = eval::setupEnvironment(pool); + const value val = eval::evalScript(expr, impl, globalEnv, pool); + httpd::logValue(val, "val"); + if (isNil(val)) + return mkfailure<value, std::string>("Could not evaluate expression"); + return val; + } +}; + +/** + * Read a script component implementation. + */ +const failable<ilambda, std::string> readLatestImplementation(const std::string path) { + std::ifstream is(path.c_str(), std::ios_base::in); + if (is.fail() || is.bad()) + return mkfailure<ilambda, std::string>("Could not read implementation: " + path); + const value impl = eval::readScript(is); + if (isNil(impl)) + return mkfailure<ilambda, std::string>("Could not read implementation: " + path); + return ilambda(evalImplementation(impl)); +} + +const cached<failable<ilambda, std::string> > readImplementation(const std::string& path) { + const lambda<failable<ilambda, std::string>(std::string)> ri(readLatestImplementation); + const lambda<unsigned long(std::string)> ft(latestFileTime); + return cached<failable<ilambda, std::string> >(curry(ri, path), curry(ft, path)); +} + +} +} +} +} + +#endif /* tuscany_modscm_hpp */
Copied: tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp (from r880633, tuscany/sca-cpp/trunk/modules/http/mod-wiring.cpp) URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp?p2=tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp&p1=tuscany/sca-cpp/trunk/modules/http/mod-wiring.cpp&r1=880633&r2=883249&rev=883249&view=diff ============================================================================== --- tuscany/sca-cpp/trunk/modules/http/mod-wiring.cpp (original) +++ tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp Mon Nov 23 05:25:33 2009 @@ -20,7 +20,7 @@ /* $Rev$ $Date$ */ /** - * HTTPD module used to wire components. + * HTTPD module used to wire component references. */ #include <sys/stat.h> @@ -34,16 +34,16 @@ #include "slist.hpp" #include "value.hpp" #include "monad.hpp" +#include "cache.hpp" #include "../scdl/scdl.hpp" -#include "../cache/cache.hpp" -#include "httpd.hpp" +#include "../http/httpd.hpp" extern "C" { extern module AP_MODULE_DECLARE_DATA mod_tuscany_wiring; } namespace tuscany { -namespace httpd { +namespace server { namespace modwiring { /** @@ -51,15 +51,12 @@ */ class ServerConf { public: - std::string home; - ServerConf() : home("") { + ServerConf(server_rec* s) : home("") { } + server_rec* s; + std::string home; }; -const ServerConf& serverConf(const request_rec* r) { - return *(ServerConf*)ap_get_module_config(r->server->module_config, &mod_tuscany_wiring); -} - /** * Set to true to wire using mod_proxy, false to wire using HTTP client redirects. */ @@ -70,17 +67,14 @@ */ class DirConf { public: - DirConf() : contributionPath(""), compositeName("") { + DirConf(char* dirspec) : contributionPath(""), compositeName("") { } + char* dirspec; std::string contributionPath; std::string compositeName; - cache::cached<failable<list<value>, std::string> > components; + cached<failable<list<value>, std::string> > components; }; -DirConf& dirConf(const request_rec* r) { - return *(DirConf*)ap_get_module_config(r->per_dir_config, &mod_tuscany_wiring); -} - /** * Read the SCDL configuration of the deployed components. */ @@ -91,11 +85,11 @@ return scdl::components(readXML(streamList(is))); } -const cache::cached<failable<list<value>, std::string> > components(DirConf* conf) { +const cached<failable<list<value>, std::string> > components(DirConf* conf) { const std::string path(conf->contributionPath + conf->compositeName); const lambda<failable<list<value>, std::string>(std::string)> rc(readComponents); - const lambda<unsigned long(std::string)> ft(cache::latestFileTime); - return cache::cached<failable<list<value>, std::string> >(curry(rc, path), curry(ft, path)); + const lambda<unsigned long(std::string)> ft(latestFileTime); + return cached<failable<list<value>, std::string> >(curry(rc, path), curry(ft, path)); } /** @@ -112,19 +106,16 @@ int translate(request_rec *r) { if (strncmp(r->uri, "/references/", 12) != 0) return DECLINED; - const list<value> rpath(path(r->uri)); - - // Log the request - if(logRequests) - logRequest(r, "mod_tuscany_wiring::translate"); + httpd::logRequest(r, "mod_tuscany_wiring::translate"); // Find the requested component, reference and its target configuration - DirConf& conf = dirConf(r); - conf.components = cache::latest(conf.components); - const failable<list<value>, std::string> comps(conf.components); - if (!hasValue(comps)) + DirConf& conf = httpd::dirConf<DirConf>(r, &mod_tuscany_wiring); + conf.components = latest(conf.components); + const failable<list<value>, std::string> comps(content(conf.components)); + if (!hasContent(comps)) return HTTP_INTERNAL_SERVER_ERROR; - const value comp(scdl::named(cadr(rpath), list<value>(comps))); + const list<value> rpath(httpd::path(r->uri)); + const value comp(scdl::named(cadr(rpath), list<value>(content(comps)))); if (isNil(comp)) return HTTP_NOT_FOUND; const value ref(scdl::named(caddr(rpath), scdl::references(comp))); @@ -174,10 +165,7 @@ int handler(request_rec *r) { if(strcmp(r->handler, "mod_tuscany_wiring")) return DECLINED; - - // Log the request - if(logRequests) - logRequest(r, "mod_tuscany_wiring::handler"); + httpd::logRequest(r, "mod_tuscany_wiring::handler"); // Do an internal redirect if (r->filename == NULL || strncmp(r->filename, "/redirect:", 10) != 0) @@ -211,17 +199,6 @@ return NULL; } -void *makeDirConf(apr_pool_t *p, char *dirspec) { - DirConf* c = new (apr_palloc(p, sizeof(DirConf))) DirConf(); - apr_pool_cleanup_register(p, c, gc_pool_cleanupCallback<DirConf>, apr_pool_cleanup_null) ; - return c; -} -void* makeServerConf(apr_pool_t *p, server_rec *s) { - ServerConf* c = new (apr_palloc(p, sizeof(ServerConf))) ServerConf(); - apr_pool_cleanup_register(p, c, gc_pool_cleanupCallback<ServerConf>, apr_pool_cleanup_null) ; - return c; -} - /** * HTTP server module declaration. */ @@ -259,18 +236,12 @@ module AP_MODULE_DECLARE_DATA mod_tuscany_wiring = { STANDARD20_MODULE_STUFF, - // dir config - tuscany::httpd::modwiring::makeDirConf, - // dir merger, default is to override - NULL, - // server config - tuscany::httpd::modwiring::makeServerConf, - // merge server config - NULL, - // command table - tuscany::httpd::modwiring::commands, - // register hooks - tuscany::httpd::modwiring::registerHooks + // dir config and merger + tuscany::httpd::makeDirConf<tuscany::server::modwiring::DirConf>, NULL, + // server config and merger + tuscany::httpd::makeServerConf<tuscany::server::modwiring::ServerConf>, NULL, + // commands and hooks + tuscany::server::modwiring::commands, tuscany::server::modwiring::registerHooks }; } Copied: tuscany/sca-cpp/trunk/modules/server/server-conf (from r880633, tuscany/sca-cpp/trunk/modules/http/httpd-conf) URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/server-conf?p2=tuscany/sca-cpp/trunk/modules/server/server-conf&p1=tuscany/sca-cpp/trunk/modules/http/httpd-conf&r1=880633&r2=883249&rev=883249&view=diff ============================================================================== --- tuscany/sca-cpp/trunk/modules/http/httpd-conf (original) +++ tuscany/sca-cpp/trunk/modules/server/server-conf Mon Nov 23 05:25:33 2009 @@ -17,21 +17,16 @@ # specific language governing permissions and limitations # under the License. -# Generate a minimal httpd.conf +# Generate a server conf here=`readlink -f $0`; here=`dirname $here` root=`readlink -f $1` -port=$2 -htdocs=`readlink -f $3` mkdir -p $root mkdir -p $root/logs mkdir -p $root/conf -cat >$root/conf/httpd.conf <<EOF -ServerName 127.0.0.1 -Listen $port -DocumentRoot $htdocs -TypesConfig $here/conf/mime.types +cat >>$root/conf/httpd.conf <<EOF LoadModule mod_tuscany_eval $here/.libs/libmod_tuscany_eval.so LoadModule mod_tuscany_wiring $here/.libs/libmod_tuscany_wiring.so +LoadModule mod_tuscany_cache $here/.libs/libmod_tuscany_cache.so EOF Copied: tuscany/sca-cpp/trunk/modules/server/wiring-test (from r880633, tuscany/sca-cpp/trunk/modules/http/wiring-test) URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/wiring-test?p2=tuscany/sca-cpp/trunk/modules/server/wiring-test&p1=tuscany/sca-cpp/trunk/modules/http/wiring-test&r1=880633&r2=883249&rev=883249&view=diff ============================================================================== --- tuscany/sca-cpp/trunk/modules/http/wiring-test (original) +++ tuscany/sca-cpp/trunk/modules/server/wiring-test Mon Nov 23 05:25:33 2009 @@ -20,7 +20,8 @@ echo "Testing..." # Setup -./httpd-conf tmp 8092 htdocs +../http/httpd-conf tmp 8090 htdocs +./server-conf tmp cat >>tmp/conf/httpd.conf <<EOF <Location /test> @@ -48,37 +49,37 @@ sleep 1 # Test HTTP GET -curl http://localhost:8092/index.html 2>/dev/null >tmp/index.html +curl http://localhost:8090/index.html 2>/dev/null >tmp/index.html diff tmp/index.html htdocs/index.html rc=$? # Test ATOMPub if [ "$rc" = "0" ]; then - curl http://localhost:8092/client/ >tmp/feed.xml 2>/dev/null + curl http://localhost:8090/client/ >tmp/feed.xml 2>/dev/null diff tmp/feed.xml htdocs/feed.xml rc=$? fi if [ "$rc" = "0" ]; then - curl http://localhost:8092/client/111 >tmp/entry.xml 2>/dev/null + curl http://localhost:8090/client/111 >tmp/entry.xml 2>/dev/null diff tmp/entry.xml htdocs/entry.xml rc=$? fi if [ "$rc" = "0" ]; then - curl http://localhost:8092/client/ -X POST -H "Content-type: application/atom+xml" --data @htdocs/entry.xml 2>/dev/null + curl http://localhost:8090/client/ -X POST -H "Content-type: application/atom+xml" --data @htdocs/entry.xml 2>/dev/null rc=$? fi if [ "$rc" = "0" ]; then - curl http://localhost:8092/client/111 -X PUT -H "Content-type: application/atom+xml" --data @htdocs/entry.xml 2>/dev/null + curl http://localhost:8090/client/111 -X PUT -H "Content-type: application/atom+xml" --data @htdocs/entry.xml 2>/dev/null rc=$? fi if [ "$rc" = "0" ]; then - curl http://localhost:8092/client/111 -X DELETE 2>/dev/null + curl http://localhost:8090/client/111 -X DELETE 2>/dev/null rc=$? fi # Test JSON-RPC if [ "$rc" = "0" ]; then - curl http://localhost:8092/client/ -X POST -H "Content-type: application/json-rpc" --data @htdocs/json-request.txt >tmp/json-result.txt 2>/dev/null + curl http://localhost:8090/client/ -X POST -H "Content-type: application/json-rpc" --data @htdocs/json-request.txt >tmp/json-result.txt 2>/dev/null diff tmp/json-result.txt htdocs/json-result.txt rc=$? fi Modified: tuscany/sca-cpp/trunk/test/store-script/store-http-test URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/test/store-script/store-http-test?rev=883249&r1=883248&r2=883249&view=diff ============================================================================== --- tuscany/sca-cpp/trunk/test/store-script/store-http-test (original) +++ tuscany/sca-cpp/trunk/test/store-script/store-http-test Mon Nov 23 05:25:33 2009 @@ -20,7 +20,8 @@ echo "Testing..." # Setup -../../modules/http/httpd-conf tmp 8093 htdocs +../../modules/http/httpd-conf tmp 8090 htdocs +../../modules/server/server-conf tmp cat >>tmp/conf/httpd.conf <<EOF <Location /Catalog> @@ -62,7 +63,7 @@ sleep 1 # Test HTTP GET -curl http://localhost:8093/store.html 2>/dev/null >tmp/store.html +curl http://localhost:8090/store.html 2>/dev/null >tmp/store.html diff tmp/store.html htdocs/store.html rc=$?
