From e22bdc0f9572b6a1a2304799d481b25b3e962f87 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 11 Jan 2010 08:30:15 +0000 Subject: Improvements to autoconf build to make support for python, web service etc and relevant test cases optional and generate ac_defines used in ifdefs to check for debug and multithreading. Moved some optional code and test cases around to run them only when the tested features are built. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@897791 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/python/Makefile.am | 26 +++++-- sca-cpp/trunk/modules/python/client-test.cpp | 46 +++++++++++++ sca-cpp/trunk/modules/python/client-test.py | 22 ++++++ sca-cpp/trunk/modules/python/domain-test.composite | 42 ++++++++++++ sca-cpp/trunk/modules/python/htdocs/index.html | 21 ++++++ sca-cpp/trunk/modules/python/mod-python.cpp | 53 ++++++++++++++ sca-cpp/trunk/modules/python/mod-python.hpp | 80 ++++++++++++++++++++++ sca-cpp/trunk/modules/python/python-conf | 29 ++++++++ sca-cpp/trunk/modules/python/server-test | 42 ++++++++++++ sca-cpp/trunk/modules/python/server-test.py | 29 ++++++++ 10 files changed, 384 insertions(+), 6 deletions(-) create mode 100644 sca-cpp/trunk/modules/python/client-test.cpp create mode 100644 sca-cpp/trunk/modules/python/client-test.py create mode 100644 sca-cpp/trunk/modules/python/domain-test.composite create mode 100644 sca-cpp/trunk/modules/python/htdocs/index.html create mode 100644 sca-cpp/trunk/modules/python/mod-python.cpp create mode 100644 sca-cpp/trunk/modules/python/mod-python.hpp create mode 100755 sca-cpp/trunk/modules/python/python-conf create mode 100755 sca-cpp/trunk/modules/python/server-test create mode 100644 sca-cpp/trunk/modules/python/server-test.py (limited to 'sca-cpp/trunk/modules/python') diff --git a/sca-cpp/trunk/modules/python/Makefile.am b/sca-cpp/trunk/modules/python/Makefile.am index d61ca5bed3..a9a06c7b12 100644 --- a/sca-cpp/trunk/modules/python/Makefile.am +++ b/sca-cpp/trunk/modules/python/Makefile.am @@ -15,17 +15,31 @@ # specific language governing permissions and limitations # under the License. -noinst_PROGRAMS = python-test python-shell - datadir=$(prefix)/modules/python + +if WANT_PYTHON + +noinst_PROGRAMS = python-test python-shell client-test + +libdir=$(prefix)/lib +lib_LTLIBRARIES = libmod_tuscany_python.la + nobase_data_DATA = *.xsd -INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE} -I${PYTHON_INCLUDE} +INCLUDES = -I${PYTHON_INCLUDE} + +libmod_tuscany_python_la_SOURCES = mod-python.cpp +libmod_tuscany_python_la_LIBADD = -lxml2 -lcurl -lmozjs -L${PYTHON_LIB} -lpython2.6 python_test_SOURCES = python-test.cpp -python_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${PYTHON_LIB} -lpython2.6 +python_test_LDADD = -L${PYTHON_LIB} -lpython2.6 python_shell_SOURCES = python-shell.cpp -python_shell_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${PYTHON_LIB} -lpython2.6 +python_shell_LDADD = -L${PYTHON_LIB} -lpython2.6 + +client_test_SOURCES = client-test.cpp +client_test_LDADD = -lxml2 -lcurl -lmozjs + +TESTS = python-test server-test -TESTS = python-test +endif \ No newline at end of file diff --git a/sca-cpp/trunk/modules/python/client-test.cpp b/sca-cpp/trunk/modules/python/client-test.cpp new file mode 100644 index 0000000000..b070f6a798 --- /dev/null +++ b/sca-cpp/trunk/modules/python/client-test.cpp @@ -0,0 +1,46 @@ +/* + * 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$ */ + +/** + * Test HTTP client functions. + */ + +#include "stream.hpp" +#include "string.hpp" +#include "../server/client-test.hpp" + +namespace tuscany { +namespace server { + +string testURI = "http://localhost:8090/python"; + +} +} + +int main() { + tuscany::cout << "Testing..." << tuscany::endl; + + tuscany::server::testServer(); + + tuscany::cout << "OK" << tuscany::endl; + + return 0; +} diff --git a/sca-cpp/trunk/modules/python/client-test.py b/sca-cpp/trunk/modules/python/client-test.py new file mode 100644 index 0000000000..24b78f83ca --- /dev/null +++ b/sca-cpp/trunk/modules/python/client-test.py @@ -0,0 +1,22 @@ +# JSON-RPC test case + +def echo(x, ref): + return ref("echo", x) + +# ATOMPub test case + +def getall(ref): + return ref("getall") + +def get(id, ref): + return ref("get", id) + +def post(entry, ref): + return ref("post", entry) + +def put(id, entry, ref): + return ref("put", id, entry) + +def delete(id, ref): + return ref("delete", id) + diff --git a/sca-cpp/trunk/modules/python/domain-test.composite b/sca-cpp/trunk/modules/python/domain-test.composite new file mode 100644 index 0000000000..7318f96520 --- /dev/null +++ b/sca-cpp/trunk/modules/python/domain-test.composite @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-cpp/trunk/modules/python/htdocs/index.html b/sca-cpp/trunk/modules/python/htdocs/index.html new file mode 100644 index 0000000000..1bfb3e30c2 --- /dev/null +++ b/sca-cpp/trunk/modules/python/htdocs/index.html @@ -0,0 +1,21 @@ + + +

It works!

+ diff --git a/sca-cpp/trunk/modules/python/mod-python.cpp b/sca-cpp/trunk/modules/python/mod-python.cpp new file mode 100644 index 0000000000..1352c50c11 --- /dev/null +++ b/sca-cpp/trunk/modules/python/mod-python.cpp @@ -0,0 +1,53 @@ +/* + * 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$ */ + +/** + * HTTPD module used to eval Python component implementations. + */ + +#include "string.hpp" +#include "function.hpp" +#include "list.hpp" +#include "value.hpp" +#include "monad.hpp" +#include "../server/mod-cpp.hpp" +#include "../server/mod-eval.hpp" +#include "mod-python.hpp" + +namespace tuscany { +namespace server { +namespace modeval { + +/** + * Return a configured component implementation. + * For now only Scheme and C++ implementations are supported. + */ +const failable&)> > readImplementation(const string& itype, const string& path, const list& px) { + if (contains(itype, ".python")) + return modpython::readImplementation(path, px); + if (contains(itype, ".cpp")) + return modcpp::readImplementation(path, px); + return mkfailure&)> >(string("Unsupported implementation type: ") + itype); +} + +} +} +} diff --git a/sca-cpp/trunk/modules/python/mod-python.hpp b/sca-cpp/trunk/modules/python/mod-python.hpp new file mode 100644 index 0000000000..9f44e1d50c --- /dev/null +++ b/sca-cpp/trunk/modules/python/mod-python.hpp @@ -0,0 +1,80 @@ +/* + * 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_modpython_hpp +#define tuscany_modpython_hpp + +/** + * Evaluation functions used by mod-eval to evaluate implementation.python + * component implementations. + */ + +#include "string.hpp" +#include "stream.hpp" +#include "function.hpp" +#include "list.hpp" +#include "value.hpp" +#include "debug.hpp" +#include "monad.hpp" +#include "eval.hpp" +#include "../http/httpd.hpp" + +namespace tuscany { +namespace server { +namespace modpython { + +/** + * Evaluate a script component implementation function. + */ +struct evalImplementation { + PyObject* impl; + const list px; + evalImplementation(PyObject* impl, const list& px) : impl(impl), px(px) { + } + const value operator()(const list& params) const { + const value expr = append(params, px); + debug(expr, "modeval::python::evalImplementation::input"); + const failable val = python::evalScript(expr, impl); + debug(val, "modeval::python::evalImplementation::result"); + if (!hasContent(val)) + return mklist(value(), reason(val)); + return mklist(content(val)); + } +}; + +/** + * Read a script component implementation. + */ +const failable&)> > readImplementation(const string& path, const list& px) { + ifstream is(path); + if (fail(is)) + return mkfailure&)> >(string("Could not read implementation: ") + path); + const failable impl = python::readScript(path, is); + if (!hasContent(impl)) + return mkfailure&)> >(reason(impl)); + return lambda&)>(evalImplementation(content(impl), px)); +} + +} +} +} + +#endif /* tuscany_modpython_hpp */ diff --git a/sca-cpp/trunk/modules/python/python-conf b/sca-cpp/trunk/modules/python/python-conf new file mode 100755 index 0000000000..856237ed9d --- /dev/null +++ b/sca-cpp/trunk/modules/python/python-conf @@ -0,0 +1,29 @@ +#!/bin/sh + +# 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. + +# Generate a server conf +here=`readlink -f $0`; here=`dirname $here` +root=`readlink -f $1` + +mkdir -p $root +mkdir -p $root/logs +mkdir -p $root/conf +cat >>$root/conf/httpd.conf <>tmp/conf/httpd.conf < +SCAContribution `pwd`/ +SCAComposite domain-test.composite + +EOF + +apachectl -k start -d `pwd`/tmp +sleep 2 + +# Test +./client-test 2>/dev/null +rc=$? + +# Cleanup +apachectl -k stop -d `pwd`/tmp +sleep 2 +return $rc diff --git a/sca-cpp/trunk/modules/python/server-test.py b/sca-cpp/trunk/modules/python/server-test.py new file mode 100644 index 0000000000..cdef94e116 --- /dev/null +++ b/sca-cpp/trunk/modules/python/server-test.py @@ -0,0 +1,29 @@ +# JSON-RPC test case + +def echo(x): + return x + +# ATOMPub test case + +def getall(): + return ("Sample Feed", "123456789", + ("Item", "111", (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 2.99))), + ("Item", "222", (("'javaClass", "services.Item"), ("'name", "Orange"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 3.55))), + ("Item", "333", (("'javaClass", "services.Item"), ("name", "Pear"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 1.55)))) + +def get(id): + entry = (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 2.99)) + return ("Item", id, entry) + +def post(entry): + return "123456789" + +def put(id, entry): + return true + +def deleteall(): + return true + +def delete(id): + return true + -- cgit v1.2.3