axis2作为客户端产生大量文件的解决方案

<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

 

http://stackoverflow.com/questions/8935581/how-to-delete-apache-axis-tmp-files-without-restarting/21735180#21735180

 

http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c422461e1f3ebce3763f4344959e2d3956b21f0baca36d2c761e26b799cd8c48d8be866d72c8713b2356dd0005d269afdc4654d651934d9fa40e96c9e74290b9d3a3c82524dd22036df0819c2e7703ca1eb6436ea1&p=c4769a4786cc42af5ea9dc3a584a8b&newp=9b788b16d9c11abe08e2977e0b4dcb231610db2151d4da166b82c825d7331b001c3bbfb423231502d2c27f6105aa4959eef6347233092ba3dda5c91d9fb4c57479d336&user=baidu&fm=sc&query=axis2+%C1%D9%CA%B1%CE%C4%BC%FE+temp&qid=ff655e880001a99b&p1=2

 

   

 //修改默认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);
    }

 

 

 

猜你喜欢

转载自cc-weige.iteye.com/blog/2368093
今日推荐