axis2作为客户端产生大量文件的解决方案
程序员文章站
2022-06-14 19:32:28
...
<div class="iteye-blog-content-contain" style="font-size: 14px"></div>
问题:使用axis2调用远程webservice时,产生大量临时文件写入磁盘,降低程序运行效率,占用磁盘空间
前提:使用axis2客户端版本:1.7.4
解决方案:
1:在初始化RPCServiceClient 使用构造器RPCServiceClient(ConfigurationContext configContext, AxisService service) 替换默认构造器
在wsdl生产的java文件中使用ConfigurationContext 的静态化
private static final ConfigurationContext configurationContextStatic = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null)
综合事例:
@Override public String abc(String reqXml) throws Exception { String value=""; RPCServiceClient serviceClient=init(); Object[] toParams = new Object[] {reqXml}; Class<?>[] clazzs = new Class[] {String.class}; Object[] resultList = null; QName addEntry = new QName("http://service.xx.xxx.com.cn","abc"); resultList = serviceClient.invokeBlocking(addEntry, toParams, clazzs); if(null!=resultList){ value= resultList[0].toString(); } serviceClient.cleanupTransport(); return value; } public RPCServiceClient init() throws AxisFault{ RPCServiceClient serviceClient = new RPCServiceClient(configurationContextStatic,null); Options options = serviceClient.getOptions(); options.setTimeOutInMilliSeconds(1000*60*3); EndpointReference ference = new EndpointReference("http://localhost:8090/api/services/exampleService?wsdl"); options.setTo(ference); return serviceClient; } private static final ConfigurationContext configurationContextStatic = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null) ;
2.
https://issues.apache.org/jira/browse/AXIS2-3919
//修改默认ConfigurationContext private static org.apache.axis2.context.ConfigurationContext configurationContextStatic; static { try { configurationContextStatic = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null); } catch (AxisFault e) { e.printStackTrace(); } } //在构造器实例化时引入configurationContextStatic /** * Constructor taking the target endpoint */ public SmsStub(java.lang.String targetEndpoint) throws org.apache.axis2.AxisFault { this(configurationContextStatic,targetEndpoint); }