32 if (generic_body.
set_) {
33 setGenericBody(status_code);
38HttpResponseJson::setGenericBody(
const HttpStatusCode& status_code) {
43 std::map<std::string, ConstElementPtr> map_elements;
44 map_elements[
"result"] =
46 map_elements[
"text"] =
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());
int version()
returns Kea hooks version.
static ElementPtr fromJSON(const std::string &in, bool preproc=false)
These functions will parse the given string (JSON) representation of a compound element.
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Notes: IntElement type is changed to int64_t.
HttpHeaderMap headers_
Parsed HTTP headers.
void checkFinalized() const
Checks if the finalize was called.
bool created_
Flag indicating whether create was called.
bool finalized_
Flag indicating whether finalize was called.
Exception thrown when body of the HTTP message is not JSON.
void setBodyAsJson(const data::ConstElementPtr &json_body)
Generates JSON content from the data structures represented as data::ConstElementPtr.
void parseBodyAsJson()
Interprets body as JSON, which can be later retrieved using data element objects.
data::ConstElementPtr json_
Pointer to the parsed JSON body.
HttpResponseJson()
Constructor for the inbound HTTP response.
virtual void finalize()
Completes creation of the HTTP response.
virtual void reset()
Reset the state of the object.
data::ConstElementPtr getJsonElement(const std::string &element_name) const
Retrieves a single JSON element.
data::ConstElementPtr getBodyAsJson() const
Retrieves JSON body.
Represents HTTP response message.
HttpResponseContextPtr context_
Pointer to the HttpResponseContext holding parsed data.
static uint16_t statusCodeToNumber(const HttpStatusCode &status_code)
Convenience method converting status code to numeric value.
static bool isClientError(const HttpStatusCode &status_code)
Checks if the status code indicates client error.
static bool isServerError(const HttpStatusCode &status_code)
Checks if the status code indicates server error.
const HttpResponseContextPtr & context() const
Returns pointer to the HttpResponseContext.
virtual void reset()
Reset the state of the object.
virtual void create()
Commits information held in the context into the response.
static std::string statusCodeToString(const HttpStatusCode &status_code)
Converts status code to string.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
HttpStatusCode
HTTP status codes (cf RFC 2068)
Defines the logger used by the top-level component of kea-lfc.
Encapsulates the boolean value indicating if the HttpResponse constructor should call its setGenericB...
bool set_
A storage for the boolean flag.