Commit 54c9991e authored by Michael Davis's avatar Michael Davis
Browse files

Sends Metadata from server

parent a9b167ad
......@@ -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
......
......@@ -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);
......
......@@ -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()
{
}
*/
......@@ -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());
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment