 |
Kea
1.5.0
|
Go to the documentation of this file.
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());
void checkFinalized() const
Checks if the finalize was called.
int version()
returns Kea hooks version.
data::ConstElementPtr json_
Pointer to the parsed JSON body.
HttpStatusCode
HTTP status codes (cf RFC 2068)
Encapsulates the boolean value indicating if the HttpResponse constructor should call its setGenericB...
bool set_
A storage for the boolean flag.
static bool isServerError(const HttpStatusCode &status_code)
Checks if the status code indicates server error.
data::ConstElementPtr getJsonElement(const std::string &element_name) const
Retrieves a single JSON element.
void parseBodyAsJson()
Interprets body as JSON, which can be later retrieved using data element objects.
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.
static uint16_t statusCodeToNumber(const HttpStatusCode &status_code)
Convenience method converting status code to numeric value.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Represents HTTP response message.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
HttpResponseJson()
Constructor for the inbound HTTP response.
bool created_
Flag indicating whether create was called.
static std::string statusCodeToString(const HttpStatusCode &status_code)
Converts status code to string.
const HttpResponseContextPtr & context() const
Returns pointer to the HttpResponseContext.
HttpResponseContextPtr context_
Pointer to the HttpResponseContext holding parsed data.
Exception thrown when body of the HTTP message is not JSON.
data::ConstElementPtr getBodyAsJson() const
Retrieves JSON body.
static bool isClientError(const HttpStatusCode &status_code)
Checks if the status code indicates client error.
Notes: IntElement type is changed to int64_t.
bool finalized_
Flag indicating whether finalize was called.
boost::shared_ptr< const Element > ConstElementPtr
virtual void reset()
Reset the state of the object.
virtual void reset()
Reset the state of the object.
virtual void create()
Commits information held in the context into the response.