Kea: response_json.h Source File

| Kea 2.2.0

response_json.h
Go to the documentation of this file.
1// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef HTTP_RESPONSE_JSON_H
8#define HTTP_RESPONSE_JSON_H
9
10#include <cc/data.h>
11#include <exceptions/exceptions.h>
12#include <http/response.h>
13
14namespace isc {
15namespace http {
16
18 class HttpResponseJsonError : public HttpResponseError {
19public:
20 HttpResponseJsonError(const char* file, size_t line, const char* what) :
21 HttpResponseError(file, line, what) { };
22};
23
24class HttpResponseJson;
25
27 typedef boost::shared_ptr<HttpResponseJson> HttpResponseJsonPtr;
28
34 class HttpResponseJson : public HttpResponse {
35public:
36
38 explicit HttpResponseJson();
39
49 explicit HttpResponseJson(const HttpVersion& version,
50 const HttpStatusCode& status_code,
51 const CallSetGenericBody& generic_body =
52 CallSetGenericBody::yes());
53
60 virtual void finalize();
61
63 virtual void reset();
64
69 data::ConstElementPtr getBodyAsJson() const;
70
75 void setBodyAsJson(const data::ConstElementPtr& json_body);
76
86 data::ConstElementPtr getJsonElement(const std::string& element_name) const;
87
88private:
89
99 void setGenericBody(const HttpStatusCode& status_code);
100
101protected:
102
105 void parseBodyAsJson();
106
108 data::ConstElementPtr json_;
109};
110
111} // end of namespace isc::http
112} // end of namespace isc
113
114#endif
version
int version()
returns Kea hooks version.
Definition: bootp/version.cc:13
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::http::HttpResponseError
Generic exception thrown by HttpResponse class.
Definition: response.h:23
isc::http::HttpResponseJsonError
Exception thrown when body of the HTTP message is not JSON.
Definition: response_json.h:18
isc::http::HttpResponseJsonError::HttpResponseJsonError
HttpResponseJsonError(const char *file, size_t line, const char *what)
Definition: response_json.h:20
isc::http::HttpResponseJson
Represents HTTP response with JSON content.
Definition: response_json.h:34
isc::http::HttpResponseJson::setBodyAsJson
void setBodyAsJson(const data::ConstElementPtr &json_body)
Generates JSON content from the data structures represented as data::ConstElementPtr.
Definition: response_json.cc:78
isc::http::HttpResponseJson::parseBodyAsJson
void parseBodyAsJson()
Interprets body as JSON, which can be later retrieved using data element objects.
Definition: response_json.cc:109
isc::http::HttpResponseJson::json_
data::ConstElementPtr json_
Pointer to the parsed JSON body.
Definition: response_json.h:108
isc::http::HttpResponseJson::HttpResponseJson
HttpResponseJson()
Constructor for the inbound HTTP response.
Definition: response_json.cc:17
isc::http::HttpResponseJson::finalize
virtual void finalize()
Completes creation of the HTTP response.
Definition: response_json.cc:55
isc::http::HttpResponseJson::reset
virtual void reset()
Reset the state of the object.
Definition: response_json.cc:66
isc::http::HttpResponseJson::getJsonElement
data::ConstElementPtr getJsonElement(const std::string &element_name) const
Retrieves a single JSON element.
Definition: response_json.cc:90
isc::http::HttpResponseJson::getBodyAsJson
data::ConstElementPtr getBodyAsJson() const
Retrieves JSON body.
Definition: response_json.cc:72
isc::http::HttpResponse
Represents HTTP response message.
Definition: response.h:98
data.h
exceptions.h
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
isc::http::HttpStatusCode
HttpStatusCode
HTTP status codes (cf RFC 2068)
Definition: response.h:30
isc::http::HttpResponseJsonPtr
boost::shared_ptr< HttpResponseJson > HttpResponseJsonPtr
Pointer to the HttpResponseJson object.
Definition: response_json.h:24
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143
response.h
isc::http::CallSetGenericBody
Encapsulates the boolean value indicating if the HttpResponse constructor should call its setGenericB...
Definition: response.h:52
isc::http::CallSetGenericBody::yes
static const CallSetGenericBody & yes()
Returns encapsulated true.
Definition: response.h:63
isc::http::HttpVersion
HTTP protocol version.
Definition: http_types.h:14