source: sources/src/rpcXmlServer.cc @ 1464:3f6711617be1

Revision 1464:3f6711617be1, 3.6 KB checked in by niam, 22 months ago (diff)

{issue #58[resolved]} support for non-c++ exceptions

Line 
1/***************************************************************************
2 *            rpcXmlServer.cc
3 *
4 *  Wed Apr 09 2008
5 *  Copyright  2008  Dmytro Milinevskyy
6 *  milinevskyy@gmail.com
7 ****************************************************************************/
8
9/*
10 *  This program is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU Lesser General Public License version 2.1 as published by
12 *  the Free Software Foundation;
13 *
14 *  This program is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU Library General Public License for more details.
18 *
19 *  You should have received a copy of the GNU Lesser General Public License
20 *  along with this program; if not, write to the Free Software
21 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24/**
25 * vim indentation settings
26 * set tabstop=4
27 * set shiftwidth=4
28 */
29
30#include <libdodo/directives.h>
31
32#include <libdodo/rpcXmlServer.h>
33#include <libdodo/types.h>
34#include <libdodo/ioChannel.h>
35#include <libdodo/rpcServer.h>
36#include <libdodo/rpcXmlMethod.h>
37#include <libdodo/rpcMethod.h>
38#include <libdodo/rpcXmlResponse.h>
39#include <libdodo/rpcResponse.h>
40#include <libdodo/dataFormatXmlProcessor.h>
41#include <libdodo/dataFormatXmlNode.h>
42#include <libdodo/exceptionBasic.h>
43
44using namespace dodo::rpc::xml;
45
46__additional__::__additional__(dodo::string &encoding) : encoding(encoding)
47{
48}
49
50//-------------------------------------------------------------------
51
52server::server(io::channel &io) : rpc::server(io),
53                                  rpEncoding("UTF-8")
54{
55}
56
57//-------------------------------------------------------------------
58
59server::~server()
60{
61}
62
63//-------------------------------------------------------------------
64
65void
66server::setResponseEncoding(const dodo::string &a_encoding)
67{
68    rpEncoding = a_encoding;
69}
70
71//-------------------------------------------------------------------
72
73dodo::rpc::method
74server::processCallRequest()
75{
76    dodo::data::format::xml::processor xmlValue;
77
78    dodo::data::format::xml::__definition__ xmlMethodCall;
79    xmlMethodCall.name = "methodCall";
80    xmlMethodCall.allChildren = true;
81
82    dodo::data::format::xml::node node = xmlValue.process(xmlMethodCall, io);
83
84    rqEncoding = xmlValue.information().encoding;
85
86    return method::xmlToMethod(node);
87}
88
89//-------------------------------------------------------------------
90
91void
92server::processCallResult(const rpc::response &resp)
93{
94    dodo::data::format::xml::processor xmlValue;
95
96    xmlValue.make(response::responseToXml(resp), rpEncoding, "1.0", io);
97
98    io.flush();
99}
100
101//-------------------------------------------------------------------
102
103void
104server::serve()
105{
106    dodo_try {
107        rpc::method meth = processCallRequest();
108
109        dodo::string encoding = rpEncoding;
110
111        __additional__ idata(rqEncoding);
112
113        __additional__ odata(rpEncoding);
114
115        dodoMap<dodo::string, handler, dodoMapStringCompare>::iterator handler = handlers.find(meth.name);
116
117        if (handler == handlers.end())
118            processCallResult(defaultHandler(meth.name, meth.arguments, &idata, &odata));
119        else
120            processCallResult(handler->second(meth.name, meth.arguments, &idata, &odata));
121
122        rpEncoding = encoding;
123    } dodo_catch (exception::basic *e UNUSED) {
124        rpc::response response;
125        response.fault(e->errStr);
126
127        processCallResult(response);
128    }
129}
130
131//-------------------------------------------------------------------
132
Note: See TracBrowser for help on using the repository browser.