Ⅰ 如何安全的更新java本地缓存
java安全的更新本地缓存的方式如下:当外部请求访问缓存数据时:如果缓存已经过期(当前时间-缓存的上次更新时间超过缓存的有效期),则重新调用webservice访问服务端查询数据,然后更新缓存。如果缓存未过期,但缓存为空,则重新调用webservice访问服务端查询数据,然后更新缓存。<pre t="code" l="java">/** 本地缓存  */  
private List<InterfaceConfig>   configs            = null;  
/** 本地缓存的上次更新时间 */  
private long                    lastUpdateTime     = 0;  
public List<InterfaceConfig> queryInterfaceList() {  
long currentTime = System.currentTimeMillis();  
//判断本次缓存是否过期,过期则重新调用webservice查询数据,并更新缓存  
if (currentTime - lastUpdateTime > 60000) {  
InterfaceManageResult result = interfaceManageFacade.queryAllInterfaceList();  
if (null != result  result.isSuccess()) {  
configs = result.getInterfaceConfigList();  
}  
lastUpdateTime = currentTime;  
}  
if (!CollectionUtils.isEmpty(configs)) {  
return configs;  
}  
//本地缓存为空,则重新调用webservice查询数据,并更新缓存  
InterfaceManageResult result = interfaceManageFacade.queryAllInterfaceList();  
if (null == result || !result.isSuccess()) {  
return null;  
}  
configs = result.getInterfaceConfigList();  
return configs;  
}
Ⅱ net webservice数据缓存,该怎么解决
用Session保存是不行的,建议把第一次结果保存在数据库里,或是xml文件里,或是Cookie里,第二次调用的时候把结果从数据库,xml,Cookie里读出来。 另外,为什么不把两个方法整合成一个方法呢?
Ⅲ webservice接口怎么使用
webservice的调用,常用的大约有3种方式:
    1、使用axis调用
    2、使用xfire调用
    3、使用cxf调用
    项目中,采用axis进行调用,记录如下,备忘:
    ps教程:想当年的时候是用的xfire方式调用的,结果没做记录,现在已经完全记不得怎么玩了。所以说要多写博客啊 t_t
   版本说明:
        aixs版本:axis-bin-1_4.zip
        java环境略
    第一步:确保wsdl文件可用,文中为获取到sendsmsservice.wsdl,当然url的也行。
    第二步:执行生成客户端代码的脚本。脚本内容为:
set axis_lib=d:axis-1_4lib
set java_cmd=java -djava.ext.dirs=%axis_lib%
set output_path=.
set package=info.jyzh.wap.liaoning.push
%java_cmd% org.apache.axis.wsdl.wsdl2java sendsmsservice.wsdl -o%output_path% -p%package% -t
 
#查看wsdl2java的使用帮助#%java_cmd% org.apache.axis.wsdl.wsdl2java -help
 
ok,至此,客户端代码就生成出来了。还带了一个单元测试哦。
 
实际工作中,碰到以下情况,客户端不能直接连上webservice服务器,中间被强大的代理服务器挡住了。如下图:
为此,修改生成的代码,本次是在中作修改,如下:
    static {
            axisproperties.setproperty("http.proxyhost","88.88.88.88");
            axisproperties.setproperty("http.proxyport","8080");
            axisproperties.setproperty("http.proxyuser","asp教程yy");
            axisproperties.setproperty("http.proxypassword","123456");
        _operations = new org.apache.axis.description.operationdesc[1];
        _initoperationdesc1();
    }直接axis调用远程的web service我觉得这种方法比较适合那些高手,他们能直接看懂xml格式的wsdl文件,我自己是看不懂的,尤其我不是专门搞这行的,即使一段时间看懂,后来也就忘记了。直接调用模式如下:import java.util.date;import java.text.dateformat;import org.apache.axis.client.call;import org.apache.axis.client.service;import javax.xml.namespace.qname;import java.lang.integer;import javax.xml.rpc.parametermode; public class caclient {                   public static void main(string[] args) {               try {                     string endpoint = "http://localhost:8080/ca3/services/casynrochnized?wsdl";                     //直接引用远程的wsdl文件                    //以下都是套路 
                     service service = new service();                     call call = (call) service.createcall();                     call.settargetendpointaddress(endpoint);                     call.setoperationname("adser");//wsdl里面描述的接口名称                     call.addparameter("username", org.apache.axis.encoding.xmltype.xsd_date,                                   javax.xml.rpc.parametermode.in);//接口的参数                     call.setreturntype(org.apache.axis.encoding.xmltype.xsd_string);//设置返回类型 
                     string temp = "测试人员";                     string result = (string)call.invoke(new object[]{temp});                     //给方法传递参数,并且调用方法                     system.out.println("result is "+result);              }              catch (exception e) {                     system.err.println(e.tostring());              }       }}2,直接soap调用远程的webservice这种模式我从来没有见过,也没有试过,但是网络上有人贴出来,我也转过来import org.apache.soap.util.xml.*;import org.apache.soap.*;import org.apache.soap.rpc.*; import java.io.*;import java.net.*;import java.util.vector; public class caservice{       public static string getservice(string user) {       url url = null;       try {           url=new url("http://192.168.0.100:8080/ca3/services/casynrochnized");       } catch (malformerlexception mue) {          return mue.getmessage();         }             // this is the main soap object       call soapcall = new call();       // use soap encoding       soapcall.setencodingstyleuri(constants.ns_uri_soap_enc);       // this is the remote object we're asking for the price       soapcall.settargetobjecturi("urn:xmethods-casynrochnized");       // this is the name of the method on the above object       soapcall.setmethodname("getuser");       // we need to send the isbn number as an input parameter to the method       vector soapparams = new vector();        // name, type, value, encoding style       parameter isbnparam = new parameter("username", string.class, user, null);       soapparams.addelement(isbnparam);       soapcall.setparams(soapparams);       try {          // invoke the remote method on the object          response soapresponse = soapcall.invoke(url,"");          // check to see if there is an error, return "n/a"          if (soapresponse.generatedfault()) {              fault fault = soapresponse.getfault();             string f = fault.getfaultstring();             return f;          } else {             // read result             parameter soapresult = soapresponse.getreturnvalue ();             // get a string from the result             return soapresult.getvalue().tostring();          }       } catch (soapexception se) {          return se.getmessage();       }    }}
3,使用wsdl2java把wsdl文件转成本地类,然后像本地类一样使用,即可。
