From bb4b895471e3165c71bdfd1fdae5e1ffde8f1696 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sun, 7 Feb 2010 00:36:25 +0000 Subject: Moved server configuration to HTTPD postConfig phase, to avoid running configuration commands twice and added a way for runtime modules and components to handle start/restart/stop events. Improved build scripts a little, to not depend on external environment variables. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@907352 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/components/cache/mcache.cpp | 2 +- sca-cpp/trunk/components/cache/server-test | 7 +-- sca-cpp/trunk/components/chat/chat-listener.cpp | 8 +-- sca-cpp/trunk/components/chat/chat-sender.cpp | 2 +- sca-cpp/trunk/components/queue/Makefile.am | 14 +++++ sca-cpp/trunk/components/queue/client-test.cpp | 71 ++++++++++++++++++++++ sca-cpp/trunk/components/queue/qpid-test.cpp | 64 +++++++++++++++++++ sca-cpp/trunk/components/queue/queue-listener.cpp | 8 +-- sca-cpp/trunk/components/queue/queue-sender.cpp | 2 +- sca-cpp/trunk/components/webservice/Makefile.am | 4 ++ sca-cpp/trunk/components/webservice/axis2-conf | 8 ++- sca-cpp/trunk/components/webservice/axis2.hpp | 13 ++-- sca-cpp/trunk/components/webservice/echo-test | 6 +- sca-cpp/trunk/components/webservice/server-test | 15 +++-- .../components/webservice/webservice-client.cpp | 5 +- .../components/webservice/webservice-listener.cpp | 2 +- 16 files changed, 191 insertions(+), 40 deletions(-) create mode 100644 sca-cpp/trunk/components/queue/client-test.cpp create mode 100644 sca-cpp/trunk/components/queue/qpid-test.cpp (limited to 'sca-cpp/trunk/components') diff --git a/sca-cpp/trunk/components/cache/mcache.cpp b/sca-cpp/trunk/components/cache/mcache.cpp index 46f707ee19..b1dc750ccb 100644 --- a/sca-cpp/trunk/components/cache/mcache.cpp +++ b/sca-cpp/trunk/components/cache/mcache.cpp @@ -99,7 +99,7 @@ const tuscany::value apply(const tuscany::list& params) { return tuscany::cache::put(cdr(params)); if (func == "delete") return tuscany::cache::del(cdr(params)); - return tuscany::mkfailure(tuscany::string("Function not supported: ") + func); + return tuscany::mkfailure(); } } diff --git a/sca-cpp/trunk/components/cache/server-test b/sca-cpp/trunk/components/cache/server-test index a30d14b1b6..821724295d 100755 --- a/sca-cpp/trunk/components/cache/server-test +++ b/sca-cpp/trunk/components/cache/server-test @@ -22,14 +22,11 @@ ../../modules/server/server-conf tmp ../../modules/server/scheme-conf tmp cat >>tmp/conf/httpd.conf < SCAContribution `pwd`/ SCAComposite mcache.composite - EOF -apachectl -k start -d `pwd`/tmp +../../modules/http/httpd-start tmp mc="memcached -l 127.0.0.1 -m 4 -p 11211" $mc & @@ -41,6 +38,6 @@ rc=$? # Cleanup kill `ps -f | grep -v grep | grep "$mc" | awk '{ print $2 }'` -apachectl -k stop -d `pwd`/tmp +../../modules/http/httpd-stop tmp sleep 2 return $rc diff --git a/sca-cpp/trunk/components/chat/chat-listener.cpp b/sca-cpp/trunk/components/chat/chat-listener.cpp index 57642036a6..884965839a 100644 --- a/sca-cpp/trunk/components/chat/chat-listener.cpp +++ b/sca-cpp/trunk/components/chat/chat-listener.cpp @@ -36,7 +36,7 @@ namespace chat { /** * Initialize the component. */ -const failable init(unused const list& params) { +const failable start(unused const list& params) { //TODO establish a session with an XMPP server for a JID and mark the current server instance busy return value(true); @@ -49,9 +49,9 @@ extern "C" { const tuscany::value apply(const tuscany::list& params) { const tuscany::value func(car(params)); - if (func == "init") - return tuscany::chat::init(cdr(params)); - return tuscany::mkfailure(tuscany::string("Function not supported: ") + func); + if (func == "start") + return tuscany::chat::start(cdr(params)); + return tuscany::mkfailure(); } } diff --git a/sca-cpp/trunk/components/chat/chat-sender.cpp b/sca-cpp/trunk/components/chat/chat-sender.cpp index dfcae6796a..bd67bf7315 100644 --- a/sca-cpp/trunk/components/chat/chat-sender.cpp +++ b/sca-cpp/trunk/components/chat/chat-sender.cpp @@ -52,7 +52,7 @@ const tuscany::value apply(const tuscany::list& params) { const tuscany::value func(car(params)); if (func == "post") return tuscany::chat::post(cdr(params)); - return tuscany::mkfailure(tuscany::string("Function not supported: ") + func); + return tuscany::mkfailure(); } } diff --git a/sca-cpp/trunk/components/queue/Makefile.am b/sca-cpp/trunk/components/queue/Makefile.am index cee3ce7820..6bbdc119b4 100644 --- a/sca-cpp/trunk/components/queue/Makefile.am +++ b/sca-cpp/trunk/components/queue/Makefile.am @@ -17,10 +17,13 @@ if WANT_QUEUE +noinst_PROGRAMS = qpid-test client-test + INCLUDES = -I${QPIDC_INCLUDE} compdir=$(prefix)/components/queue comp_LTLIBRARIES = libqueue-sender.la libqueue-listener.la +comp_DATA = qpidc.prefix libqueue_sender_la_SOURCES = queue-sender.cpp libqueue_sender_la_LDFLAGS = -L${QPIDC_LIB} -R${QPIDC_LIB} -lqpidclient @@ -28,4 +31,15 @@ libqueue_sender_la_LDFLAGS = -L${QPIDC_LIB} -R${QPIDC_LIB} -lqpidclient libqueue_listener_la_SOURCES = queue-listener.cpp libqueue_listener_la_LDFLAGS = -L${QPIDC_LIB} -R${QPIDC_LIB} -lqpidclient +qpid_test_SOURCES = qpid-test.cpp +qpid_test_LDFLAGS = -L${QPIDC_LIB} -R${QPIDC_LIB} -lqpidclient + +client_test_SOURCES = client-test.cpp +client_test_LDFLAGS = -lxml2 -lcurl -lmozjs + +qpidc.prefix: $(top_builddir)/config.status + echo ${QPIDC_PREFIX} >qpidc.prefix + +#TESTS = qpid-test server-test + endif diff --git a/sca-cpp/trunk/components/queue/client-test.cpp b/sca-cpp/trunk/components/queue/client-test.cpp new file mode 100644 index 0000000000..121a739e0d --- /dev/null +++ b/sca-cpp/trunk/components/queue/client-test.cpp @@ -0,0 +1,71 @@ +/* + * 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 queue component. + */ + +#include +#include "stream.hpp" +#include "string.hpp" +#include "list.hpp" +#include "element.hpp" +#include "value.hpp" +#include "monad.hpp" +#include "perf.hpp" +#include "../../modules/http/curl.hpp" + +namespace tuscany { +namespace queue { + + +bool testPost() { + http::CURLSession cs; + + const value func = "http://ws.apache.org/axis2/c/samples/echoString"; + const list arg = mklist( + list() + "ns1:echoString" + + (list() + "@xmlns:ns1" + string("http://ws.apache.org/axis2/services/echo")) + + (list() + "text" + string("Hello World!"))); + + const failable rval = http::evalExpr(mklist(func, arg), "http://localhost:8090/echo-client", cs); + assert(hasContent(rval)); + + const list r = mklist( + list() + "ns1:echoString" + + (list() + "@xmlns:ns1" + string("http://ws.apache.org/axis2/c/samples")) + + (list() + "text" + string("Hello World!"))); + assert(content(rval) == r); + return true; +} + +} +} + +int main() { + tuscany::cout << "Testing..." << tuscany::endl; + + tuscany::queue::testPost(); + + tuscany::cout << "OK" << tuscany::endl; + + return 0; +} diff --git a/sca-cpp/trunk/components/queue/qpid-test.cpp b/sca-cpp/trunk/components/queue/qpid-test.cpp new file mode 100644 index 0000000000..97d8d2f5d5 --- /dev/null +++ b/sca-cpp/trunk/components/queue/qpid-test.cpp @@ -0,0 +1,64 @@ +/* + * 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 Qpid support functions. + */ + +#include +#include "stream.hpp" +#include "string.hpp" +#include "list.hpp" +#include "element.hpp" +#include "monad.hpp" +#include "value.hpp" +#include "perf.hpp" +#include "qpid.hpp" + +namespace tuscany { +namespace queue { + +bool testPost() { + QpidConnection qc; + + QpidSession qs(qc); + + // Post the item + const list params; + const value key = ((lambda)>)cadr(params))(list()); + post(key, car(params), qs); + + return value(true); + return true; +} + +} +} + +int main() { + tuscany::cout << "Testing..." << tuscany::endl; + + tuscany::queue::testPost(); + + tuscany::cout << "OK" << tuscany::endl; + + return 0; +} diff --git a/sca-cpp/trunk/components/queue/queue-listener.cpp b/sca-cpp/trunk/components/queue/queue-listener.cpp index 6f1c54873c..75c53e7b41 100644 --- a/sca-cpp/trunk/components/queue/queue-listener.cpp +++ b/sca-cpp/trunk/components/queue/queue-listener.cpp @@ -44,7 +44,7 @@ QpidConnection qc; /** * Initialize the component. */ -const failable init(const list& params) { +const failable start(const list& params) { QpidSession qs(qc); // Declare the configured AMQP key / queue pair @@ -64,9 +64,9 @@ extern "C" { const tuscany::value apply(const tuscany::list& params) { const tuscany::value func(car(params)); - if (func == "init") - return tuscany::queue::init(cdr(params)); - return tuscany::mkfailure(tuscany::string("Function not supported: ") + func); + if (func == "start") + return tuscany::queue::start(cdr(params)); + return tuscany::mkfailure(); } } diff --git a/sca-cpp/trunk/components/queue/queue-sender.cpp b/sca-cpp/trunk/components/queue/queue-sender.cpp index fbbbd0376b..15128411c2 100644 --- a/sca-cpp/trunk/components/queue/queue-sender.cpp +++ b/sca-cpp/trunk/components/queue/queue-sender.cpp @@ -63,7 +63,7 @@ const tuscany::value apply(const tuscany::list& params) { const tuscany::value func(car(params)); if (func == "post") return tuscany::queue::post(cdr(params)); - return tuscany::mkfailure(tuscany::string("Function not supported: ") + func); + return tuscany::mkfailure(); } } diff --git a/sca-cpp/trunk/components/webservice/Makefile.am b/sca-cpp/trunk/components/webservice/Makefile.am index b12518076b..264b150c93 100644 --- a/sca-cpp/trunk/components/webservice/Makefile.am +++ b/sca-cpp/trunk/components/webservice/Makefile.am @@ -23,6 +23,7 @@ INCLUDES = -I${AXIS2C_INCLUDE} compdir=$(prefix)/components/webservice comp_LTLIBRARIES = libwebservice-client.la libwebservice-listener.la libaxis2-dispatcher.la libaxis2-service.la +comp_DATA = axis2c.prefix libwebservice_client_la_SOURCES = webservice-client.cpp libwebservice_client_la_LDFLAGS = -lxml2 -L${AXIS2C_LIB} -R${AXIS2C_LIB} -laxis2_engine @@ -45,6 +46,9 @@ axis2_test_LDFLAGS = -lxml2 -L${AXIS2C_LIB} -R${AXIS2C_LIB} -laxis2_engine client_test_SOURCES = client-test.cpp client_test_LDFLAGS = -lxml2 -lcurl -lmozjs -L${AXIS2C_LIB} -R${AXIS2C_LIB} -laxis2_engine +axis2c.prefix: $(top_builddir)/config.status + echo ${AXIS2C_PREFIX} >axis2c.prefix + TESTS = axiom-test echo-test server-test endif diff --git a/sca-cpp/trunk/components/webservice/axis2-conf b/sca-cpp/trunk/components/webservice/axis2-conf index 28f8a0be94..2e1f6116cd 100755 --- a/sca-cpp/trunk/components/webservice/axis2-conf +++ b/sca-cpp/trunk/components/webservice/axis2-conf @@ -20,14 +20,15 @@ # Generate an Axis2 server conf here=`readlink -f $0`; here=`dirname $here` root=`readlink -f $1` +axis2_prefix=`cat axis2c.prefix` # Create an Axis2 home directory mkdir -p $root/axis2c -ln -f -s $AXIS2C_HOME/lib $root/axis2c/lib +ln -f -s $axis2_prefix/lib $root/axis2c/lib mkdir -p $root/axis2c/logs mkdir -p $root/axis2c/modules -ln -f -s $AXIS2C_HOME/modules/addressing $root/axis2c/modules/addressing -ln -f -s $AXIS2C_HOME/modules/logging $root/axis2c/modules/logging +ln -f -s $axis2_prefix/modules/addressing $root/axis2c/modules/addressing +ln -f -s $axis2_prefix/modules/logging $root/axis2c/modules/logging mkdir -p $root/axis2c/services # Install Tuscany Axis2 module and service @@ -41,6 +42,7 @@ cp $here/axis2.xml $root/axis2c/axis2.xml # Configure HTTPD Axis2 module cat >>$root/conf/httpd.conf < > axiomNodeToValues(axiom_node_t* node, const A * Evaluate an expression in the form (soap-action-string, document, uri). Send the * SOAP action and document to the Web Service at the given URI using Axis2. */ -const char* axis2Home = getenv("AXIS2C_HOME"); - const failable evalExpr(const value& expr, const Axis2Context& ax) { debug(expr, "webservice::evalExpr::input"); @@ -155,16 +153,13 @@ const failable evalExpr(const value& expr, const Axis2Context& ax) { const value uri(caddr(expr)); // Create Axis2 client + axis2_svc_client_t *client = axis2_svc_client_create(env(ax), getenv("AXIS2C_HOME")); + if (client == NULL) + return mkfailure("Couldn't create Axis2 client: " + axis2Error(ax)); axis2_endpoint_ref_t *epr = axis2_endpoint_ref_create(env(ax), c_str(uri)); axis2_options_t *opt = axis2_options_create(env(ax)); axis2_options_set_to(opt, env(ax), epr); axis2_options_set_action(opt, env(ax), (const axis2_char_t*)c_str(func)); - axis2_svc_client_t *client = axis2_svc_client_create(env(ax), axis2Home); - if (client == NULL) { - axis2_endpoint_ref_free(epr, env(ax)); - axis2_options_free(opt, env(ax)); - return mkfailure("Couldn't create Axis2 client: " + axis2Error(ax)); - } axis2_svc_client_set_options(client, env(ax), opt); axis2_svc_client_engage_module(client, env(ax), AXIS2_MODULE_ADDRESSING); diff --git a/sca-cpp/trunk/components/webservice/echo-test b/sca-cpp/trunk/components/webservice/echo-test index b999b1aede..5e7a380521 100755 --- a/sca-cpp/trunk/components/webservice/echo-test +++ b/sca-cpp/trunk/components/webservice/echo-test @@ -18,9 +18,11 @@ # under the License. # Setup -axis2="$AXIS2C_HOME/bin/axis2_http_server" +axis2_prefix=`cat axis2c.prefix` +export AXIS2C_HOME=$axis2_prefix +axis2="$axis2_prefix/bin/axis2_http_server" pwd=`pwd` -cd $AXIS2C_HOME/bin +cd "$axis2_prefix/bin" $axis2 & cd $pwd sleep 1 diff --git a/sca-cpp/trunk/components/webservice/server-test b/sca-cpp/trunk/components/webservice/server-test index eb3d53a33a..7d33223b3d 100755 --- a/sca-cpp/trunk/components/webservice/server-test +++ b/sca-cpp/trunk/components/webservice/server-test @@ -23,18 +23,17 @@ ../../modules/server/scheme-conf tmp ./axis2-conf tmp cat >>tmp/conf/httpd.conf < SCAContribution `pwd`/ SCAComposite webservice.composite - EOF -apachectl -k start -d `pwd`/tmp +../../modules/http/httpd-start tmp -axis2="$AXIS2C_HOME/bin/axis2_http_server" +axis2_prefix=`cat axis2c.prefix` +export AXIS2C_HOME=$axis2_prefix +axis2="$axis2_prefix/bin/axis2_http_server" pwd=`pwd` -cd $AXIS2C_HOME/bin +cd "$axis2_prefix/bin" $axis2 & cd $pwd sleep 2 @@ -44,7 +43,7 @@ sleep 2 rc=$? # Cleanup -kill `ps -f | grep -v grep | grep "$axis2" | awk '{ print $2 }'` -apachectl -k stop -d `pwd`/tmp +kill `ps -f | grep -v grep | grep "${axis2}" | awk '{ print $2 }'` +../../modules/http/httpd-stop tmp sleep 2 return $rc diff --git a/sca-cpp/trunk/components/webservice/webservice-client.cpp b/sca-cpp/trunk/components/webservice/webservice-client.cpp index cc3a15c734..ae4e472e65 100644 --- a/sca-cpp/trunk/components/webservice/webservice-client.cpp +++ b/sca-cpp/trunk/components/webservice/webservice-client.cpp @@ -56,7 +56,10 @@ const failable apply(const value& func, const list& params) { extern "C" { const tuscany::value apply(const tuscany::list& params) { - return tuscany::webservice::apply(car(params), cdr(params)); + const tuscany::value func(car(params)); + if (func == "start" || func == "stop" || func == "restart") + return tuscany::mkfailure(); + return tuscany::webservice::apply(func, cdr(params)); } } diff --git a/sca-cpp/trunk/components/webservice/webservice-listener.cpp b/sca-cpp/trunk/components/webservice/webservice-listener.cpp index 7198a00749..2127ecf0df 100644 --- a/sca-cpp/trunk/components/webservice/webservice-listener.cpp +++ b/sca-cpp/trunk/components/webservice/webservice-listener.cpp @@ -80,7 +80,7 @@ const tuscany::value apply(const tuscany::list& params) { const tuscany::value func(car(params)); if (func == "handle") return tuscany::webservice::handle(cdr(params)); - return tuscany::mkfailure(tuscany::string("Function not supported: ") + func); + return tuscany::mkfailure(); } } -- cgit v1.2.3