All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.includes.webclient.gsoap.class.body.vm Maven / Gradle / Ivy

There is a newer version: 3.5.0
Show newest version
#parse("${include}/generic.include.vm")
#if( $source_type == "cpp" )
\#include "${className}.h"
\#include "${C_UTILITS}.h"
\#include 
#else
#pragma once
## include所有引用类型的.h文件
#INCLUDE_REFCLASS("true")
\#include "${sourceinfo.baseClass.simpleName}.h"
\#include "stdsoap2.h"
\#include "gsoap_exception.h"
#end
#parse("${include}/webclient.gsoap.${sourceinfo.interfaceClass.simpleName}.import.vm")
#init_qualifier($source_type)
#macro(  initValue $jclass)#if(!$jclass.array||$TOOL.isArrayOfbyte($jclass))nullptr#end#end
$gsoapHelper.namespaceBegin($sourceinfo.baseClass)
#if( $source_type != "h" )
${BASEINDENT}        using namespace net::gdface::utils; 
${BASEINDENT}        // 根据SOAP版本(SOAP 1.1/SOAP 1.2)返回异常详细信息描述对象的指针  
${BASEINDENT}        inline SOAP_ENV__Detail* getFaultDetail(soap &_soap) {
${BASEINDENT}            return  _soap.version == 2 ? _soap.fault->SOAP_ENV__Detail : _soap.fault->detail;
${BASEINDENT}        }
${BASEINDENT}        // 从soap对象中获取错误信息 
${BASEINDENT}        static std::string getFaultString(soap& _soap){
${BASEINDENT}            auto faultstring_ptr = *soap_faultstring(&_soap);
${BASEINDENT}            std::string faultstring;
${BASEINDENT}            if (nullptr == faultstring_ptr) {
${BASEINDENT}                // 错误信息为nullptr时,输出soap错误代码 
${BASEINDENT}                // 参见 http://www.genivia.com/doc/soapdoc2.html#tth_sEc10.2 或 stdsoap2.h
${BASEINDENT}                std::ostringstream stream;
${BASEINDENT}                stream << "soap.error=" << _soap.error;
${BASEINDENT}                faultstring=stream.str();
${BASEINDENT}            }else{
${BASEINDENT}                faultstring=faultstring_ptr;
${BASEINDENT}            }
${BASEINDENT}            return faultstring;
${BASEINDENT}        }
#end
#if( $source_type != "cpp" )
#USING_REFCLASSES($BASEINDENT "true")
${BASEINDENT}    // 基于GSoap stub 的$gsoapHelper.toCppFullName(${sourceinfo.interfaceClass}) 接口( 对应java接口${sourceinfo.interfaceClass.name} )的Webservice实现 
${BASEINDENT}    // 所有自来服务器端的$gsoapHelper.toCppFullName(${sourceinfo.serviceRuntimeClass})异常 
${BASEINDENT}    // 可以通过调用$gsoapHelper.toCppFullName(${sourceinfo.serviceRuntimeClass})::getServerStackTraceMessage()获取服务器端异常的堆栈信息,参见实现代码中的注释 
${BASEINDENT}    // 线程安全(theadsafe),可以被多个线程共享使用 
${BASEINDENT}    // 相关接口描述参见javadoc文档 
${BASEINDENT}    // $GENERAED_BY
${BASEINDENT}    class ${className} : public  $gsoapHelper.toCppFullName($sourceinfo.baseClass){
#end
#if( $source_type != "cpp" )
${BASEINDENT}    private:
${BASEINDENT}        // webservice服务器访问地址(url)
${BASEINDENT}        std::string endpoint;
${BASEINDENT}        // soap参数对象 
${BASEINDENT}        soap paramSoap; 
${BASEINDENT}    public:
${BASEINDENT}        virtual~${className}()=default;
${BASEINDENT}        ${className}()=default;
${BASEINDENT}        // 基本构造函数 
${BASEINDENT}        // endpoint webservice服务器访问地址(url)  
${BASEINDENT}        // paramSoap soap参数对象,不填则使用默认soap参数 
${BASEINDENT}        ${className}(const std::string &endpoint,const soap ¶mSoap=soap());
${BASEINDENT}        inline const std::string& getEndpoint()const noexcept{
${BASEINDENT}            return this->endpoint;
${BASEINDENT}        }
${BASEINDENT}        inline const soap& getParamSoap()const noexcept{
${BASEINDENT}            return this->paramSoap;
${BASEINDENT}        }
#end
#parse("${include}/webclient.gsoap.${sourceinfo.interfaceClass.simpleName}.body.vm")
#set( $method2PortMap=$sourceinfo.method2PortMap)
#if( $source_type != "cpp" )
${BASEINDENT}    public:
#end
#foreach ($method in $TOOL.sortBySignature($methods))
#set( $port = $method2PortMap.get($method))
#set( $exceptions=$TOOL.sortThrowable($port.genericExceptionTypes))
#set( $parameterClassName=$typeNameMap[$port.name])
${BASEINDENT}        //$velocityCount
${BASEINDENT}        // $gsoapHelper.toCppFullName(${sourceinfo.interfaceClass}) 接口函数实现 
${BASEINDENT}        // 对应java接口${sourceinfo.interfaceClass.name}的方法: 
${BASEINDENT}        // $method
#if( $source_type != "h" )
${BASEINDENT}        // 调用过程中可能会抛出std::logic_error标准异常, 
${BASEINDENT}        // 以及#join($exceptions '$e.simpleName' ',') 

${BASEINDENT}        // 等服务器端异常, 
${BASEINDENT}        // 必须用try{}catch{}语句捕获异常,例如:  
${BASEINDENT}        /*  
${BASEINDENT}                try {
${BASEINDENT}                    ${sourceinfo.interfaceClass.simpleName.toLowerCase()}_instance->${method.name}(...);
${BASEINDENT}                }
#foreach($exp in $exceptions)
#if($sourceinfo.isServiceRuntime($exp))
${BASEINDENT}                catch ($gsoapHelper.toCppFullName($exp)& e) {
${BASEINDENT}                   //输出服务器异常堆栈信息 
${BASEINDENT}                   std::cout<< e.getServerStackTraceMessage() <paramSoap);
${BASEINDENT}            // 参见 http://www.genivia.com/doc/soapdoc2.html#tth_sEc9.12 
${BASEINDENT}            soap_set_omode(&_soap,SOAP_C_NILSTRING| SOAP_XML_NIL);
#ifdef WITH_GSOAP_GZIP
// 启用GZIP压缩 参见 http://www.genivia.com/doc/soapdoc2.html#tth_sEc19.28
${BASEINDENT}            soap_set_omode(&_soap,SOAP_IO_CHUNK| SOAP_ENC_ZLIB);
#endif
${BASEINDENT}            $parameterClassName param;
${BASEINDENT}            ${parameterClassName}Response ret;
#foreach($parameter in $method.parameters)
#set($stubName=$gsoapHelper.toStubName($parameter.name))
#if($parameter.type.primitive||$TOOL.isString($parameter.type))
${BASEINDENT}            param.$stubName=(decltype(param.$stubName))std::addressof($parameter.name);
#else
${BASEINDENT}            param.$stubName=convert(_soap,$parameter.name,decltype(param.$stubName)(#initValue($parameter.type)));
#end
#end
${BASEINDENT}            // endpoint为空则抛出异常 
${BASEINDENT}            throw_if_msg(this->endpoint.empty(),"endpoint must not be empty")
${BASEINDENT}            // 执行soap远程调用 
${BASEINDENT}            soap_call__${parameterClassName}(&_soap, this->endpoint.c_str(), nullptr, ¶m, ret);
${BASEINDENT}            if (_soap.error != SOAP_OK) {
${BASEINDENT}                soap_fault(&_soap);
${BASEINDENT}                auto detail = getFaultDetail(_soap);
${BASEINDENT}                // detail不为nullptr 表示有webservice声明的异常发生 
${BASEINDENT}                if ( nullptr != detail ) {
#foreach($exp in $exceptions)
${BASEINDENT}                    // 根据指针 $gsoapHelper.toStubExpectionClassName($exp) 判断是否为$gsoapHelper.toCppFullName($exp)异常 
${BASEINDENT}                    // 如果不为nullptr则调用convert函数将stub 类型对象转为$gsoapHelper.toCppFullName($exp)异常对象抛出
${BASEINDENT}                    // 在调用convert时将代码抛出位置信息通过 ${exp.simpleName} 对象传递给convert函数
${BASEINDENT}                    if (nullptr != detail->$gsoapHelper.toStubExpectionClassName($exp)) 
${BASEINDENT}                        throw convert(detail->$gsoapHelper.toStubExpectionClassName($exp)->$exp.simpleName,${exp.simpleName}(std::string(SOURCE_AT ":")));
#end
${BASEINDENT}                }
${BASEINDENT}                // 其他类型错误以 net::gdface::exception::gsoap_exception 异常抛出 
${BASEINDENT}                throw net::gdface::exception::gsoap_exception(_soap.error,ERROR_STR(getFaultString(_soap)));
${BASEINDENT}            }
#if ($TOOL.isVoid($method.returnType))            
#elseif($method.returnType.primitive||$TOOL.isString($method.returnType))
${BASEINDENT}            return *ret.return_;
#else
${BASEINDENT}            // 调用convert函数将返回值(stub 类型对象)转为$gsoapHelper.toCppType($method.genericReturnType)类型对象返回 
${BASEINDENT}            return convert(ret.return_,$gsoapHelper.toCppType($method.genericReturnType)());
#end
${BASEINDENT}        }
#end
#end
#if( $source_type != "cpp" )
${BASEINDENT}    protected:
${BASEINDENT}        std::shared_ptr<${className}> shared_from_this()
${BASEINDENT}        {
${BASEINDENT}            return std::static_pointer_cast<${className}>($gsoapHelper.toCppFullName($sourceinfo.baseClass)::shared_from_this());
${BASEINDENT}        }
#end
#if( $source_type != "cpp" )
${BASEINDENT}    };
#end
 $gsoapHelper.namespaceEnd()




© 2015 - 2025 Weber Informatics LLC | Privacy Policy