Add async-client support; refine http message dump format.
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
file(GLOB SRCS *.cc *.h)
|
||||
|
||||
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}")
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
#include "calc_client.h"
|
||||
#include <iostream>
|
||||
#include "boost/lexical_cast.hpp"
|
||||
#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("notexist", "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::GetErrorMessage(error));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert the result from string to double.
|
||||
try {
|
||||
*result = boost::lexical_cast<double>(result_str);
|
||||
} catch (boost::bad_lexical_cast&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
#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_
|
||||
@@ -1,250 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,36 +0,0 @@
|
||||
#include <iostream>
|
||||
#include "webcc/logger.h"
|
||||
#include "calc_client.h"
|
||||
|
||||
int main() {
|
||||
LOG_INIT(webcc::VERB, 0);
|
||||
|
||||
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("notexist: %.1f\n", result);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user