templates.webclient.stub.stub.class.vm Maven / Gradle / Ivy
#parse("${include}/generic.include.vm")
#set ( $className ="${sourceinfo.interfaceClass.simpleName}WebserviceByStub")
#set ( $serviceInfo =$sourceinfo.serviceInfo)
#set ( $RemoteException =$CLASS.forName("java.rmi.RemoteException"))
#addIntoImports($RemoteException)
$codewriter.setCurrentJavaFilename("$pkg", "${className}.java")
package $pkg;
#outputImports()
#include("${include}/webclient.stub.${sourceinfo.interfaceClass.simpleName}.import.vm")
/**
*
* stub方式实现 {@link #typeName(${sourceinfo.interfaceClass})}的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} extends #typeName($sourceinfo.baseClass){
/**
* @see Axis2Utilits#getStubObject(Object, Class)
* @param t
* @return Object
* @throws AxisFault
*/
private static Object getStubObject(T t) throws AxisFault {
return Axis2Utilits.getStubObject(t, ${sourceinfo.stubClassName}.class);
}
private final StubProvider<${sourceinfo.stubClassName}> stubProvider;
#*${className}(StubProvider<${sourceinfo.stubClassName}> stub) {
this.stubProvider = stub;
}*#
#parse("${include}/webclient.stub.${sourceinfo.interfaceClass.simpleName}.body.vm")
#set( $method2PortMap=$sourceinfo.method2PortMap)
#foreach ($method in $TOOL.sortBySignature($methods))
#set( $port = $method2PortMap.get($method))
#set( $parameterClassName=$sourceinfo.toStubClassName($port))
#set( $hasIOException=false)
#set( $isVoid=$TOOL.isVoid($method.returnType))
@Override//$velocityCount
public #typeParametersDefine() #typeName($method.genericReturnType) $method.name (#join($method.parameters '#pamameterType($e) $e.name' ',')) #fillThrows($TOOL.sortBy($method.genericExceptionTypes,"simpleName")){
try{
$parameterClassName m=new $parameterClassName();
#foreach($parameter in $method.parameters)
#if($TOOL.isArrayOfbyte($parameter.type))
m.${sourceinfo.toSetMethod($parameter.name)}(new DataHandler(new ByteArrayDataSource($parameter.name)));
#elseif($TOOL.isSimpleType($TOOL.getElementClass($parameter.type)))
m.${sourceinfo.toSetMethod($parameter.name)}($parameter.name);
#elseif($TOOL.isURI($TOOL.getElementClass($parameter.type)))
m.${sourceinfo.toSetMethod($parameter.name)}(new org.apache.axis2.databinding.types.URI(${parameter.name}.toString()));
#elseif($sourceinfo.isGenericTypeClass($method,$parameter.type))
m.${sourceinfo.toSetMethod($parameter.name)}(${parameter.name}.toString());//#typeName($parameter.type)转为String发送到服务器解析获取目标数据类型(#typeName($serviceInfo.targetType))
#else
m.${sourceinfo.toSetMethod($parameter.name)}(($sourceinfo.toStubClassName($parameter.type))getStubObject($parameter.name));
#end
#end
#if($isVoid)
stubProvider.getStub().${port.name}(m);
#else
#if($TOOL.isSimpleType($method.returnType))
return stubProvider.getStub().${port.name}(m).get_return();
#elseif($TOOL.isArrayOfbyte($method.returnType))
${parameterClassName}Response resp= stubProvider.getStub().${port.name}(m);
return null == resp.get_return() ? null : com.gitee.l0km.com4j.base.BinaryUtils.readBytes(resp.get_return().getInputStream());
#set($hasIOException=true)
#elseif($method.returnType.array)
#set($dimcount=$TOOL.getArrayDimension($method.returnType))
$sourceinfo.toStubClassName($port.returnType) res= stubProvider.getStub().${port.name}(m).get_return();
#if($TOOL.getElementClass($method.genericReturnType).primitive) ## 如果是class.isPrimitive()返回true则直接返回结果
return res;
#else ## 对返回的数组结果进行判断
if (res == null || (res.length == 1 && res#foreach($c in [1..$dimcount])[0]#end == null))
return new #typeName($TOOL.getElementClass($method.genericReturnType))#foreach( $c in [1..$dimcount])#if ($velocityCount==1)[0]#else[]#end#end;
else
return Axis2Utilits.simpleBeanConvert(res, #typeName($method.returnType).class);
#end
#else
return Axis2Utilits.simpleBeanConvert(stubProvider.getStub().${port.name}(m).get_return(),#typeName($method.returnType).class);
#end
#end
}catch(AxisFault e){
throw new RuntimeException(e);
}catch(RemoteException e){
throw new RuntimeException(e);
}#foreach($exp in $TOOL.sortThrowable($port.genericExceptionTypes))catch($sourceinfo.toStubExpectionClassName($exp) e){
#if($sourceinfo.isServiceRuntime($exp))
throw new RuntimeException(Axis2Utilits.convertStubException(e, #typeName($sourceinfo.toExpection($method,$exp)).class));
#else
throw Axis2Utilits.convertStubException(e, #typeName($sourceinfo.toExpection($method,$exp)).class);
#end
}#end
#if($hasIOException)catch(java.io.IOException e){
throw new RuntimeException(e);
}#end finally {
try {
this.stubProvider.getStub()._getServiceClient().cleanupTransport();
}catch (AxisFault e) {
throw new RuntimeException(e);
}
}
}
#end
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy