libtasks Documentation  1.6
thrift_client/thrift_http_client.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ADTECH GmbH
3  * Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4  *
5  * Author: Andreas Pohl
6  */
7 
8 #include <iostream>
9 #include <arpa/inet.h>
10 #include <thrift/protocol/TBinaryProtocol.h>
11 #include <thrift/transport/THttpClient.h>
12 #include <boost/shared_ptr.hpp>
13 #include "test_service.h"
14 
15 int main(int argc, char** argv) {
16  using namespace apache::thrift::protocol;
17  using namespace apache::thrift::transport;
18  boost::shared_ptr<THttpClient> transport(new THttpClient("localhost", 8080, "/test?id=42"));
19  boost::shared_ptr<TBinaryProtocol> protocol(new TBinaryProtocol(transport));
20  test_serviceClient client(protocol);
21 
22  try {
23  transport->open();
24 
25  std::cout << "Sending request" << std::endl;
26  id_name m;
27  client.lookup(m);
28  std::cout << "lookup(id=" << m.id << ", name=" << m.name << ")" << std::endl;
29 
30  transport->close();
31  } catch (TTransportException& e) {
32  std::cerr << e.what() << std::endl;
33  }
34 
35  return 0;
36 }
int main(int argc, char **argv)