/**模拟页面访问*/
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);
}
}
模拟页面访问
最新推荐文章于 2024-07-04 15:27:15 发布