From 5f5db5f45fdcd770018003bdcfe02a0888f25ca1 Mon Sep 17 00:00:00 2001 From: Michael Davis <michael.davis@cern.ch> Date: Sun, 4 Jun 2017 04:51:18 +0200 Subject: [PATCH] Sends Metadata from server --- frontend/TestSsiClient.h | 14 ++++++-------- frontend/TestSsiRequest.h | 2 +- frontend/TestSsiRequestProc.cpp | 17 +++++++++++++---- frontend/TestSsiRequestProc.h | 29 ++++++++++++++++++++++++----- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/frontend/TestSsiClient.h b/frontend/TestSsiClient.h index 4b24861502..ace4d6eed6 100644 --- a/frontend/TestSsiClient.h +++ b/frontend/TestSsiClient.h @@ -60,22 +60,20 @@ public: } } - void send(RequestType request_msg) + void send(RequestType request) { - // Requests are always executed in the context of a service. They need to correspond to what the service allows. - - XrdSsiRequest *requestP; - // Serialize the request object std::string request_str; - if(!request_msg.SerializeToString(&request_str)) + if(!request.SerializeToString(&request_str)) { - throw XrdSsiException("SerializeToString() failed"); + throw XrdSsiException("request.SerializeToString() failed"); } - requestP = new TestSsiRequest(request_str, timeout); + // Requests are always executed in the context of a service. They need to correspond to what the service allows. + + XrdSsiRequest *requestP = new TestSsiRequest(request_str, timeout); // Transfer ownership of the request to the service object // TestSsiRequest handles deletion of the request buffer, so we can allow the pointer to go out-of-scope diff --git a/frontend/TestSsiRequest.h b/frontend/TestSsiRequest.h index fcfa81399e..dd7ed56cea 100644 --- a/frontend/TestSsiRequest.h +++ b/frontend/TestSsiRequest.h @@ -7,7 +7,7 @@ class TestSsiRequest : public XrdSsiRequest { public: - TestSsiRequest(const std::string &buffer_str, uint16_t tmo=0) : request_buffer(buffer_str.c_str()), request_len(buffer_str.length()) + TestSsiRequest(const std::string &buffer_str, uint16_t tmo=0) : request_buffer(buffer_str.c_str()), request_len(buffer_str.size()) { std::cerr << "Creating TestSsiRequest object, setting tmo=" << tmo << std::endl; this->SetTimeOut(tmo); diff --git a/frontend/TestSsiRequestProc.cpp b/frontend/TestSsiRequestProc.cpp index 2eb3de557f..d6d280b0d4 100644 --- a/frontend/TestSsiRequestProc.cpp +++ b/frontend/TestSsiRequestProc.cpp @@ -22,7 +22,7 @@ void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Meta // Output message in Json format (for debugging) - std::cerr << "Sending response:" << std::endl; + std::cerr << "Preparing response:" << std::endl; std::cerr << xrdssi::test::MessageToJsonString(response); } @@ -35,9 +35,14 @@ void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Meta template <> void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Metadata, xrdssi::test::Alert>::ExecuteMetadata() { - std::cerr << "Sending metadata..." << std::endl; - const std::string metadata("Have some metadata!"); - SetMetadata(metadata.c_str(), metadata.size()); + // Set metadata + + metadata.set_message_text("Have some metadata"); + + // Output message in Json format (for debugging) + + std::cerr << "Preparing metadata..." << std::endl; + std::cerr << xrdssi::test::MessageToJsonString(metadata); } @@ -63,4 +68,8 @@ void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Meta * A parameter to the method tells you why it’s being called. * * See example p.45 +template <> +void RequestProc<xrdssi::test::Request, xrdssi::test::Result, xrdssi::test::Metadata, xrdssi::test::Alert>::ExecuteAlert() +{ +} */ diff --git a/frontend/TestSsiRequestProc.h b/frontend/TestSsiRequestProc.h index 501596253e..52e72563cc 100644 --- a/frontend/TestSsiRequestProc.h +++ b/frontend/TestSsiRequestProc.h @@ -37,6 +37,8 @@ private: RequestType request; ResponseType response; + MetadataType metadata; + AlertType alert; }; @@ -61,7 +63,7 @@ void RequestProc<RequestType, ResponseType, MetadataType, AlertType>::Execute() if(!request.ParseFromString(request_str)) { - throw XrdSsiException("ParseFromString() failed"); + throw XrdSsiException("request.ParseFromString() failed"); } // Release the request buffer (optional, perhaps it is more efficient to reuse it?) @@ -76,22 +78,39 @@ void RequestProc<RequestType, ResponseType, MetadataType, AlertType>::Execute() ExecuteAlerts(); - // Optional: send metadata ahead of the response + // Optional: prepare to send metadata ahead of the response ExecuteMetadata(); - // Serialize the Response + // Serialize the Metadata std::string response_str; + if(!metadata.SerializeToString(&response_str)) + { + throw XrdSsiException("metadata.SerializeToString() failed"); + } + + // Send the Metadata + + if(response_str.size() > 0) + { + SetMetadata(response_str.c_str(), response_str.size()); + } + + // Serialize the Response + if(!response.SerializeToString(&response_str)) { - throw XrdSsiException("SerializeToString() failed"); + throw XrdSsiException("response.SerializeToString() failed"); } // Send the response - SetResponse(response_str.c_str(), response_str.length()); + if(response_str.size() > 0) + { + SetResponse(response_str.c_str(), response_str.size()); + } } -- GitLab