HttpClient Class Reference

#include <Pt/JsonRpc/HttpClient.h>

A client for JSON-RPC 2.0 remote procedure calls via HTTP.

Inherits Client, and Connectable.

Public Member Functions

 HttpClient ()
 Constructor.
 
 HttpClient (const Net::Endpoint &ep, const std::string &url)
 Construct with host and service URL.
 
 HttpClient (System::EventLoop &loop)
 Construct with EventLoop used for I/O.
 
 HttpClient (System::EventLoop &loop, const Net::Endpoint &ep, const std::string &url)
 Construct with host and service URL.
 
virtual ~HttpClient ()
 Destructor.
 
void setActive (System::EventLoop &loop)
 Sets the EventLoop to use for I/O.
 
System::EventLooploop () const
 Gets the used EventLoop.
 
void setSecure (Ssl::Context &ctx)
 Sets SSL context.
 
void setPeerName (const std::string &peer)
 Set expected SSL peer name.
 
void setKeepAlive ()
 Enables HTTP keep-alive.
 
void setTimeout (std::size_t timeout)
 Sets timeout for I/O operations.
 
void setTarget (const Net::Endpoint &ep, const std::string &url)
 Sets target host and service URL.
 
void setTarget (const Net::Endpoint &ep, const Net::TcpSocketOptions &opts, const std::string &url)
 Sets target host and service URL.
 
void setHost (const Net::Endpoint &ep)
 Sets host to connect.
 
void setHost (const Net::Endpoint &ep, const Net::TcpSocketOptions &opts)
 Sets host to connect.
 
void setServiceUrl (const std::string &url)
 Sets the service URL.
 
void setServiceUrl (const char *url)
 Sets the service URL.
 
const Net::Endpointhost () const
 Returns target host.
 
void close ()
 Closes the connection.
 
void setProcedure (const ProcedureDeclaration *decl)
 Set procedure declaration for named parameters. More...
 
const RemoteCall * activeProcedure () const
 The currently executing procedure.
 
void cancel ()
 Cancels the currently executing procedure.
 

Protected Member Functions

virtual bool isFailed () const
 Indicates if the procedure has failed.
 
virtual void onBeginInvoke ()
 Begin an asynchronous invocation. More...
 
virtual void onInvoke ()
 Perform a synchronous invocation. More...
 
virtual void onEndInvoke ()
 End an asynchronous invocation.
 
virtual void onCancel ()
 Cancels the remote procedure call. More...
 
void beginMessage (std::ostream &os)
 Begin formatting a JSON-RPC request to a stream.
 
bool advanceMessage ()
 Continue formatting the request. More...
 
void finishMessage ()
 Finish formatting the request.
 
void beginResult (std::istream &is)
 Begin parsing a JSON-RPC response from a stream.
 
bool parseResult ()
 Parse available response data. More...
 
void processResult (std::istream &is)
 Parse the entire response synchronously.
 
void setFault (int rc, const char *msg)
 Mark the current procedure as failed.
 
void setReady ()
 Parses the XML-RPC result. More...
 

Member Function Documentation

◆ onBeginInvoke()

virtual void onBeginInvoke ( )
protectedvirtual

Derived Clients implement this to send the formatted request.

Implements Client.

◆ onInvoke()

virtual void onInvoke ( )
protectedvirtual

Derived Clients implement this to send the request and receive the response.

Implements Client.

◆ onCancel()

virtual void onCancel ( )
protectedvirtual

Derived Clients implement this method to cancel the remote procedure call.

Reimplemented from Client.

◆ setProcedure()

void setProcedure ( const ProcedureDeclaration decl)
inherited

If set, parameters will be sent as a JSON object with named keys. If not set, parameters are sent as a JSON array.

◆ advanceMessage()

bool advanceMessage ( )
protectedinherited
Returns
true if all parameters are formatted.

◆ parseResult()

bool parseResult ( )
protectedinherited
Returns
true if parsing is complete.

◆ setReady()

void setReady ( )
protectedinherited

This method is used by derived Clients after the XML-RPC result has been parsed by parseResult(). The current RemoteProcedure will receive completion notification to process the result.