Add an option to switch off SOAP support.

master
Adam Gu 7 years ago
parent 47e94bffd2
commit e04565a468

@ -3,11 +3,15 @@ if(WEBCC_ENABLE_UT)
add_subdirectory(webcc_unittest)
endif()
add_subdirectory(pugixml)
if(WEBCC_ENABLE_SOAP)
add_subdirectory(pugixml)
endif()
add_subdirectory(webcc)
if(WEBCC_ENABLE_DEMO)
add_subdirectory(demo/soap/calc_client)
add_subdirectory(demo/soap/calc_server)
if(WEBCC_ENABLE_SOAP)
add_subdirectory(demo/soap/calc_client)
add_subdirectory(demo/soap/calc_server)
endif()
endif()

@ -7,6 +7,43 @@ endif()
# Don't use any deprecated definitions (e.g., io_service).
add_definitions(-DBOOST_ASIO_NO_DEPRECATED)
file(GLOB SRCS *.cc *.h)
set(SRCS
common.cc
common.h
http_client.cc
http_client.h
http_message.cc
http_message.h
http_parser.cc
http_parser.h
http_request.cc
http_request.h
http_request_handler.cc
http_request_handler.h
http_request_parser.cc
http_request_parser.h
http_response.cc
http_response.h
http_response_parser.cc
http_response_parser.h
http_server.cc
http_server.h
http_session.cc
http_session.h
queue.h
rest_server.cc
rest_server.h
rest_service.h
url.cc
url.h
utility.cc
utility.h
)
if(WEBCC_ENABLE_SOAP)
# SOAP specific sources.
file(GLOB SOAP_SRCS soap_*.cc soap_*.h)
set(SRCS ${SRCS} ${SOAP_SRCS})
endif()
add_library(webcc ${SRCS})

@ -83,7 +83,7 @@ Error HttpClient::SendRequest(const HttpRequest& request,
// Send HTTP request.
#if WEBCC_DEBUG_OUTPUT
std::cout << "# REQUEST" << std::endl << request << std::endl;
std::cout << "--- REQUEST ---" << std::endl << request << std::endl;
#endif
try {
@ -93,7 +93,7 @@ Error HttpClient::SendRequest(const HttpRequest& request,
}
#if WEBCC_DEBUG_OUTPUT
std::cout << "# RESPONSE" << std::endl;
std::cout << "--- RESPONSE ---" << std::endl;
#endif
// Read and parse HTTP response.
@ -131,7 +131,7 @@ Error HttpClient::SendRequest(const HttpRequest& request,
#if WEBCC_DEBUG_OUTPUT
std::cout << std::endl;
std::cout << "# RESPONSE (PARSED)" << std::endl;
std::cout << "--- RESPONSE (PARSED) ---" << std::endl;
std::cout << *response << std::endl;
#endif

@ -1,8 +1,5 @@
#include "webcc/http_response.h"
#include "webcc/common.h"
#include "webcc/xml.h"
namespace webcc {
std::ostream& operator<<(std::ostream& os, const HttpResponse& response) {
@ -12,12 +9,8 @@ std::ostream& operator<<(std::ostream& os, const HttpResponse& response) {
os << h.name << ": " << h.value << std::endl;
}
os << std::endl;
// Pretty print the SOAP response XML.
if (!xml::PrettyPrintXml(os, response.content())) {
os << response.content();
}
os << std::endl << std::endl;
os << response.content();
return os;
}

@ -22,6 +22,7 @@ public:
int status() const {
return status_;
}
void set_status(int status) {
status_ = status;
}
@ -35,7 +36,7 @@ public:
static HttpResponse Fault(HttpStatus::Enum status);
private:
int status_ = HttpStatus::kOK; // TODO: HttpStatus
int status_ = HttpStatus::kOK;
};
} // namespace webcc

@ -1,7 +1,7 @@
#include "webcc/soap_message.h"
#include <cassert>
#include "webcc/xml.h"
#include "webcc/soap_xml.h"
namespace webcc {
@ -18,15 +18,15 @@ void SoapMessage::ToXml(std::string* xml_string) {
// pugi::xml_node xdecl = xdoc.prepend_child(pugi::node_declaration);
// xdecl.append_attribute("version").set_value("1.0");
pugi::xml_node xroot = xml::AddChild(xdoc, soapenv_ns_.name, "Envelope");
pugi::xml_node xroot = soap_xml::AddChild(xdoc, soapenv_ns_.name, "Envelope");
xml::AddNSAttr(xroot, soapenv_ns_.name, soapenv_ns_.url);
soap_xml::AddNSAttr(xroot, soapenv_ns_.name, soapenv_ns_.url);
pugi::xml_node xbody = xml::AddChild(xroot, soapenv_ns_.name, "Body");
pugi::xml_node xbody = soap_xml::AddChild(xroot, soapenv_ns_.name, "Body");
ToXmlBody(xbody);
xml::XmlStrRefWriter writer(xml_string);
soap_xml::XmlStrRefWriter writer(xml_string);
xdoc.save(writer, "\t", pugi::format_default, pugi::encoding_utf8);
}
@ -40,10 +40,10 @@ bool SoapMessage::FromXml(const std::string& xml_string) {
pugi::xml_node xroot = xdoc.document_element();
soapenv_ns_.name = xml::GetPrefix(xroot);
soapenv_ns_.url = xml::GetNSAttr(xroot, soapenv_ns_.name);
soapenv_ns_.name = soap_xml::GetPrefix(xroot);
soapenv_ns_.url = soap_xml::GetNSAttr(xroot, soapenv_ns_.name);
pugi::xml_node xbody = xml::GetChild(xroot, soapenv_ns_.name, "Body");
pugi::xml_node xbody = soap_xml::GetChild(xroot, soapenv_ns_.name, "Body");
if (xbody) {
return FromXmlBody(xbody);
}

@ -1,5 +1,5 @@
#include "webcc/soap_request.h"
#include "webcc/xml.h"
#include "webcc/soap_xml.h"
namespace webcc {
@ -23,11 +23,11 @@ const std::string& SoapRequest::GetParameter(const std::string& key) const {
}
void SoapRequest::ToXmlBody(pugi::xml_node xbody) {
pugi::xml_node xop = xml::AddChild(xbody, service_ns_.name, operation_);
xml::AddNSAttr(xop, service_ns_.name, service_ns_.url);
pugi::xml_node xop = soap_xml::AddChild(xbody, service_ns_.name, operation_);
soap_xml::AddNSAttr(xop, service_ns_.name, service_ns_.url);
for (Parameter& p : parameters_) {
pugi::xml_node xparam = xml::AddChild(xop, service_ns_.name, p.key());
pugi::xml_node xparam = soap_xml::AddChild(xop, service_ns_.name, p.key());
xparam.text().set(p.value().c_str());
}
}
@ -38,13 +38,13 @@ bool SoapRequest::FromXmlBody(pugi::xml_node xbody) {
return false;
}
xml::SplitName(xoperation, &service_ns_.name, &operation_);
service_ns_.url = xml::GetNSAttr(xoperation, service_ns_.name);
soap_xml::SplitName(xoperation, &service_ns_.name, &operation_);
service_ns_.url = soap_xml::GetNSAttr(xoperation, service_ns_.name);
pugi::xml_node xparameter = xoperation.first_child();
while (xparameter) {
parameters_.push_back({
xml::GetNameNoPrefix(xparameter),
soap_xml::GetNameNoPrefix(xparameter),
std::string(xparameter.text().as_string())
});

@ -1,16 +1,19 @@
#include "webcc/soap_response.h"
#include <cassert>
#include "webcc/xml.h"
#include "webcc/soap_xml.h"
namespace webcc {
void SoapResponse::ToXmlBody(pugi::xml_node xbody) {
std::string rsp_operation = operation_ + "Response";
pugi::xml_node xop = xml::AddChild(xbody, service_ns_.name, rsp_operation);
xml::AddNSAttr(xop, service_ns_.name, service_ns_.url);
pugi::xml_node xresult = xml::AddChild(xop, service_ns_.name, result_name_);
pugi::xml_node xop = soap_xml::AddChild(xbody,
service_ns_.name,
operation_ + "Response");
soap_xml::AddNSAttr(xop, service_ns_.name, service_ns_.url);
pugi::xml_node xresult = soap_xml::AddChild(xop,
service_ns_.name,
result_name_);
xresult.text().set(result_.c_str());
}
@ -19,10 +22,10 @@ bool SoapResponse::FromXmlBody(pugi::xml_node xbody) {
pugi::xml_node xresponse = xbody.first_child();
if (xresponse) {
xml::SplitName(xresponse, &service_ns_.name, NULL);
service_ns_.url = xml::GetNSAttr(xresponse, service_ns_.name);
soap_xml::SplitName(xresponse, &service_ns_.name, NULL);
service_ns_.url = soap_xml::GetNSAttr(xresponse, service_ns_.name);
pugi::xml_node xresult = xml::GetChildNoNS(xresponse, result_name_);
pugi::xml_node xresult = soap_xml::GetChildNoNS(xresponse, result_name_);
if (xresult) {
result_ = xresult.text().get();
return true;

@ -1,7 +1,7 @@
#include "webcc/xml.h"
#include "webcc/soap_xml.h"
namespace webcc {
namespace xml {
namespace soap_xml {
void SplitName(const pugi::xml_node& xnode,
std::string* prefix,
@ -92,9 +92,9 @@ std::string GetNSAttr(pugi::xml_node& xnode,
return xnode.attribute(attr_name.c_str()).as_string();
}
bool PrettyPrintXml(std::ostream& os,
const std::string& xml_string,
const char* indent) {
bool PrettyPrint(std::ostream& os,
const std::string& xml_string,
const char* indent) {
pugi::xml_document xdoc;
if (!xdoc.load_string(xml_string.c_str())) {
os << "Invalid XML" << std::endl;
@ -105,5 +105,5 @@ bool PrettyPrintXml(std::ostream& os,
return true;
}
} // namespace xml
} // namespace soap_xml
} // namespace webcc

@ -1,5 +1,5 @@
#ifndef WEBCC_XML_H_
#define WEBCC_XML_H_
#ifndef WEBCC_SOAP_XML_H_
#define WEBCC_SOAP_XML_H_
// XML utilities.
@ -7,7 +7,7 @@
#include "pugixml/pugixml.hpp"
namespace webcc {
namespace xml {
namespace soap_xml {
// Split the node name into namespace prefix and real name.
// E.g., if the node name is "soapenv:Envelope", it will be splited to
@ -81,11 +81,12 @@ private:
std::string* result_;
};
bool PrettyPrintXml(std::ostream& os,
const std::string& xml_string,
const char* indent = "\t");
// Print the XML string to output stream in pretty format.
bool PrettyPrint(std::ostream& os,
const std::string& xml_string,
const char* indent = "\t");
} // namespace xml
} // namespace soap_xml
} // namespace webcc
#endif // WEBCC_XML_H_
#endif // WEBCC_SOAP_XML_H_
Loading…
Cancel
Save