java 调用监控接口_Web循环监控Java调用 / Java调用.net wcf接口

背景介紹 (Background Introduction)

目前有一些报表客户抱怨打不开

报表执行过程过长,5、8、10秒甚至更多

不能及时发现和掌握服务器web站点情况

用戶需求(User Requirements)

监控web站点执行情况

使用跟用户相同的谷歌浏览器进行模拟后台解析

获得web站点初始化时间单位秒

提供接口给运维人员做监控实时掌握web站点情况

詳細設計(Design details)

1. simple设计

(1)   TipDetail 数据消息

字段(Field)

字段说明(Description)

备注所有:

Success

是否成功(调用是否成功)

WebstatusInEntity

Message

调用消息(错误或提醒)

T Data

泛型对象(描述相关功能信息)

(2)   WebstatusInEntity站点输入参数实体

字段(Field)

字段说明(Description)

备注所有:

Url

加载的Url

FilterIps

过滤Ips,多个逗号隔开

FilterPorts

多个逗号隔开

MaxLoadScends

最大加载时间

MinRequstLen

最小请求数

(3)   WebstatusOutEntity  Web解析结果输出对象

字段(Field)

字段说明(Description)

备注所有:

Id

Id(服务端执行的唯一id)

IsFinish

是否结束

IsSuccess

是否成功(是否执行成功)

LoadScends

加载秒数(在MaxLoadScends时间内)

2. 功能接口

description

方法

描述

参数(替换模板内数据)

返回结果

逻辑说明

http://127.0.0.1:8734/NetAnalyzerService?wsdl

Post

WCF接口地址

RunWebstatusJson

运行状态分析

WebstatusInEntity webstatusInEntity = newWebstatusInEntity();

webstatusInEntity.setUrl("http://10.134.226.153:81/Reports/powerbi/OEE_BU?rs:embed=true&rs:token=1");   //要执行的webwebstatusInEntity.setFilterIps("10.134.226.153");   //通过谷歌可以监控到Url需要访问的原始Ip,如果有多个可以逗号隔开webstatusInEntity.setMaxLoadScends(20);             //服务端监控一直执行所等待时间,webstatusInEntity.setMinRequstLen(100);

数据结果集

GetWebstatusJson

获取Webstatus分析详情

Id

1. 相关类:

(1)   packagesimple;

importcom.google.gson.Gson;

importcom.google.gson.reflect.TypeToken;

importorg.apache.cxf.endpoint.Client;

importorg.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

importjava.util.ArrayList;

importjava.util.List;

/**

* created by xun-yu.she on 2019/8/15

*/public classWebstatusTest {

/*程序主入口*/public static voidmain(String[]

args) throwsException {

try{

String resultJson = RunWebstatusJsonJob(100);

System.out.println("*******"+ resultJson);

} catch(Exception ex)

{

System.out.println("*******"+ ex.getMessage());

}

}

/*

Java调用动态调用Wcf接口执行web查看状态,由于第一二次执行涉及到初始化等,所以难免获取的时间会长一些,

所以平均的打开速度竟可能以第3~4次的分析,所以这里我设置的是一个执行的Job,根据情况执行*/public staticString

RunWebstatusJsonJob(intrunCount) throwsException {

try{

//初始服务JaxWsDynamicClientFactory

dcflient = JaxWsDynamicClientFactory.newInstance();

//创建服务Client client =

dcflient.createClient("http://10.60.136.172:8734/NetAnalyzerService?wsdl");

//初始化序列化对象Gson gson = newGson();

Object[] objects;

//结果集List

webstatusOutEntitys = newArrayList();

//参数对象WebstatusInEntity

webstatusInEntity = newWebstatusInEntity();

webstatusInEntity.setUrl("http://127.0.0.1:81/Reports/powerbi/OEE_BU?rs:embed=true&rs:token=1");   //要执行的webwebstatusInEntity.setFilterIps("10.134.226.153");   //通过谷歌可以监控到Url需要访问的原始Ip,如果有多个可以逗号隔开webstatusInEntity.setMaxLoadScends(20);             //服务端监控一直执行所等待时间,webstatusInEntity.setMinRequstLen(100);             //执行一次Url执行大概最小请求数,可以通过谷歌浏览器的network监控到,如果服务端执行的请求数大于最小请求数,就会默认web执行成功//循环多次执行for(inti = 0; i <

runCount; i++) {

try{

objects =

client.invoke("RunWebstatusJson", webstatusInEntity.getUrl(),

webstatusInEntity.getFilterIps(), null,

webstatusInEntity.getMaxLoadScends(), webstatusInEntity.getMinRequstLen());

//泛型序列化TipDetail

resultDetail = gson.fromJson(objects[0].toString(), newTypeToken>()

{

}.getType());

//线程等待,这等待的时间是服务器端需要根据用户设定的MaxLoadScends的值去监控等待一段时间,所以调用端一般需要在此基础上多增加15+秒,在调用查询接口了解执行情况,服务端同一时间只处理一次请求,不能被多个客户端同时调用Thread.currentThread().sleep(webstatusInEntity.getMaxLoadScends()

* 1000 + 10000);//毫秒if(resultDetail.getSuccess()

&& resultDetail.getData() != null) {

objects =

client.invoke("GetWebstatusJson",

resultDetail.getData().getId());

//泛型序列化resultDetail =

gson.fromJson(objects[0].toString(), newTypeToken>()

{

}.getType());

webstatusOutEntitys.add(resultDetail.Data);

}

} catch(Exception ex)

{

}

}

String strWebstatusOutEntitys

= gson.toJson(webstatusOutEntitys);

returnstrWebstatusOutEntitys;

} catch(Exception ex)

{

// statusCode=500 //Wcf挂了System.out.println("*******"+ ex.getMessage());

throwex;

}

}

}

(2)

packagesimple;

importlombok.AllArgsConstructor;

importlombok.Data;

importlombok.NoArgsConstructor;

importjava.util.List;

/**

* created by xun-yu.she on 2019/8/14

*数据消息对象*/@Data

@AllArgsConstructor

@NoArgsConstructor

public classTipDetail {

///

///是否成功(调用是否成功)///

publicBoolean Success;

///

///调用消息(错误或提醒)/// publicString Message;

///

///泛型对象(描述相关功能信息)///

publicT Data;

//public List Datas ;}

(3)

packagesimple;

importlombok.Data;

/**

* created by xun-yu.she on 2019/8/15

*站点输入参数实体*/@Data

public classWebstatusInEntity {

///

///加载的Url

/// publicString Url;

///

///过滤Ips,多个逗号隔开///

publicString FilterIps;

///

///过滤Ports,多个逗号隔开/// publicString FilterPorts;

///

///最大加载时间///

public intMaxLoadScends;

///

///最小请求数///

public intMinRequstLen;

}

(4)

packagesimple;

importlombok.Data;

/**

* created by xun-yu.she on 2019/8/15

* Web解析结果输出对象*/@Data

public classWebstatusOutEntity {

///

/// Id(服务端执行的唯一id)///

publicString Id;

///

///是否结束///

public booleanIsFinish;

///

///是否成功(是否执行成功)///

public booleanIsSuccess;

///

///加载秒数///

public intLoadScends;

}

前提條件(Design Constants)

1.  导入需要的包

org.apache.httpcomponents

httpclient

4.5.4

com.alibaba

fastjson

1.1.41

org.apache.cxf

cxf-spring-boot-starter-jaxws

3.1.11

org.scala-lang

scala-library

2.11.0

com.google.code.gson

gson

2.8.5

org.projectlombok

lombok

1.16.22

最終用戶特征(User characteristics)

ce431d4037899eb6ef041e31c57c4ae6.png

总结:此为java调用.net wcf调用实例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值