17 HttpResponseJson::HttpResponseJson()
32 if (generic_body.
set_) {
33 setGenericBody(status_code);
38 HttpResponseJson::setGenericBody(
const HttpStatusCode& status_code) {
43 std::map<std::string, ConstElementPtr> map_elements;
44 map_elements[
"result"] =
46 map_elements[
"text"] =
48 auto body = Element::createMap();
49 body->setValue(map_elements);
80 context()->body_ = json_body->str();
94 const std::map<std::string, ConstElementPtr>& map_value = body->mapValue();
95 auto map_element = map_value.find(element_name);
96 if (map_element != map_value.end()) {
97 return (map_element->second);
101 }
catch (
const std::exception& ex) {
103 << element_name <<
": " << ex.
what());
115 }
catch (
const std::exception& ex) {
117 " response: " << ex.
what());
static bool isClientError(const HttpStatusCode &status_code)
Checks if the status code indicates client error.
bool finalized_
Flag indicating whether finalize was called.
data::ConstElementPtr getJsonElement(const std::string &element_name) const
Retrieves a single JSON element.
data::ConstElementPtr getBodyAsJson() const
Retrieves JSON body.
data::ConstElementPtr json_
Pointer to the parsed JSON body.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
virtual void create()
Commits information held in the context into the response.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
bool created_
Flag indicating whether create was called.
HttpResponseContextPtr context_
Pointer to the HttpResponseContext holding parsed data.
Represents HTTP response message.
Notes: IntElement type is changed to int64_t.
boost::shared_ptr< const Element > ConstElementPtr
int version()
returns Kea hooks version.
static bool isServerError(const HttpStatusCode &status_code)
Checks if the status code indicates server error.
void checkFinalized() const
Checks if the finalize was called.
const HttpResponseContextPtr & context() const
Returns pointer to the HttpResponseContext.
static std::string statusCodeToString(const HttpStatusCode &status_code)
Converts status code to string.
Defines the logger used by the top-level component of kea-lfc.
virtual void reset()
Reset the state of the object.
void parseBodyAsJson()
Interprets body as JSON, which can be later retrieved using data element objects. ...
static uint16_t statusCodeToNumber(const HttpStatusCode &status_code)
Convenience method converting status code to numeric value.
Exception thrown when body of the HTTP message is not JSON.
virtual void finalize()
Completes creation of the HTTP response.
void setBodyAsJson(const data::ConstElementPtr &json_body)
Generates JSON content from the data structures represented as data::ConstElementPtr.
bool set_
A storage for the boolean flag.
Encapsulates the boolean value indicating if the HttpResponse constructor should call its setGenericB...
HttpStatusCode
HTTP status codes (cf RFC 2068)
HttpResponseJson()
Constructor for the inbound HTTP response.
virtual void reset()
Reset the state of the object.