模拟页面访问

/**模拟页面访问*/
	public void visitPage(String url,String type,PrpLvisitConfig prpLvisitConfig,String systype){
		HttpURLConnection httpConnection;
		Long l2;
		Long l1 = 0l;
		String status = "1";
		Date d = new Date();
		try {
			//开始时间 
			l1 = System.currentTimeMillis();  
			httpConnection = (HttpURLConnection) new URL(url+"&identify=Remote%20Manage%20System%20PICC%20INS").openConnection();
			httpConnection.setConnectTimeout(60000);
			httpConnection.setReadTimeout(60000);
			httpConnection.setRequestMethod("POST");
			httpConnection.setDoOutput(true);
			httpConnection.setDoInput(true);
			httpConnection.setInstanceFollowRedirects(false);
			httpConnection.setAllowUserInteraction(true);
			httpConnection.connect();
			// 2、发送数据
			OutputStream outputStream = httpConnection.getOutputStream();
			outputStream.flush();
			outputStream.close();
		     //判定是否会进行302重定向
            if (httpConnection.getResponseCode() == 302) { 
                //理赔系统第一次调用会通过acegi重定向
                String location = httpConnection.getHeaderField("Location");  
                String cookies = httpConnection.getHeaderField("Set-Cookie");  
                 
                URL serverUrl = new URL(location);  
                httpConnection = (HttpURLConnection) serverUrl.openConnection();  
                httpConnection.setRequestMethod("POST");
                httpConnection.setRequestProperty("Cookie", cookies);
                httpConnection.addRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.8) Firefox/3.6.8");  
                httpConnection.connect();  
//                System.out.println("跳转地址:" + location); 
            }
			
			// 3、返回数据
			//存在异常
			if(httpConnection.getResponseCode() == 500){
				//结束时间 
				l2 = System.currentTimeMillis(); 
				status = "5";
			}else{
				InputStreamReader inputStreamReader = new InputStreamReader(
						httpConnection.getInputStream());
				//结束时间 
				l2 = System.currentTimeMillis(); 
				BufferedReader bufferedReader = new BufferedReader(
						inputStreamReader);
				StringBuffer inputLines = new StringBuffer();
				char[] cbuf = new char[1024];
				for (int len = bufferedReader.read(cbuf) ; len >0; len = bufferedReader.read(cbuf)) {
					inputLines.append(cbuf,0,len);
				}
				inputStreamReader.close();
				bufferedReader.close();
//				System.out.println(11+inputLines.toString());
			}
			// 4、关闭连接
			httpConnection.disconnect();
			
		} catch (Exception e) {
			//结束时间 
			l2 = System.currentTimeMillis(); 
			if(e != null && e.getMessage() != null && e.getMessage().indexOf("Read timed out") > -1){
				status ="7";
			}else if(e != null && e.getMessage() != null && e.getMessage().indexOf("Connection timed out") > -1){
				status = "8";
			}else{
				status = "9";
			}
			logger.error("页面监控异常"+url, e);
		} 
		
		PrpLvisitLog prpLvisitLog = new PrpLvisitLog();
		prpLvisitLog.setComcode(prpLvisitConfig.getComcode());
		//--**系统类型 1-非车自赔 2-非车通赔3-车险自赔4-车险通赔  5-特险  6 航保
		if(prpLvisitConfig.getComcode().startsWith("00")){
			if(CommonUtil.equals(systype, "Car")){
				prpLvisitLog.setSystemType("4");
			}else{
				prpLvisitLog.setSystemType("2");
			}
		}else if(prpLvisitConfig.getComcode().startsWith("67")){//特险
			prpLvisitLog.setSystemType("5");
		}else if(prpLvisitConfig.getComcode().startsWith("A")){//航保
			prpLvisitLog.setSystemType("6");
		}else{
			if(CommonUtil.equals(systype, "Car")){
				prpLvisitLog.setSystemType("3");
			}else{
				prpLvisitLog.setSystemType("1");
			}
		}
		prpLvisitLog.setIp(url.trim());
		prpLvisitLog.setType(type);
		prpLvisitLog.setVisitdate(new Date());
//		prpLvisitLog.setIntervalTime(10);
		prpLvisitLog.setTime((l2-l1));
		prpLvisitLog.setStatus(status);
		if(prpLvisitLog.getTime()> 10000){
			prpLvisitLog.setWarning("1");
		}else{
			prpLvisitLog.setWarning("");
		}
		this.saveVisitLog(prpLvisitLog);
		
		
	}
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值