<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    于吉吉的技術(shù)博客

    建造高性能門戶網(wǎng)

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      65 隨筆 :: 6 文章 :: 149 評(píng)論 :: 0 Trackbacks
    目前幾套系統(tǒng)中主要使用的hessian進(jìn)行遠(yuǎn)程調(diào)用webservice服務(wù)的有hessian的HessianProxyFactory(com.caucho.hessian.client.HessianProxyFactory)和spring的HessianProxyFactoryBean(org.springframework.remoting.caucho.HessianProxyFactoryBean).

    1.HessianProxyFactory
    查看HessianProxyFactory源碼后發(fā)現(xiàn),hessian在創(chuàng)建http請(qǐng)求連接webservice服務(wù)并沒有對(duì)連接超時(shí)進(jìn)行相關(guān)的參數(shù)設(shè)置,所以當(dāng)網(wǎng)絡(luò)出現(xiàn)問題就會(huì)造成整個(gè)hessian處理的阻塞,進(jìn)而阻塞整個(gè)線程后續(xù)的處理
    以下是HessianProxyFactory對(duì)連接處理的源碼

    protected URLConnection openConnection(URL url)
        
    throws IOException
      {
        URLConnection conn 
    = url.openConnection();

        conn.setDoOutput(
    true);

        
    if (_readTimeout > 0) {
          
    try {
        conn.setReadTimeout((
    int) _readTimeout);
          } 
    catch (Throwable e) {
          }
        }

        conn.setRequestProperty(
    "Content-Type""x-application/hessian");

        
    if (_basicAuth != null)
          conn.setRequestProperty(
    "Authorization", _basicAuth);
        
    else if (_user != null && _password != null) {
          _basicAuth 
    = "Basic " + base64(_user + ":" + _password);
          conn.setRequestProperty(
    "Authorization", _basicAuth);
        }

        
    return conn;
      }

    所以我們針對(duì)此邏輯繼承并重寫該openConnection方法,在創(chuàng)建http連接的時(shí)候通過設(shè)置連接超時(shí)時(shí)間來解決因網(wǎng)絡(luò)問題阻塞程序繼續(xù)的問題

    public class MyHessianProxyFactory extends HessianProxyFactory {

        
    private int connectTimeOut = 10000;

        
    private int readTimeOut = 10000;

        
    public int getConnectTimeOut() {
            
    return connectTimeOut;
        }

        
    public void setConnectTimeOut(int connectTimeOut) {
            
    this.connectTimeOut = connectTimeOut;
        }

        
    public int getReadTimeOut() {
            
    return readTimeOut;
        }

        
    public void setReadTimeOut(int readTimeOut) {
            
    this.readTimeOut = readTimeOut;
        }

        
    protected URLConnection openConnection(URL url) throws IOException {
            URLConnection conn 
    = url.openConnection();
            conn.setDoOutput(
    true);
            
    if (this.connectTimeOut > 0) {
                conn.setConnectTimeout(
    this.connectTimeOut);
            }
            
    if (this.readTimeOut > 0) {
                conn.setReadTimeout(
    this.readTimeOut);
            }
            conn.setRequestProperty(
    "Content-Type""x-application/hessian");
                
    if (_basicAuth != null)
                      conn.setRequestProperty(
    "Authorization", _basicAuth);
                
    else if (_user != null && _password != null) {
                      _basicAuth 
    = "Basic " + base64(_user + ":" + _password);
                      conn.setRequestProperty(
    "Authorization", _basicAuth);
                }
            
    return conn;
        }
    }

    2.HessianProxyFactoryBean
    查看spring的HessianProxyFactoryBean源碼發(fā)現(xiàn),它在封裝hessian是直接創(chuàng)建一個(gè)HessianProxyFactory實(shí)例,然后利用該實(shí)例完成創(chuàng)建遠(yuǎn)程服務(wù)

    public class HessianProxyFactoryBean extends HessianClientInterceptor implements FactoryBean {

        
    private Object serviceProxy;


        
    public void afterPropertiesSet() {
            
    super.afterPropertiesSet();
            
    this.serviceProxy = ProxyFactory.getProxy(getServiceInterface(), this);
        }
        

        
    public Object getObject() {
            
    return this.serviceProxy;
        }

        
    public Class getObjectType() {
            
    return getServiceInterface();
        }
        
        
    public boolean isSingleton() {
            
    return true;
        }

    }

    所以對(duì)此的解決方法與上面差不多,繼承HessianProxyFactoryBean然后加入相應(yīng)的連接超時(shí)和讀取超時(shí)的變量,重寫afterPropertiesSet方法,并且同時(shí)完成上面第一步對(duì)HessianProxyFactory的改造,這樣就能保證連接遠(yuǎn)程webserver服務(wù)器時(shí)不會(huì)因?yàn)榫W(wǎng)絡(luò)原因阻塞程序的執(zhí)行

    public class MyHessianProxyFactoryBean extends HessianProxyFactoryBean {

        
    private MyHessianProxyFactory proxyFactory = new MyHessianProxyFactory();

        
    private int readTimeOut = 10000;

        
    private int connectTimeOut = 10000;

        
    public int getReadTimeOut() {
            
    return readTimeOut;
        }

        
    public void setReadTimeOut(int readTimeOut) {
            
    this.readTimeOut = readTimeOut;
        }

        
    public int getConnectTimeOut() {
            
    return connectTimeOut;
        }

        
    public void setConnectTimeOut(int connectTimeOut) {
            
    this.connectTimeOut = connectTimeOut;
        }

        
    public void afterPropertiesSet() {
            proxyFactory.setReadTimeout(readTimeOut);
            proxyFactory.setConnectTimeOut(connectTimeOut);
            setProxyFactory(proxyFactory);
            
    super.afterPropertiesSet();
        }
    }


    posted on 2010-12-16 14:46 陳于喆 閱讀(12039) 評(píng)論(11)  編輯  收藏 所屬分類: web開發(fā)javaweb service

    評(píng)論

    # re: 解決hessian遠(yuǎn)程調(diào)用連接超時(shí)的問題 2010-12-16 15:25 Xuzhengsong
    我覺得可以這樣重寫openConnection方法
    protected URLConnection openConnection(URL url) throws IOException {

    URLConnection conn = super.openConnection(url);
    if (this.connectTimeOut > 0) {
    conn.setConnectTimeout(this.connectTimeOut);
    }
    retrun conn;
    }  回復(fù)  更多評(píng)論
      

    # re: 解決hessian遠(yuǎn)程調(diào)用連接超時(shí)的問題 2010-12-16 15:33 陳于喆
    @Xuzhengsong
    非常感謝,這樣更簡(jiǎn)潔  回復(fù)  更多評(píng)論
      

    # ugg boots womens 2010-12-16 15:47 ugg boots womens
    謝謝 這樣以后方便了許多  回復(fù)  更多評(píng)論
      

    # re: 解決hessian遠(yuǎn)程調(diào)用連接超時(shí)的問題 2010-12-28 18:53 mrt_soul
    HessianProxyFactory 有_readTimeout設(shè)置項(xiàng)啊!
    只是沒有connectTimeOut  回復(fù)  更多評(píng)論
      

    # re: 解決hessian遠(yuǎn)程調(diào)用連接超時(shí)的問題 2011-10-17 13:05 郭蕾
    樓主,在hessian中相關(guān)設(shè)置的!  回復(fù)  更多評(píng)論
      

    # re: 解決hessian遠(yuǎn)程調(diào)用連接超時(shí)的問題 2012-07-23 12:25 Eddy.he
    請(qǐng)問你用的是哪個(gè)版本的hessian包?父類HessianProxyFactory 里面的變量_basicAuth 、_user ,子類能引用到嗎?不知道你自己有沒有測(cè)試過哦。  回復(fù)  更多評(píng)論
      

    # re: 解決hessian遠(yuǎn)程調(diào)用連接超時(shí)的問題 2012-07-23 12:30 Eddy.he
    @郭蕾
    你設(shè)置給我看看,怎么設(shè)置connectTimeout?麻煩分享一下。  回復(fù)  更多評(píng)論
      

    # re: 解決hessian遠(yuǎn)程調(diào)用連接超時(shí)的問題 2012-11-05 17:24 郭蕾
    factory.setReadTimeout  回復(fù)  更多評(píng)論
      

    # re: 解決hessian遠(yuǎn)程調(diào)用連接超時(shí)的問題 2012-11-05 17:25 郭蕾
    請(qǐng)看看這個(gè)軟件:http://www.oschina.net/news/34462/hetty-1-3-rpc-framework  回復(fù)  更多評(píng)論
      

    # re: 解決hessian遠(yuǎn)程調(diào)用連接超時(shí)的問題 2012-11-15 15:17 gahd
    你敢把代碼寫完么?帖一部分跟沒帖沒什么區(qū)別吧  回復(fù)  更多評(píng)論
      

    # re: 解決hessian遠(yuǎn)程調(diào)用連接超時(shí)的問題[未登錄] 2016-01-22 11:11 aa
    樓主用的是哪個(gè)版本的hessian啊  回復(fù)  更多評(píng)論
      

    主站蜘蛛池模板: 日本永久免费a∨在线视频| 亚洲国产精品国自产拍电影| 精品国产精品久久一区免费式| 国产免费女女脚奴视频网| 99久热只有精品视频免费看| 人人玩人人添人人澡免费| 免费精品99久久国产综合精品| 中文字幕一区二区免费| 免费网站观看WWW在线观看| av永久免费网站在线观看| 中文无码成人免费视频在线观看| 青青操免费在线观看| 亚洲电影免费在线观看| 最近中文字幕2019高清免费| 黄网站色在线视频免费观看| 中国在线观看免费高清完整版| 成年在线网站免费观看无广告| 免费看的黄色大片| 又粗又硬又黄又爽的免费视频 | 亚洲AV无码一区二区三区久久精品 | 91嫩草免费国产永久入口| 91成人免费在线视频| 成年在线网站免费观看无广告| 成人永久免费福利视频网站| heyzo亚洲精品日韩| 亚洲色大成网站www永久一区| 亚洲av午夜福利精品一区| 久久久亚洲欧洲日产国码二区 | 亚洲国产精品久久久久婷婷软件| 97久久精品亚洲中文字幕无码 | 亚洲电影在线免费观看| 亚洲中文字幕无码爆乳app| 国产成人精品亚洲| 本免费AV无码专区一区| 每天更新的免费av片在线观看| 成年美女黄网站18禁免费| 亚洲第一视频在线观看免费| 久久精品夜色国产亚洲av| 久久精品国产亚洲αv忘忧草| 国产成人综合亚洲绿色| 永久免费A∨片在线观看|