由于业务部门需要将现有系统的WebService中的利率,鉴于C/S客户端的维护性,因此使用了B/S的结构,框架选择了较为熟悉的ZK.主要使用了ZK较早的Server Push技术实现数据的主动推送。由于WebService是基于vb.net开发,这里的客户端就偷懒使用了Axis2直接生成的方式了~接下来就是非常简易的在ZK中调用该客户端,主要代码如下
class UpdateRunnable implements Runnable {
boolean running = false;
int maxRatio = 10;public void run() {running = true;while (running) {synchronized (stockModel) {clearAll();if (params) {//用于查询try {MarketStub fms = new MarketStub();GetXmlCNYFWD_Point xmlCnyfwdPt = new GetXmlCNYFWD_Point();xmlCnyfwdPt.setCcy(sccy);xmlCnyfwdPt.setPair(spair);Iterator it = fms.getXmlCNYFWD_Point(xmlCnyfwdPt).getGetXmlCNYFWD_PointResult().getExtraElement().getChildElements();while (it.hasNext()) {OMElement ome = (OMElement) it.next();String exCode = ome.getFirstChildWithName(new QName("CNYFWDPoint_Code")).getText();Double exBid = Double.valueOf(ome.getFirstChildWithName(new QName("Bid")).getText());Double exAsk = Double.valueOf(ome.getFirstChildWithName(new QName("Ask")).getText());String dt = ome.getFirstChildWithName(new QName("InputDate")).getText();CnyfwdPtInfo exRt = new CnyfwdPtInfo(exCode, exBid,exAsk, dt);stockModel.add(exRt);// ListModelList stockModel;}} catch (AxisFault e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (RemoteException e) {// TODO Auto-generated catch blocke.printStackTrace();}} else {try {MarketStub fms = new MarketStub();GetAllCNYFWD_Point allCnyfwdPt = new GetAllCNYFWD_Point();Iterator it = fms.getAllCNYFWD_Point(allCnyfwdPt).getGetAllCNYFWD_PointResult().getExtraElement().getChildElements();while (it.hasNext()) {OMElement ome = (OMElement) it.next();String exCode = ome.getFirstChildWithName(new QName("CNYFWDPoint_Code")).getText();Double exBid = Double.valueOf(ome.getFirstChildWithName(new QName("Bid")).getText());Double exAsk = Double.valueOf(ome.getFirstChildWithName(new QName("Ask")).getText());String dt = ome.getFirstChildWithName(new QName("InputDate")).getText();CnyfwdPtInfo exRt = new CnyfwdPtInfo(exCode, exBid,exAsk, dt);stockModel.add(exRt);}} catch (AxisFault e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (RemoteException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}try {Thread.currentThread().sleep(90000);} catch (InterruptedException e) {running = false;}}}}
页面部分代码
<zk><zscript>import com.living.data.cnyfwdpt.*;if(!desktop.isServerPushEnabled()){desktop.enableServerPush(true);}CnyfwdPtUpdateService service = CnyfwdPtUpdateService.lookup();ListModelmodel= service.getProxy(desktop);CnyfwdPtItemRendererrenderer = newCnyfwdPtItemRenderer();</zscript><groupbox width="1000px"><caption label="Live CNYFWD Point " /><listbox model="${model}" itemRenderer="${renderer}" mold="paging"pageSize="25" vflex="true"><listhead><listheader label="CNYFWDPt Code" width="100px"style="font-size : large;font-weight : bold;text-align:center;color:blue" /><listheader label="Bid"style="font-size : large;font-weight : bold;text-align:center" /><listheader label="Ask"style="font-size : large;font-weight : bold;text-align:center" /><listheader label="QuoteDate"style="font-size : large;font-weight : bold;text-align:center" /></listhead></listbox></groupbox></zk>
主页面代码
<?page title="Live Rate V 2.0 " contentType="text/html;charset=UTF-8"?> <window id="main" title="Live Rate V 2.0 "><vbox><tabbox><tabs><tab label="ExchangeRate" /><tab label="InterestRate" /><tab label="SwapPoint" /><tab label="CNYFWDPoint" /></tabs><tabpanels><tabpanel><include src="exchangeRt.zul" /></tabpanel><tabpanel><include src="interestRt.zul" /></tabpanel><tabpanel><include src="swapPt.zul" /></tabpanel><tabpanel><include src="cnyfwdPt.zul" /></tabpanel></tabpanels></tabbox></vbox></window>
程序效果图