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

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

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            65 隨筆 :: 6 文章 :: 149 評(píng)論 :: 0 Trackbacks
          <2010年12月>
          2829301234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          公告

          本博客的文章,未注明轉(zhuǎn)載字樣的均為原創(chuàng),本著好記性不如爛博客的精神,QQ是34174409,歡迎指教和討論

          留言簿(12)

          隨筆分類

          隨筆檔案

          文章檔案

          收藏夾

          blog

          開源社區(qū)

          活動(dòng)

          積分與排名

          最新評(píng)論

          由于歷史原因,幾個(gè)項(xiàng)目都選用hessian作為web service的實(shí)現(xiàn)方式,hessian的確是非常輕量級(jí),基于http協(xié)議進(jìn)行傳輸,通過(guò)自定義的串行化機(jī)制將請(qǐng)求信息進(jìn)行序列化,以二進(jìn)制傳輸節(jié)省了不少的開銷,速度跟socket差不多.客戶端和服務(wù)器發(fā)起和接收請(qǐng)求都是通過(guò)spring提供的hessian api進(jìn)行請(qǐng)求和接收,但是在服務(wù)端中并沒(méi)有記錄和控制遠(yuǎn)端ip地址和主機(jī)的信息,所以需要對(duì)源碼進(jìn)行一些重寫

          對(duì)org.springframework.remoting.caucho.HessianServiceExporter進(jìn)行重寫

          /**
           * 重寫HessianServiceExporter.handleRequest(),攔截獲取遠(yuǎn)端調(diào)用信息
           * 
          @author chenyz
           *
           
          */
          public class HouseHessianServiceExporter extends HessianServiceExporter {
              
              
          private static String[] entryIP = {"192.168.0.1","192.168.0.3","192.168.0.3"};
              
              
          private static Log log = LogFactory.getLog("Myremote"); 
              
              @Override
              
          public void handleRequest(HttpServletRequest request,
                      HttpServletResponse response) 
          throws ServletException, IOException {        
                  log.info(
          "try ==>remote 's IP:"+IpUtil.getIpAddr(request)+"remote 's host: "+request.getRemoteHost());
                  
          int call = 0;
                  
          for(String ip:entryIP){
                      
          if(ip.equals(IpUtil.getIpAddr(request)))
                          call
          ++;
                  }
                  
          if(call>0){
                      log.info(
          "call ==>remote 's IP:"+IpUtil.getIpAddr(request)+"remote 's host: "+request.getRemoteHost());
                      
          super.handleRequest(request, response);
                  }
              }
          }

             <bean id="shineLibWSImpl" class="com.***.shine.remote.ShineLibWSImpl"/>
              
          <bean name="/remote/shineinfo" class="com.***.shine.hessian.service.HouseHessianServiceExporter">
                  
          <property name="service">
                      
          <ref bean="shineLibWSImpl"/>
                  
          </property>
                  
          <property name="serviceInterface">
                      
          <value>com.***.shine.remote.ShineLibWebService</value>
                  
          </property>
              
          </bean>

          重寫HessianServiceExporter.handleRequest(),攔截獲取遠(yuǎn)端調(diào)用信息,提取出調(diào)用端的ip信息與服務(wù)端制定的ip列表進(jìn)行對(duì)比,并將所有調(diào)用信息記錄日志

          如果直接使用hessian的api的HessianServlet,直接對(duì)HessianServlet的service()重寫,攔截并提取遠(yuǎn)端調(diào)用信息

          /**
           * 重寫HouseHessianServlet.service(),攔截獲取遠(yuǎn)端調(diào)用信息
           * 
          @author chenyz
           *
           
          */
          public class HouseHessianServlet extends HessianServlet{
              
              
          private static String[] entryIP = {"192.168.0.1","192.168.0.3","192.168.0.3"};
              
              
          private static Log log = LogFactory.getLog("Myremote"); 
              
              @Override
              
          public void service(ServletRequest request, ServletResponse response)
                      
          throws IOException, ServletException {
                  HttpServletRequest req 
          = (HttpServletRequest) request;
                  log.info(
          "try ==>remote 's IP:"+IpUtil.getIpAddr(req)+"remote 's host: "+request.getRemoteHost());
                  
          int call = 0;
                  
          for(String ip:entryIP){
                      
          if(ip.equals(IpUtil.getIpAddr(request)))
                          call
          ++;
                  }
                  
          if(call>0){
                      log.info(
          "call ==>remote 's IP:"+IpUtil.getIpAddr(req)+"remote 's host: "+request.getRemoteHost());
                      
          super.service(request, response);
                  }
              }
          }

          web.xml

             <servlet>   
              
          <servlet-name>HessianServlet</servlet-name>   
              
          <servlet-class>   
                  com.***.product.remote.Htest
              
          </servlet-class>   
            
          </servlet>  

            
          <servlet-mapping>   
              
          <servlet-name>HessianServlet</servlet-name>   
              
          <url-pattern>/service/hession</url-pattern>   
            
          </servlet-mapping>  

          com.***.product.remote.Htest

          public class Htest extends HouseHessianServlet implements IHtest{
              
              
          public hello(){
                  System.out.println(
          "hello");
              }
          }


          posted on 2010-12-21 16:05 陳于喆 閱讀(3031) 評(píng)論(0)  編輯  收藏 所屬分類: javaweb service
          主站蜘蛛池模板: 奉贤区| 合川市| 同仁县| 济宁市| 遂平县| 衢州市| 秦皇岛市| 磴口县| 黄龙县| 普兰店市| 大悟县| 左云县| 商水县| 泸定县| 高雄县| 卢龙县| 斗六市| 曲松县| 大兴区| 德化县| 白城市| 博野县| 洪洞县| 连城县| 五指山市| 长汀县| 苏尼特左旗| 阜新市| 赞皇县| 克拉玛依市| 阿拉善盟| 萝北县| 吴旗县| 芜湖县| 澄城县| 淮安市| 南华县| 讷河市| 噶尔县| 宣化县| 治县。|