How to get a struct value from xmlrpc_c::clientSimple call result - c++

I have started using XML-RPC for C/C++ (Xmlrpc-c) library on an embedded device, to implement a simple client application.
I need to use xmlrpc_c::clientSimple class to setup a request message as follows:
xmlrpc_c::paramList getParams;
getParams.add("userName");
getParams.add("password");
xmlrpc_c::clientSimple myClient;
xmlrpc_c::value result;
myClient.call("serverUrl", "verifyAccount", tokenGetParams, &result);
I see there are utilities to get int, string (etc.) values from result variable:
xmlrpc_c::value_string(result);
xmlrpc_c::value_int(result);
...
What if I get a more than a variable as result of my RPC call?
For example if the result is made up of an int value and a string, should I convert xmlrpc_c::value to a struct?
What is the best way to do that?

Related

Dump apache thrift messages for debugging purposes?

Apache Thrift is one of the more popular choices for an opensource RPC frameworks (gRPC is also one that gets lot of tracktion since release into the open).
In my setup in c++ Im using a TMultiplexedProcessor. I guess this could be any TProcessor for that matter since Im just interested in printing whatever is sent.
This has a method called:
bool process(std::shared_ptr<protocol::TProtocol> in,
std::shared_ptr<protocol::TProtocol> out,
void* connectionContext) override {
My idea was to override this again, so that I could print the in argument - but how can I write TProtocol to output ? (at a glance, it does not seem straightforward to serialize into a string)
I get a feeling there maybe is some other or an easier method. So my question is how can I dump all messages recieved via thrift (for debugging purpose) ?
There's TProtocolTap and TDebugProtocol.
Usage example can be found in thrift_dump.cpp:
shared_ptr<TProtocol> iprot(new TBinaryProtocol(itrans));
shared_ptr<TProtocol> oprot(
new TDebugProtocol(
shared_ptr<TTransport>(new TBufferedTransport(
shared_ptr<TTransport>(new TFDTransport(STDOUT_FILENO))))));
TProtocolTap tap(iprot, oprot);
std::string name;
TMessageType messageType;
int32_t seqid;
for (;;) {
tap.readMessageBegin(name, messageType, seqid);
tap.skip(T_STRUCT);
tap.readMessageEnd();
}

How to interpret the received data in C++ when using gSoap?

I have implemented a service in C++ using gSoap. I have created it from a multiple existing WSDL files.
And now I need to give a definition to every virtual method of the service.
Let's take a look at one generated method declaration in the file soapMyServiceService.h:
///
/// Service operations (you should define these):
/// Note: compile with -DWITH_PURE_VIRTUAL for pure virtual methods
///
/// Web service operation 'Initialize' (returns error code or SOAP_OK)
virtual int Initialize(_ns5__Initialize *ns5__Initialize, _ns5__InitializeResponse *ns5__InitializeResponse);
Actually, I was expecting to get :
virtial string Initialize(int var_a , int var_b , string var_c);
But now, I need to implement it what I got generated and return the SOAP code :
int MyService::Initialize(_ns5__Initialize *ns5__Initialize, _ns5__InitializeResponse *ns5__InitializeResponse)
{
// HOW can I get here the received values for that I can able to implement my logic?
return SOAP_OK;
}
How can I get the received values ( the values sent by the client for var_a, var_b, and var_c) and then set for him the returned for the string and in the same time return the error code...
How do you normally implement the logic of the services?
Thank you.
In your service method implementation MyService::Initialize(_ns5__Initialize *ns5__Initialize, _ns5__InitializeResponse *ns5__InitializeResponse)
the last argument is the response argument all the rest are input argument, here you have only one input parameter that is of type _ns5__Initialize which probably wud be a structure, if you access its member, you will get all the input parameters of the request.

libxml2 with default sax handler and custom error handler

I would like to use a simple libxml2 parser in a C++ program the following way:
default sax handler is fine (actually I'd like to avoid the effort of writing my own. I understand that I can do what I want with a custom sax handler)
the parser should be embedded in a C++ class that can be instantiated arbitrarily (possibly multi-threaded), the libxml2 parser context as member var
there are other components also using libxml2 but out of my control (I cannot
exactly tell what they do and how they use libxml2)
in the C++ class I want to use a custom error handler that does not just prints to stderr but I want to collect the errors and throw an exception
Example:
class XmlParser
{
public:
XmlDoc * parseText(const char * txt, ...);
private:
xmlParserCtxtPtr ctx;
static void xmlErrorHandler(void * userData, xmlErrorPtr err);
}
Here is what does NOT work (to my testing and understanding):
use xmlSetStructuredErrorFunc() or xmlSetGenericErrorFunc() and set the current C++ instance as user data because these funcs just set a global var (not thread-safe)
use xmlNewParserCtxt() and set ctx->sax->serror to a regular C++ method - error handler must be static
same as previous but with a static class method - actually that does work but at the same time I want to set ctx->user_data (to 'this' of the current C++ instance) - that makes the parser crash, it looks as if inside of libxml2 ctx->user_data is passed through the functions where there should be just ctx ... however that happens consistently, i.e. looks rather like a feature than a bug :-)
Now, has anybody an idea how to get this to work?
Many thx!!!

Can I serialize/deserialize JSON from protocol buffers with C++?

There are frameworks for Java and other languages that help connect protocol buffers to JSON, but I have not seen a native solution in C++.
Is there a library/framework that I can use to connect C++ protocol buffer objects to JSON?
I'm developing one. I'm using the protobuf's reflection mechanism to parse any generated protobuf. Here http://corbasim.googlecode.com/svn/trunk/protobuf2json_exported.zip you can find an initial implementation of this idea. It currently just parse string fields, but I want to support any type as soon as possible.
For a message Foo:
message Foo {
optional string text = 1;
}
it can parse instances of Foo by this way:
Foo foo;
const std::string json_foo = "{\"text\": \"Hello world\"}";
protobuf2json::json::parse(foo, json_foo)
By the same way, I want to write a JSON serializer from protobuf generated types.
There is a similar question here:
C++ Protobuf to/from JSON conversion
pb2json is another library that can be used.

Passing an arraylist as a struct property from a webservice

I have a web service that sends a struct to a client program.
I need to pass an arraylist of string values as one of the properties of this struct, but by the time it gets to the client program its type is 'object'. Once it gets back to the client program, how can I convert this Object datatype back into the arraylist?
Unless you're stuck at .NET 1.1, don't use ArrayList. Try returning a List<YourStruct> instead.
The problem was the way I was attempting to explicitly create an arraylist and then setting it equal to the returned property from the struct; here's the correct way to do it - some weird VB implicit thingy. (sorry, never drank the VB kool-aid)
Dim ReturnedArrList As New ArrayList(structReturned.arrReturnedArrayList)