templates.stub.ksoap.stub.class.vm Maven / Gradle / Ivy
#parse("${include}/generic.include.vm")
#parse("${include}/webclient.ksoap.include.vm")
#set ( $className ="$stubClassName")
$codewriter.setCurrentJavaFilename("$pkg", "${className}.java")
##生成注释
#macro (comment $method)
/**
* $GENERAED_BY
* 参见{@link $method.getDocSignature($imports)}
#foreach( $parameter in $method.parameters)
* @param $parameter.name
#end
* @return #typeName($method.genericReturnType)
#foreach( $exception in $method.exceptionTypes)
* @throws $exception.simpleName
#end
* @see $method.getDocSignature($imports)
*/
#end
package $pkg;
#outputImports()
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.serialization.PropertyInfo;
import java.io.File;
import java.lang.reflect.Constructor;
import java.net.URI;
import java.util.List;
/**
* 实现{@link #typeName(${sourceinfo.serviceClass})} WebService的本地代理
* 所有自来服务器端的{@link ServiceRuntime}异常都被封装在{@link RuntimeException}中抛出,
* 可以通过调用{@link ServiceRuntime#getServerStackTraceMessage()}获取服务器端异常的堆栈信息,
* 例如:
*
* try{
* double sim = faceapi.detectAndCompare2Face(
* TestFaceAPI.class.getResourceAsStream("/images/guyadong-1.jpg")
* , null
* , TestFaceAPI.class.getResourceAsStream("/images/guyadong-2.jpg")
* , null);
* System.out.printf("similarity=%f\n",sim);
* }catch(RuntimeException e){
* if(e.getCause() instanceof ServiceRuntime){
* ((ServiceRuntime)e.getCause()).printServerStackTrace();
* }else
* e.printStackTrace();
* }
*
* $GENERAED_BY
* @author guyadong
*
*/
public class ${className} implements $I_CONSTANT{
/**
* 线程局部变量
* 每个线程独享一个 {@link $C_ENVELOPE}对象
*/
private static final ThreadLocal<$C_ENVELOPE> envelope=new ThreadLocal<$C_ENVELOPE>();
/**
* 线程局部变量
* 每个线程独享一个 {@link HttpTransportSE}对象
*/
private static final ThreadLocal transport=new ThreadLocal();
private final String nameSpace ="http://service.gdface.net";
/**
* Webservice目标目标地址
*/
private final String endPoint;
/**
* {@link HttpTransportSE}超时参数(毫秒)默认
*/
private long timeoutMills=-1;
/**
* {@link org.ksoap2.transport.Transport}请求头
* 参见{@link org.ksoap2.transport.Transport#call(String, SoapEnvelope, List, File)}
*/
private List> headers=null;
/**
* 是否启动GZIP压缩
*/
private boolean compress=true;
/**
* 用于调试的输出xml文件({@link #debug}为{@code true}有效),默认为{@code null}
* 每次webservice调用返回的xml会保存到指定的文件中
*/
private File outputFile=null;
/**
* {@link org.ksoap2.transport.Transport}调试标志,默认为{@code false}
* 参见 {@link org.ksoap2.transport.Transport#debug}
*/
private boolean debug=false;
/**
* ${className}构造方法
*
* @param endPoint
* Webservice目标目标地址
* 如:http://192.168.1.18:8080/axis2/services/FaceDbService
*/
$className(String endPoint){
if(endPoint==null)
throw new IllegalArgumentException("endpoint must not be null");
this.endPoint=endPoint;
}
/**
* ${className}构造方法
* @param builder
*/
${className}(Builder builder){
endPoint=builder.endPoint;
timeoutMills = builder.timeoutMills;
debug=builder.debug;
outputFile=builder.outputFile;
headers=builder.headers;
compress=builder.compress;
}
/**
* 从 {@link #envelope}中获取 {@link $C_ENVELOPE}对象,如果不存在则创建新对象
* @return $C_ENVELOPE
*/
public final $C_ENVELOPE getEnvelope(){
$C_ENVELOPE env;
if(null==(env = envelope.get())){
env = new $C_ENVELOPE(SoapEnvelope.VER11);
for(PropertyInfo info:$V_COMPLEXTYPES){
env.addMapping(info.namespace, info.name,(Class>) info.type);
}
envelope.set(env);
}
return env;
}
/**
* 从 {@link #transport}中获取 {@link HttpTransportSE}对象,如果不存在则创建新对象
* @return HttpTransportSE
*/
public HttpTransportSE getHttpTransport(){
HttpTransportSE trans=transport.get();
if (null == trans) {
$C_GZIPHTTPTRANSPORT gziptrans;
try {
if (timeoutMills > 0) {
gziptrans = new $C_GZIPHTTPTRANSPORT(endPoint,(int)timeoutMills);
} else
gziptrans = new $C_GZIPHTTPTRANSPORT(endPoint);
} catch (Exception e) {
throw new RuntimeException(e);
}
gziptrans.compress=this.compress;
trans=gziptrans;
transport.set(trans);
}
trans.debug=debug;
return trans;
}
/**
* 所有port方法的请求(Request)对象{@link java.util.Map}
* 以请求对象类(Class)为key,以{@link ThreadLocal}为value,保存每个线程独享的Request对象
* 在同一个线程反复port方法时只会使用一个Request对象
*/
private static final java.util.Map,ThreadLocal
© 2015 - 2025 Weber Informatics LLC | Privacy Policy