Reorganize folder structure.

This commit is contained in:
Adam Gu
2018-07-06 13:59:16 +08:00
parent 3b13cc74f7
commit 88511caff6
82 changed files with 38 additions and 48 deletions
+7
View File
@@ -0,0 +1,7 @@
set(SRCS calc_client.cc calc_client.h main.cc)
add_executable(soap_calc_client ${SRCS})
target_link_libraries(soap_calc_client webcc pugixml ${Boost_LIBRARIES})
target_link_libraries(soap_calc_client "${CMAKE_THREAD_LIBS_INIT}")
+89
View File
@@ -0,0 +1,89 @@
#include "example/soap_calc_client/calc_client.h"
#include <iostream>
#include "webcc/logger.h"
// Set to 0 to test our own calculator server created with webcc.
#define ACCESS_PARASOFT 0
CalcClient::CalcClient() {
Init();
}
bool CalcClient::Add(double x, double y, double* result) {
return Calc("add", "x", "y", x, y, result);
}
bool CalcClient::Subtract(double x, double y, double* result) {
return Calc("subtract", "x", "y", x, y, result);
}
bool CalcClient::Multiply(double x, double y, double* result) {
return Calc("multiply", "x", "y", x, y, result);
}
bool CalcClient::Divide(double x, double y, double* result) {
// ParaSoft's Calculator Service uses different parameter names for Divide.
#if ACCESS_PARASOFT
return Calc("divide", "numerator", "denominator", x, y, result);
#else
return Calc("divide", "x", "y", x, y, result);
#endif
}
bool CalcClient::NotExist(double x, double y, double* result) {
return Calc("not_exist", "x", "y", x, y, result);
}
void CalcClient::Init() {
// Override the default timeout.
timeout_seconds_ = 5;
#if ACCESS_PARASOFT
url_ = "/glue/calculator";
host_ = "ws1.parasoft.com";
port_ = ""; // Default to "80".
service_ns_ = { "cal", "http://www.parasoft.com/wsdl/calculator/" };
result_name_ = "Result";
#else
url_ = "/calculator";
host_ = "localhost";
port_ = "8080";
service_ns_ = { "ser", "http://www.example.com/calculator/" };
result_name_ = "Result";
#endif
}
bool CalcClient::Calc(const std::string& operation,
const std::string& x_name,
const std::string& y_name,
double x,
double y,
double* result) {
// Prepare parameters.
std::vector<webcc::Parameter> parameters{
{ x_name, x },
{ y_name, y }
};
// Make the call.
std::string result_str;
webcc::Error error = Call(operation, std::move(parameters), &result_str);
// Error handling if any.
if (error != webcc::kNoError) {
LOG_ERRO("Operation '%s' failed: %s", operation.c_str(),
webcc::DescribeError(error));
return false;
}
// Convert the result from string to double.
try {
*result = std::stod(result_str);
} catch (const std::exception&) {
return false;
}
return true;
}
+35
View File
@@ -0,0 +1,35 @@
#ifndef CALC_CLIENT_H_
#define CALC_CLIENT_H_
#include <string>
#include "webcc/soap_client.h"
class CalcClient : public webcc::SoapClient {
public:
CalcClient();
bool Add(double x, double y, double* result);
bool Subtract(double x, double y, double* result);
bool Multiply(double x, double y, double* result);
bool Divide(double x, double y, double* result);
// For testing purpose.
bool NotExist(double x, double y, double* result);
protected:
void Init();
// A more concrete wrapper to make a call.
bool Calc(const std::string& operation,
const std::string& x_name,
const std::string& y_name,
double x,
double y,
double* result);
};
#endif // CALC_CLIENT_H_
+250
View File
@@ -0,0 +1,250 @@
<?xml version="1.0" encoding="US-ASCII"?>
<!--generated by GLUE Standard 4.1.2 on Fri Nov 21 13:50:48 PST 2003-->
<wsdl:definitions name="Calculator"
targetNamespace="http://www.parasoft.com/wsdl/calculator/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tme="http://www.themindelectric.com/"
xmlns:tns="http://www.parasoft.com/wsdl/calculator/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xsd:schema
elementFormDefault="qualified"
targetNamespace="http://www.parasoft.com/wsdl/calculator/">
<xsd:element
name="add">
<xsd:complexType>
<xsd:sequence>
<xsd:element
name="x" type="xsd:float"/>
<xsd:element name="y"
type="xsd:float"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element
name="addResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element
name="Result"
type="xsd:float"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element
name="divide">
<xsd:complexType>
<xsd:sequence>
<xsd:element
name="numerator" type="xsd:float"/>
<xsd:element
name="denominator"
type="xsd:float"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element
name="divideResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element
name="Result"
type="xsd:float"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element
name="multiply">
<xsd:complexType>
<xsd:sequence>
<xsd:element
name="x" type="xsd:float"/>
<xsd:element name="y"
type="xsd:float"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element
name="multiplyResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element
name="Result"
type="xsd:float"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element
name="subtract">
<xsd:complexType>
<xsd:sequence>
<xsd:element
name="x" type="xsd:float"/>
<xsd:element name="y"
type="xsd:float"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element
name="subtractResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element
name="Result"
type="xsd:float"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message
name="add0In">
<wsdl:part element="tns:add"
name="parameters"/>
</wsdl:message>
<wsdl:message
name="add0Out">
<wsdl:part element="tns:addResponse"
name="parameters"/>
</wsdl:message>
<wsdl:message
name="divide1In">
<wsdl:part element="tns:divide"
name="parameters"/>
</wsdl:message>
<wsdl:message
name="divide1Out">
<wsdl:part element="tns:divideResponse"
name="parameters"/>
</wsdl:message>
<wsdl:message
name="multiply2In">
<wsdl:part element="tns:multiply"
name="parameters"/>
</wsdl:message>
<wsdl:message
name="multiply2Out">
<wsdl:part element="tns:multiplyResponse"
name="parameters"/>
</wsdl:message>
<wsdl:message
name="subtract3In">
<wsdl:part element="tns:subtract"
name="parameters"/>
</wsdl:message>
<wsdl:message
name="subtract3Out">
<wsdl:part element="tns:subtractResponse"
name="parameters"/>
</wsdl:message>
<wsdl:portType
name="ICalculator">
<wsdl:operation name="add"
parameterOrder="x y">
<wsdl:input message="tns:add0In"
name="add0In"/>
<wsdl:output message="tns:add0Out"
name="add0Out"/>
</wsdl:operation>
<wsdl:operation name="divide"
parameterOrder="numerator denominator">
<wsdl:input
message="tns:divide1In" name="divide1In"/>
<wsdl:output
message="tns:divide1Out"
name="divide1Out"/>
</wsdl:operation>
<wsdl:operation
name="multiply" parameterOrder="x y">
<wsdl:input
message="tns:multiply2In" name="multiply2In"/>
<wsdl:output
message="tns:multiply2Out"
name="multiply2Out"/>
</wsdl:operation>
<wsdl:operation
name="subtract" parameterOrder="x y">
<wsdl:input
message="tns:subtract3In" name="subtract3In"/>
<wsdl:output
message="tns:subtract3Out"
name="subtract3Out"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding
name="ICalculator" type="tns:ICalculator">
<soap:binding
style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation
name="add">
<soap:operation soapAction="add"
style="document"/>
<wsdl:input name="add0In">
<soap:body
use="literal"/>
</wsdl:input>
<wsdl:output
name="add0Out">
<soap:body
use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation
name="divide">
<soap:operation soapAction="divide"
style="document"/>
<wsdl:input name="divide1In">
<soap:body
use="literal"/>
</wsdl:input>
<wsdl:output
name="divide1Out">
<soap:body
use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation
name="multiply">
<soap:operation soapAction="multiply"
style="document"/>
<wsdl:input name="multiply2In">
<soap:body
use="literal"/>
</wsdl:input>
<wsdl:output
name="multiply2Out">
<soap:body
use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation
name="subtract">
<soap:operation soapAction="subtract"
style="document"/>
<wsdl:input name="subtract3In">
<soap:body
use="literal"/>
</wsdl:input>
<wsdl:output
name="subtract3Out">
<soap:body
use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service
name="Calculator">
<wsdl:documentation>instance of class webtool.soap.examples.calculator.Calculator</wsdl:documentation>
<wsdl:port
binding="tns:ICalculator" name="ICalculator">
<soap:address
location="http://ws1.parasoft.com/glue/calculator"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
+38
View File
@@ -0,0 +1,38 @@
#include <iostream>
#include "webcc/logger.h"
#include "example/soap_calc_client/calc_client.h"
int main() {
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
CalcClient calc;
double x = 1.0;
double y = 2.0;
double result = 0.0;
if (calc.Add(x, y, &result)) {
printf("add: %.1f\n", result);
}
if (calc.Subtract(x, y, &result)) {
printf("subtract: %.1f\n", result);
}
if (calc.Multiply(x, y, &result)) {
printf("multiply: %.1f\n", result);
}
if (calc.Divide(x, y, &result)) {
printf("divide: %.1f\n", result);
}
// Try to call a non-existing operation.
if (calc.NotExist(x, y, &result)) {
printf("not_exist: %.1f\n", result);
}
return 0;
}