2 #include <THttpCallArg.h>
3 #include "NCloudEvent.h"
12 : TObject(), fId(id), fSource(source), fSpecVersion(specVersion), fType(type)
24 if (!arg->GetRequestHeader(
"Content-Type").CompareTo(
"application/json")) {
25 fId = arg->GetRequestHeader(
"Ce-Id").Data();
26 fSource = arg->GetRequestHeader(
"Ce-Source").Data();
27 fSpecVersion = arg->GetRequestHeader(
"Ce-Specversion").Data();
28 fType = arg->GetRequestHeader(
"Ce-Type").Data();
30 else if (!arg->GetRequestHeader(
"content-type").CompareTo(
"application/json")) {
31 fId = arg->GetRequestHeader(
"ce-id").Data();
32 fSource = arg->GetRequestHeader(
"ce-source").Data();
33 fSpecVersion = arg->GetRequestHeader(
"ce-specversion").Data();
34 fType = arg->GetRequestHeader(
"ce-type").Data();
36 else if (!arg->GetRequestHeader(
"Content-Type").CompareTo(
"application/cloudevents+json") ||
37 !arg->GetRequestHeader(
"content-type").CompareTo(
"application/cloudevents+json")) {
43 std::string postDataString(
static_cast<const char *
>(arg->GetPostData()), arg->GetPostDataLength());
44 json j = json::parse(postDataString);
46 fData = j.dump().c_str();
47 if (j[
"datacontenttype"].is_null()) {
52 fData = j[
"data"].get<std::string>();
55 if (
fId.empty() && !j[
"id"].is_null())
fId = j[
"id"].get<std::string>();
56 if (
fSource.empty() && !j[
"source"].is_null())
fSource = j[
"source"].get<std::string>();
58 if (
fType.empty() && !j[
"type"].is_null())
fType = j[
"type"].get<std::string>();
67 return TString::Format(
"NCloudEvent: id=%s source=%s specVersion=%s type=%s datacontenttype=%s data=%s",
fId.c_str(),
83 Printf(
"%s",
GetInfo().c_str());
Represents a CloudEvent object for HTTP communication.
std::string fType
Event type.
void HandleNCloudEventRequest(THttpCallArg *arg)
Handles an HTTP request for a CloudEvent.
std::string fSource
Event source URI-reference.
bool fIsValid
Validity flag for the event.
virtual ~NCloudEvent()
Destroys the NCloudEvent instance.
NCloudEvent(std::string id="0", std::string source="unknown", std::string specVersion="1.0", std::string type="unknown")
Constructs a new NCloudEvent with specified parameters.
std::string GetInfo() const
Gets additional event information.
std::string fDataContentType
Event data content type.
std::string fData
Event data payload.
std::string fId
Event identifier.
std::string fSpecVersion
CloudEvent specification version.
virtual void Clear(Option_t *opt="")
Clears the event data.
virtual void Print(Option_t *opt="") const
Prints the event details.